gpt4 book ai didi

c - 如何仅使用 ansi-c 在 Windows 计算机上连接 GPIB 设备

转载 作者:行者123 更新时间:2023-11-30 18:41:50 25 4
gpt4 key购买 nike

如何仅使用 ANSI-C 和可能的 Windows header 打开和关闭与 GPIB 设备的连接。

是否有默认方法可以执行此操作,或者 gpib 本质上涉及第三方驱动程序?

最佳答案

仅使用 Windows header 和 ANSI C...不太可能。如Adriano指出。

最简单的方法是使用 VISA libraries 。它们是(几乎)不同制造商之间的 GPIB 标准化接口(interface)...使用此库,您的代码和生成的可执行文件将不会关心您使用的 VISA 实现(下面链接的示例警告)...

您需要链接到 visa32.lib。可以在目录 $(VXIPNPPATH)/WinNT/lib/msc 中找到该文件。变量VXIPNPPATH,我认为默认设置为指向C:\Program Files (x86)\IVI Foundation\VISA\或相当于 32 位机器上的值。

C VISA 库的头文件可以在 $(VXIPNPPATH)/WinNT/include

中找到

请注意,根据您安装的 VISA 库的不同制造商使用 GPIB,您可能需要进行一些配置。例如,当使用 NI 的库成功连接到 Agilent 设备时,您必须启用 option described in this article .

我知道 NI 有一些示例程序您可以查看。打开和关闭设备的一般示例可能类似于...

ViStatus status;
ViChar buffer[80];
unsigned int board = 0, device = 10;

/* Open the default resource manage */
status = viOpenDefaultRM(&mVisaDefaultRM);
if (status < VI_SUCCESS)
exit(-1);

/* Construct a string describing the GPIB device to open and open it! */
sprintf(buffer, "GPIB%u::%u::INSTR", board, device);
status = viOpen(mVisaDefaultRM, buffer, VI_NULL, VI_NULL, &mVisaInst);
if (status < VI_SUCCESS)
{
viClose(mVisaDefaultRM);
exit(-1);
}

/* Close it */
viClose(mVisaInst);
viClose(mVisaDefaultRM);

然后,您可以使用 API 的其余部分执行各种操作...例如,要重置设备,您可能会编写类似...

/* Reset the device */
status = viEnableEvent(mVisaInst, VI_EVENT_SERVICE_REQ, VI_QUEUE, VI_NULL);
if( status >= VI_SUCCESS )
{
/* Send SDC (Selected Device Clear) to reset the information interchange
* between controller and instrument.
* Cleans input and output buffer, aborts operations that prevent
* processing of new commands etc. */
status = viClear(mVisaInst);
if (status >= VI_SUCCESS)
{
/* If the SDC successed progress onto reset the device and set it
* up for detecting SRQ events... */
Write("*CLS;"); /* Clear status command. Clears the whole status structure */
Write("*RST;"); /* Reset command. Abort all activities and initialise the device (instrument specific) */
Write("*SRE 255;"); /* Service request enable. Disable all service requests except ESB: 0010_0000 */
Write("*ESE 255;"); /* Standard event status enable. Disable all statuses except the errors and op complete: 0011_1101 */
}
}

if (status < VI_SUCCESS)
{
/* Do something */
}

National Instruments VISA API doc can be found here 的示例。我确信安捷伦和其他人也一定有他们的版本。关键是您的代码和生成的 EXE 不应该关心正在使用谁的实现...

最后一个小链接...我发现 this GPIB programming tutorial真正有用...

关于c - 如何仅使用 ansi-c 在 Windows 计算机上连接 GPIB 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19794670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com