Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert VB.Net NiDAQmx code to VB6 NiDAQmx code?

Solved!
Go to solution

I have the following code written in VB.Net using NiDAQmx. I have the need to have the same code written in VB6. Can someone give me the equivalent calls in VB6 using NiDAQmx?

 

Imports NationalInstruments.DAQmx

Public Class frmDIO

    Private sPort As String = "Port1"
    Private sDevices() As String = Nothing
    Private sOutputLines() As String = Nothing
    Private sInputLines() As String = Nothing
    Private sPorts() As String = Nothing
    Private sSerialNumber As String
    Private sDeviceID As String

    Private Sub frmDIO_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sDAQDevice As String
        Dim sDAQPorts As String
        Dim sString As String

        sDevices = DaqSystem.Local.Devices
        sPorts = DaqSystem.Local.LoadDevice(sDevices(0)).DOPorts

        For Each sDAQDevice In sDevices
            cbDigitalIOCard.Items.Add(DaqSystem.Local.LoadDevi​ce(sDAQDevice).ProductType & " " & DaqSystem.Local.LoadDevice(sDAQDevice).DeviceID)
        Next sDAQDevice
        cbDigitalIOCard.Text = cbDigitalIOCard.Items(0)

        For Each sDAQPorts In sPorts
            cbPort.Items.Add(sDAQPorts)
        Next sDAQPorts
        cbPort.Text = cbPort.Items(0)
    End Sub

    Private Sub PortValue_Changed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Port1.PortValueChanged
        Dim digitalWriteTask As New Task()
        Dim OutputChannel As DOChannel
        Dim bInvertLines As Boolean
        Dim iSlashPos As Integer = cbPort.Text.IndexOf("/")
        Dim sPortName As String = cbPort.Text.Substring(iSlashPos + 1, cbPort.Text.Length - (iSlashPos + 1))

        If Port1.Inverted Then
            lblPortValue.Text = 255 - Port1.State
        Else
            lblPortValue.Text = Port1.State
        End If

        OutputChannel = digitalWriteTask.DOChannels.CreateChannel(cbPort.T​ext, sPortName, ChannelLineGrouping.OneChannelForAllLines)
("Dev1/Port1/Line0", "Line0", ChannelLineGrouping.OneChannelForEachLine)
        digitalWriteTask.Start()
        bInvertLines = OutputChannel.InvertLines
        digitalWriteTask.Stop()
        OutputChannel.InvertLines = Not chkPortInversion.Checked
        Dim writer As DigitalSingleChannelWriter = New DigitalSingleChannelWriter(digitalWriteTask.Stream​)
        writer.WriteSingleSamplePort(True, Decimal.ToUInt32(lblPortValue.Text))
        digitalWriteTask.Dispose()
    End Sub

End Class
0 Kudos
Message 1 of 13
(5,275 Views)

Hello,

 

If you are just going to be using Visual Basic the latest version of DAQmx to officially support it is DAQmx 9.0.2. I am including a link that tells where the programming reference is located and where examples are located for DAQmx. Have a great day!

 

Best Regards,

 

Adam G 

National Instruments
Applications Engineer
0 Kudos
Message 2 of 13
(5,252 Views)

Anywhere to get the examples. When I installed DAQmx on Windows7 the examples for VB were nowhere to be found...

0 Kudos
Message 3 of 13
(5,249 Views)

Hello,

 

By default the examples are not installed for VB6. If you go into add/remove programs and select NI Software then Uninstall/change it will bring up a listing of all NI Software on your computer. From here you can select the DAQmx driver you have installed and select modify. If you then look under the application support there will be an option for VB6 support. Enable this option then click next and it will install the support for VB6 along with the examples. Have a great day!

 

Best Regards,

 

Adam G 

National Instruments
Applications Engineer
0 Kudos
Message 4 of 13
(5,243 Views)

That option was already selected and still there are no VB6 sample programs installed anywhere I can find on the system...

0 Kudos
Message 5 of 13
(5,224 Views)

OK,

Finally found them. But cannot find any of the similar functions I used in the .Net version.

 

For instance:

 

    Private sDevices() As String = Nothing
    Private sPorts() As String = Nothing

        sDevices = DaqSystem.Local.Devices
        sPorts = DaqSystem.Local.LoadDevice(sDevices(0)).DOPorts

 

Where can I find these two functions?

0 Kudos
Message 6 of 13
(5,196 Views)

You need to use DAQmx properties and not functions. For example, one of the System propertites is DAQmxGetSysDevNames. The Device property DAQmxGetDevDOPorts will return the number of digital output ports.

0 Kudos
Message 7 of 13
(5,184 Views)

I tried the following:

 

Dim sDevices As String

Dim lReturn As Long

 

lReturn = DAQmxGetSysDevNames(sDevices, 256)

 

When I execute these lines I get a return value of 5 and nothing in sDevices

 

Any ideas?

 

Measurement & Automation reports a Device on "Dev1"

 

0 Kudos
Message 8 of 13
(5,157 Views)

Hello,

 

Are you able to run any of the example programs with no errors? 

 

Best Regards,

 

Adam G 

National Instruments
Applications Engineer
0 Kudos
Message 9 of 13
(5,099 Views)

Yes. But they do not include calls to these functions like DAQmxGetSysDevNames. When I include them in the example programs, I get the same results...

 

 

Dim sDevices As String

Dim lReturn As Long

 

lReturn = DAQmxGetSysDevNames(sDevices, 256)

 

When I execute these lines I get a return value of 5 and nothing in sDevices

0 Kudos
Message 10 of 13
(5,094 Views)