0

Architecture ->GBIP from external interface is connected to target ( linux) system via gpib bus. Inside Linux box , there is ethernet cable from GPIB to motherboard.

The PIC_GPIB card on external interface is IEEE 488.2

I am sending a query from external interface to linux box.

Few scenarios

1) If I send a query which does not expect a response back , then next query send will work.

2) If I send a query which expect response back , and when I have received the response and read it and then fire next query it works fine.

3) BUT if I send a query from external interface and got response back and I ignore to read the response , then Next query fails. I am requesting help for scenario 3.

The coding is done on linux side and its a socket programming , which uses linux inbuilt function from unistd.h for read and write.

My investigation : I have found there is a internal memory on gbib card on external interface which stores the value of previous response until we have the read. Generally I use IEEE string utility software to write commands that goes to linux box and read reposne via read button .

Could someone please direct me how to clean input buffer or memory which stores value so that write from external command contiunues without bothering to read it.

My code on linux side has been developed in C++ and socket programming. I have used in bulit write and read function to write and read to the gpib and to json server.

Sample code is shown below

    bool GpibClass::ReadWriteFromGPIB()
{
  bool check = true;
  int n = 0;
  char buffer[BUFFER_SIZE];
  fd_set read_set;
  struct timeval lTimeOut;

  // Reset the read mask for the select
  FD_ZERO(&read_set);
  FD_SET(mGpibFd, &read_set);
  FD_SET(mdiffFd, &read_set);

  // Set Timeout to check the status of the connection
  // when no data is being received
  lTimeOut.tv_sec = CONNECTION_STATUS_CHECK_TIMEOUT_SECONDS;
  lTimeOut.tv_usec = 0;

  cout << "Entered into this function" << endl;

  // Look for sockets with available data
  if (-1 == select(FD_SETSIZE, &read_set, NULL, NULL, &lTimeOut))
  {
    cout << "Select failed" << endl;

    // We don't know the cause of select's failure.
    // Close everything and start from scratch:
    CloseConnection(mGpibFd);
    CloseConnection(mdifferntServer); // this is different server

    check = false;
  }

  // Check if data is available from GPIB server,
  // and if any read and push it to gpib
  if(true == check)
  {
    cout << "Check data from GPIB after select" << endl;

    if (FD_ISSET(mGpibFd, &read_set))
    {
      n = read(mGpibFd, buffer, BUFFER_SIZE);

      cout << "Read from GPIB" << n << " bytes" << endl;

      if(0 < n)
      {
        // write it to different server and check if we get response from it
      }
      else
      {
        // Something failed on socket read - most likely
        // connection dropped. Close socket and retry later
        CloseConnection(mGpibFd);

        check = false;
      }
    }
  }

  // Check if data is available from different server,
  // and if any read and push it to gpib
  if(true == check)
  {
    cout << "Check data from diff server after select" << endl;

    if (FD_ISSET(mdiffFd, &read_set))
    {
      n = read(mdiffFd, buffer, BUFFER_SIZE);

      cout << "Read from diff servewr " << n << " bytes" << endl;

      if (0 < n)
      {
        // Append, just in case - makes sure data is sent.
        // Extra cr/lf shouldn't cause any problem if the json
        // server has already added them
        strcpy(buffer + n, "\r\n");

        write(mGpibFd, buffer, n + 2);
        std::cout <<" the buffer sixze  = " << buffer << std::endl;

      }
      else
      {
        // Something failed on socket read - most likely
        // connection dropped. Close socket and retry later
        CloseConnection(mdiffFd);

        check = false;
      }
    }
  }

  return check;
}
4

1 回答 1

0

您通常应该在任何可能生成响应的操作之后阅读响应。

如果您不这样做,一个简单的解决方案是循环读取响应,直到您将队列排空。

您可以重置仪器(可能是 *RST),但您也可能会失去其他状态。您将不得不检查它的文档以查看是否有仅重置响应队列的命令。检查文档始终是一个好主意,因为精确符合规范的仪器数量与以独特方式增加或省略部件的数量相比相形见绌。

于 2012-07-20T14:42:28.820 回答