我想使用 .NET 使用 PCI-7250 NuDAQ 卡打开继电器。
我知道在VB中打开的代码是:
card = Register_Card(PCI_7250, 0)
v = DO_WritePort(card, 0, &O17)
并关闭:
v = DO_WritePort(card, 0, &O0)
我需要将此迁移到 C# 代码。谁能帮我解决这个问题?
如果你想走读/写 I/O 端口的方式,你需要能够写它们。.net 框架(至少是 windows 上的微软)不直接支持这一点。对于并行端口的读/写,我在 InOut32 库(链接)方面取得了巨大成功。这意味着您必须使用 PInvoke 才能使其工作。对我来说,这段代码有效:
[DllImport("inpoutx64.dll", EntryPoint = "Out32")]
private static extern void OutputImpl(int adress, int value);
[DllImport("inpoutx64.dll", EntryPoint = "Inp32")]
private static extern int InputImpl(int adress);
public static void Output(int adress, int value)
{
// I use this wrapper to set debug breakpoints so I can see what's going on
OutputImpl(adress, value);
}
public static int Input(int adress)
{
int ret = InputImpl(adress);
return ret;
}
请注意,如果您运行的是 32 位应用程序,则需要引用“InOut32.dll”库。我不确定您需要使用的特定端口,但我想您可以在互联网上找到它们,或者从您的 PCI 卡配置的 IO 地址范围中尝试一些(请参阅设备管理器中的设备属性)。