【问题标题】:Flush queued GPIB responses刷新排队的 GPIB 响应
【发布时间】:2012-07-20 14:14:35
【问题描述】:

架构->外部接口的GBIP通过gpib总线连接到目标(linux)系统。 在 Linux 盒子里面,有从 GPIB 到主板的以太网电缆。

外部接口上的 PIC_GPIB 卡是 IEEE 488.2

我正在从外部接口向 linux 机器发送查询。

几个场景

1) 如果我发送一个不期望回复的查询,那么下一个查询发送将起作用。

2) 如果我发送一个期望返回响应的查询,并且当我收到响应并阅读它然后触发下一个查询它工作正常。

3) 但是如果我从外部接口发送查询并得到响应并且我忽略读取响应,那么下一个查询将失败。 我正在请求方案 3 的帮助。

编码是在 linux 端完成的,它是一个套接字编程,它使用 unistd.h 中的 linux 内置函数进行读写。

我的调查:我发现外部接口的 gbib 卡上有一个内部存储器,它存储先前响应的值,直到我们读取。通常我使用 IEEE 字符串实用软件来编写进入 linux 盒子的命令并通过读取按钮读取 reposne。

有人可以指导我如何清理输入缓冲区或存储值的内存,以便从外部命令继续写入而无需阅读它。

我在 linux 端的代码是用 C++ 和套接字编程开发的。我在 buli 中使用了读写函数来读写 gpib 和 json 服务器。

示例代码如下所示

    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;
}

【问题讨论】:

  • 这段文字太混乱了..请尝试改写...

标签: c++ linux embedded gpib


【解决方案1】:

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

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

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

【讨论】:

  • 感谢您的建议,我已经发布了我的示例代码,但我想它没有按预期工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-28
  • 1970-01-01
  • 2020-08-24
  • 1970-01-01
  • 2010-10-22
  • 1970-01-01
相关资源
最近更新 更多