NI LabVIEW,CVI,数据采集等产品讨论区

取消
显示结果 
搜索替代 
您的意思是: 

驱动TNT5002时 Timeout的问题

我再在用MCU驱动TNT5002,使用NI提供的ESP-488软件包,我把程序移植到我的平台上后可以正常接收上位机发送的SCPI指令,收到SCPI指令后可以发送数据回复上位机,上位机可以收到TNT5002发给它的数据,但每次在回复上位机前都会产生一个超时错误(INTERFACE_ERROR = 3),而且如果我设置的超时时间是1秒,上位机发送SCPI指令后TNT5002要间隔1秒才能回复上位机,请问Set_Timeout(0xc,TRUE); 这个超时的设置有什么作用?为什么每次回复上位机数据前INTERFACE_STATUS中的ERR标志都会置位?

下面是main函数的代码:

 

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

 

0 项奖励
1 条消息(共 1 条)
1,922 次查看