Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use a USB-6008 with vb.net

I'm trying to talk to a USB-6008 with VB.net. I simply need to set analog out 0 to a voltage. That's it. Anyone have a simple example?
0 Kudos
Message 1 of 11
(8,522 Views)
Hi Breeyet,

The USB-6008 uses the DAQmxBase driver software. Currently, DAQmxBase is only officially supported in C and LabVIEW. However, I have found a way to get it to work in .NET languages.

You basically need to declare all of your DAQmxBase functions at the top of your program before using them. The link below describes how to do this in C#.NET and has an example attached. This process should be almost the same for VB.NET.

To get an idea of how to do analog output with your 6008, look at the shipping examples found here:
C:\Program Files\National Instruments\NI-DAQmx Base\Examples

These are C examples, but the functions are used exactly the same in VB.NET. Just make the same calls in the same order and it should work.


http://digital.ni.com/public.nsf/websearch/AF5F4827A953E7B286256F35005E4260?OpenDocument

-Sal
0 Kudos
Message 2 of 11
(8,494 Views)
When writing the wrappers, make sure to specify the calling convention to cdecl, since thats how the DAqmxBase functions have been declared. If you dont specify a calling convention attribute, the default of stdcall is used. Check out this link for more examples on DLLImport.
Bilal Durrani
NI
0 Kudos
Message 3 of 11
(8,488 Views)
Can anybody please provide some example of how this can be done for use in VB.NET?

THanks a million
0 Kudos
Message 4 of 11
(8,355 Views)
Here's an example that I came across for VB.NET.
-Alan A.

Message Edited by Alan A. on 06-03-2005 03:00 PM

0 Kudos
Message 5 of 11
(8,059 Views)
Dear Alan,
-The AI_mxBase_VB_DotNet example on how to read Analog input was very useful but we had the following error:
("Namespace or type 'UI' in the project-level Imports 'NationalInstruments.UI' cannot be found.")

-Do you Have another example for the digital input output and for the analog output.
We have the measurement studio .Net 2003, do you have examples for how to benefit from it for the USB-6008

Thank you
0 Kudos
Message 6 of 11
(7,804 Views)
Hello gab73,
You will need to add a couple .Net assemblies to use this program. You will need NationalInstruments.Common.dll, NationalInstruments.UI.dll, and NationalInstruments.UI.WindowsForms.dll. All of which install by default to this directory: C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Assemblies\Current. As for other examples, I simply don't think they exist at this particular point in time. DAQmx Base in VB.Net is not an extremely common combination. But you can use the previous example as a guide to creating your own.
-Alan A.
0 Kudos
Message 7 of 11
(7,771 Views)
Dear Allen

your example AI_mxBase_VB_dotNet.zip work very good !!

-> Do you Have another example for the digital input or/and output <-

We have USB-6009 and not the measurement studio .Net 2003, only VB.NET 2003

Thank you
0 Kudos
Message 8 of 11
(7,700 Views)
I am not aware of any digital i/o examples in vb.net for NI-DAQmx Base. However, the ai example shows how to use the NI-DAQmx Base functions, so you should be able to get a pretty good idea of how to go about it. Also, I would recommend looking at the C Examples for DIO(to see programming flow) that install here: Start>>All Programs>>National Instruments>>NI-DAQmx Base>>Examples>>C Examples.
-Alan A.
0 Kudos
Message 9 of 11
(7,655 Views)
Hello Allen









my translation from Ansi C -> VB.NET









[DAQmxBaseCreateDOChan,DAQmxBaseWriteDigitalU8]









P0.0..P0.7 and P1.0..P1.3 always 5 Volts









can you help me what's wrong ?









/*********************************************************/









_




Public Shared Function DAQmxBaseCreateDOChan(ByVal taskHandle As TaskHandle, ByVal lines As String, ByVal nameToAssignToLines As String, ByVal lineGrouping As Integer) As Integer









'int32 DAQmxBaseCreateDOChan (TaskHandle taskHandle, const char lines[ ], const char nameToAssignToLines[ ], int32 lineGrouping);




End Function









_




Public Shared Function DAQmxBaseWriteDigitalU8(ByVal taskHandle As TaskHandle, ByVal numSampsPerChan As Integer, ByVal autoStart As System.UInt32, ByVal timeout As Double, ByVal dataLayout As System.UInt32, ByVal writeArray As Integer, ByRef sampsPerChanWritten As Integer, ByRef reserved As System.UInt32) As Integer









'int32 DAQmxBaseWriteDigitalU8 (TaskHandle taskHandle, int32 numSampsPerChan, bool32 autoStart, float64 timeout, bool32 dataLayout, uInt8 writeArray[ ], int32 *sampsPerChanWritten, bool32 *reserved);




End Function














Private Function write_digital_usb()









' Task Parameters









Dim [error] As Integer = 0




Dim taskHandle As TaskHandle = Convert.ToUInt32(0)




' Channel parameters




Dim lines As String = "Dev1/port0"




Dim lineGrouping As Integer = 1 ' 1 = One Channel For All Lines [DAQmx_Val_ChanForAllLines]




Dim numSampsPerChan As Integer = 0 '0




Dim autoStart As System.UInt32 = Convert.ToUInt32(0)




Dim timeout As Double = 1.0




Dim writeArray As Integer = 1 'bit 0000 0001




Dim sampsPerChanWritten As Integer




Dim dataLayout As System.UInt32 = Convert.ToUInt32(0) ' 0 = Group by Channel [DAQmx_Val_GroupByChannel]





[error] = DAQmxBaseCreateTask("", taskHandle)




[error] = DAQmxBaseCreateDOChan(taskHandle, lines, Nothing, lineGrouping)




[error] = DAQmxBaseStartTask(taskHandle)




[error] = DAQmxBaseWriteDigitalU8(taskHandle, numSampsPerChan, autoStart, timeout, dataLayout, writeArray, sampsPerChanWritten, Nothing)




[error] = DAQmxBaseStopTask(taskHandle)




[error] = DAQmxBaseClearTask(taskHandle)




End Function









/*********************************************************/














Thank you in advance for your Support









Werner G.

Message Edited by Werner G. on 07-01-2005 09:32 AM

0 Kudos
Message 10 of 11
(7,624 Views)