外部接口的体系结构->GBIP通过gpib总线连接到目标( linux)系统。Linux机箱内有从GPIB到主板的以太网电缆。
外部接口上的PIC_GPIB卡是IEEE 488.2。
我将从外部接口发送一个查询到linux框。
很少的情况
1)如果我发送一个不期望返回响应的查询,那么下一个查询发送就可以了。
2)如果我发送一个期望响应的查询,当我收到响应并读取它,然后启动下一个查询时,它就可以正常工作了。
但是如果我从外部接口发送一个查询并得到响应,而忽略读取响应,那么下一个查询就失败了。我请求对场景3.的帮助。
代码是在linux端完成的,它是一个套接字编程,它使用来自unistd.h的linux内置函数进行读写。
我的调查:我发现在外部接口上的gbib卡上有一个内部内存,它存储以前响应的值,直到读取为止。通常,我使用IEEE实用软件来编写通过read按钮进入linux盒和读取存储库的命令。
请有人告诉我,如何清除输入缓冲区或内存,其中存储的值,以便写从外部命令连体,而不打扰读取它。
我在linux端的代码是用C++和套接字编程开发的。我在bulit读写功能中使用了对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;
}发布于 2012-07-20 14:42:28
通常,在可能生成响应的任何操作之后,您都应该读取响应。
如果没有这样做,一个简单的解决方案就是在循环中读取响应,直到您将队列耗尽为空为止。
您可以重置仪器(可能*RST),但您可能也会失去其他状态。您必须检查它的文档,以确定是否有命令只重置响应队列。检查文档总是一个好主意,因为精确符合规范的仪器数量与以独特方式增加或省略部件的数量相比相形见绌。
https://stackoverflow.com/questions/11581160
复制相似问题