3,882
社区成员
发帖
与我相关
我的任务
分享 void open_port()
//************************************************************************************
// This function opens a port (the communication between the instrument and computer).
// Be sure that the GPIB address has been set in the 'GPIBAddr' variable before
// calling this routine.
//************************************************************************************
{
long start,finish;
char ch;
// Open the Visa session
errorStatus = viOpenDefaultRM(&videfaultRM);
// Open communication to the instrument
errorStatus = viOpen(videfaultRM, "ASRL1::INSTR", VI_TRUE, VI_TRUE, &vi);
// If an error occurs, give a message
if (errorStatus < VI_SUCCESS)
{
printf("Unable to Open port; check address.\nPress any key to exit.");
scanf("%c", &ch);
exit(1);
}
// Set the RS-232 parameters; refer to the 34970A and VISA documentation
// to change the settings. Make sure the instrument and the following
// settings agree.
errorStatus = viSetAttribute(vi, VI_ATTR_ASRL_BAUD, 115200);
errorStatus = viSetAttribute(vi, VI_ATTR_ASRL_DATA_BITS, 8);
errorStatus = viSetAttribute(vi, VI_ATTR_ASRL_PARITY, VI_ASRL_PAR_NONE);
errorStatus = viSetAttribute(vi, VI_ATTR_ASRL_STOP_BITS, VI_ASRL_STOP_ONE);
errorStatus = viSetAttribute(vi, VI_ATTR_ASRL_FLOW_CNTRL, VI_ASRL_FLOW_XON_XOFF);
// Set the instrument to remote
send_cmd ("SYSTem:REMote");
// Wait 1 second
time(&start);
finish=start + 1;
do
{
time(&start);
} while (start < finish);
}