|
正在做GPIB开发,用STM32驱动TNT5002作GPIB设备,在NI网站一找到一个软件包ESP-488,把程序移植到STM32上后可以通过GPIB和上位机通信了,但每次上位机发送一个SCPI指令给STM32后,STM32回复上位机之前TNT5002都会产生一个超时错误,下面是main函数的代码
- #include <stdio.h>
- #include <stdlib.h>
- #include <termios.h>
- #include <unistd.h>
- #include "gpmc.h"
- #include "NGPIB_IO.h"
- #include "IO_PARAM.h"
- #include "main.h"
- int flag = 0;
- char buf[50];
- int main(void)
- {
- char keystroke;
- int spoll_count=0;
- Mem_Init();
- Gpmc_Init();
- Initialize_Interface(); /* Initialize TNT */
- Set_Timeout(0xc,TRUE); /* Change timeout to 1 sec. */
- Set_4882_Status(SRE,0x10); /* Set SRQ on MAV */
- Set_Address_Mode(0); /* Set to single primary mode */
- Change_Primary_Address(12); /* Set primary address */
- while(keystroke!='q')
- {
- /* Loop until 'q' pressed */
- do
- {
- if(Read_GPIB_Lines()&0x8000)
- printf("\nATN asserted");
- Update_INTERFACE_STATUS(); /* Update status word */
- usleep(1000);
- }
- while(Read_GPIB_Lines()&0x8000); /* Continue when ATN not asserted Update_INTERFACE_STATUS()*/
- /* calls CPT_Handler() which validates the HS488 and mult- */
- /* primary addresses. These bytes must be read from the GPIB*/
- /* before an I/O function can be called. */
- //当ATN未断言时继续Update_INTERFACE_STATUS()调用CPT_Handler(),该CPT_Handler()验证HS488和多主地址。
- //必须先从GPIB读取这些字节,然后才能调用I/O功能。
- if(INTERFACE_STATUS&SPOLL)
- {
- /* If SPOLL set */
- Set_4882_Status(STB,spoll_count++); /* Set count of SPOLL */
- Clear_4882_Status(STB,0xff); /* Clear STB */
- }
- else if(INTERFACE_STATUS&LACS)
- {
- /* If listen addressed */
- Receive(buf,50,EOI); /* Read up to 50 bytes */
- /*************************************
- *
- * Parse commands/data
- *
- *************************************/
- if( strcmp(buf , "*IDN?\n") == 0 )
- {
- flag = 1;
- }
- else if( strcmp(buf , "1234\n") == 0 )
- {
- flag = 2;
- }
- else if( strcmp(buf , "56\n") == 0 )
- {
- flag = 3;
- }
- else if( strcmp(buf , "78900\n") == 0 )
- {
- flag = 4;
- }
- else
- {
- flag = 0;
- }
- if(DATA_COUNT>0)
- {
- /* If bytes were received */
- Set_4882_Status(STB,0x10); /* Set MAV bit in STB */
- /* Print to stdio */
- printf("\nReceived %lu data bytes\n",DATA_COUNT);
- printf("\nReceive %x = %s\n",buf, buf);
- }
- }
- else if(INTERFACE_STATUS&TACS)
- {
- /* If talk addressed */
- /* Send status data */
- if( flag ==0 )
- {
- DATA_COUNT = 0;
- flag = 0;
- }
- if( flag == 1 )
- {
- flag = 0;
- Send("flag = 1",8,EOI);
- }
- if( flag == 2 )
- {
- flag = 0;
- Send("flag = 2",8,EOI);
- }
- if( flag == 3 )
- {
- flag = 0;
- Send("flag = 3",8,EOI);
- }
- if( flag == 4 )
- {
- flag = 0;
- Send("flag = 4",8,EOI);
- }
- if(DATA_COUNT>0)
- {
- Clear_4882_Status(STB,0x10); /* Clear MAV bit */
- /* If data bytes sent print it */
- printf("\nSent %lu data bytes",DATA_COUNT);
- }
- }
- if(INTERFACE_STATUS&ERR)
- {
- /* If EABO report it */
- //INTERFACE_ERROR = ENOL(1):没有听者
- //INTERFACE_ERROR = EARG(2):函数参数错误或不能进行某种参数设置
- //INTERFACE_ERROR = EABO(3):超时
- printf("\nGPIB error has occured (INTERFACE_ERROR = %d)",INTERFACE_ERROR);
- INTERFACE_STATUS&=~ERR;
- }
- }
- Interface_Off(); /* Disable interface */
- Gpmc_free();
- Mem_free();
- return 0;
- }
复制代码
初始化中的Set_Timeout(0xc,TRUE); 函数没搞明白作用,而且如果我这里设置的超时时间是1秒,那上位机发送SCPI指令后TNT5002要过1秒才会回复上位机,没有明白这个超时的作用是什么,还有为什么INTERFACE_STATUS会报错误,附上ESP-488软件包,请大家帮我看看,谢谢
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|