11-18-2010 03:10 PM
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.LoadDevice(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.Text, 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
Solved! Go to Solution.
11-19-2010 10:28 AM
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
11-19-2010 10:38 AM
Anywhere to get the examples. When I installed DAQmx on Windows7 the examples for VB were nowhere to be found...
11-19-2010 11:38 AM
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
11-19-2010 08:27 PM
That option was already selected and still there are no VB6 sample programs installed anywhere I can find on the system...
11-21-2010 01:46 PM
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?
11-21-2010 08:48 PM
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.
11-23-2010 11:58 PM
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"
11-29-2010 10:36 AM
Hello,
Are you able to run any of the example programs with no errors?
Best Regards,
Adam G
11-29-2010 10:53 AM
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