Reputation: 59
I would like to switch on a relay using a PCI-7250 NuDAQ card using .NET.
I know that the code in VB to turn on is:
card = Register_Card(PCI_7250, 0)
v = DO_WritePort(card, 0, &O17)
and to turn off:
v = DO_WritePort(card, 0, &O0)
I need to migrate this to C# code. Can anyone help me out with this?
Upvotes: 0
Views: 2422
Reputation: 818
If you want to go the way of reading/writing I/O ports, you need to be able to write them. The .net framework (the microsoft one on windows atleast) does not support this directly. For reading/writing to parallel ports i'm having great success with the InOut32 library (link). This means you will have to use PInvoke to make it work. For me this code works:
[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;
}
Note that if you are running a 32 bit application you will need to referrence the "InOut32.dll" library. I am unsure about the specific ports you need to use, but I imagine you can either find them on the internet, or give it a few tries some from your PCI cards configured IO address range (see the deveice's properties in the device manager).
Upvotes: 1