Dear All,
I am using NI6009 USB Device and programming on VB 6.0. I am using a sample program from the examples given in the NI DAQMX base software. I need to display a textbox and increment a count everytime a signal is recieved as input. I have defined a text box for the same as well as a checkbox. The checkbox value changes to 0 and 1 everytime I pres a switch connected to give input to the device. However I am not able to display the Count value in the Textbox.
If I define a msgbox command to display the count, the count is properly displayed along with the textbox. But not so otherwise.
I am also not able to stop the program. It just hangs up and the application has to be closed forecefully ie CRTL+ALT+DEL. In some instances it crashes the OS itself I am using WinXP with SP2, VB6.0 with SP6
i am enclosing the code also.
'/*********************************************************************
'
' Visual Basic 6.0 Example Program:
' ReadDigChan.frm
'
' Example Category:
' DI
'
' Description:
' This example demonstrates how to read values from one or more
' digital input channels.
'
' Instructions for Running:
' 1. Select the digital lines on the DAQ device to be read.
' Note: The array is sized for 8 lines, if using a different
' amount of lines, change the number of elements in the
' array to equal the number of lines chosen.
'
' Steps:
' 1. Create a task.
' 2. Create a Digital Input channel. Use one channel for all
' lines.
' 3. Call the Start function to start the task.
' 4. Read the digital data.
' 5. Call the StopTask module to stop and clear the task.
' 6. Display an error if any.
'
' I/O Connections Overview:
' Make sure your signal input terminals match the Lines I/O
' Control. In this case wire your digital signals to the first
' eight digital lines on your DAQ Device.
'
'*********************************************************************/
Option Explicit
Private taskIsRunning As Boolean
Private taskHandle As Long
Private Sub Command1_Click()
DAQmxErrChk DAQmxStopTask(taskHandle)
DAQmxErrChk DAQmxClearTask(taskHandle)
startCommandButton.Enabled = True
taskIsRunning = False
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub startCommandButton_Click()
Dim sampsPerChanRead As Long
Dim data As Long
Dim numBytesPerSamp As Long
Dim i As Integer
Dim bufferSize As Long
Dim channelList As String * 255
Dim arraySizeInBytes As Long
Dim readArray() As Byte
Dim PCount, j, PCount1 As Integer
PCount = 1
j = 0
On Error GoTo ErrorHandler
startCommandButton.Enabled = False
If ValidateControlValues Then
startCommandButton.Enabled = True
Exit Sub
End If
arraySizeInBytes = 100
bufferSize = 1000
' Re-initialize a dynamic array to hold values read off the digital lines
ReDim readArray(arraySizeInBytes)
' Create the DAQmx task.
'A:
DAQmxErrChk DAQmxCreateTask(" ", taskHandle)
'DAQmxErrChk (DAQmxCfgInputBuffer(taskHandle, 100000))
' Add a digital input channel to the task.
DAQmxErrChk DAQmxCreateDIChan(taskHandle, digitalLinesTextBox.Text, "", DAQmx_Val_ChanForAllLines)
' Start the task running, and read from the digital lines.
DAQmxErrChk DAQmxStartTask(taskHandle)
A:
'DAQmxErrChk DAQmxReadDigitalLines(taskHandle, 1, 10#, _
DAQmx_Val_GroupByChannel, readArray(0), arraySizeInBytes, _
sampsPerChanRead, numBytesPerSamp, ByVal 0&)
DAQmxErrChk (DAQmxReadDigitalU8(taskHandle, 1, 10#, True, readArray(0), arraySizeInBytes, sampsPerChanRead, ByVal 0&))
'For i = 0 To 3
'#########################
If readArray(0) = 0 Then
'PCount1 = PCount - 1
'MsgBox PCount1
PCount = PCount + 1
End If
'#########################
bitCheckBox(i) = readArray(i)
Text1.Text = PCount
'Next
' Display a window indicating the number of samples per channel read.
' samplesPerChannelReadLabel.Caption = "Samples / Line Read = " & sampsPerChanRead
' samplesPerChannelReadLabel.Visible = True
' All done!
StopTask
GoTo A
Exit Sub
ErrorHandler:
If taskIsRunning = True Then
DAQmxStopTask taskHandle
DAQmxClearTask taskHandle
taskIsRunning = False
End If
startCommandButton.Enabled = True
MsgBox Err.Number & " " & Err.Description, , "Error"
End Sub
Private Sub StopTask()
'DAQmxErrChk DAQmxStopTask(taskHandle)
'DAQmxErrChk DAQmxClearTask(taskHandle)
'startCommandButton.Enabled = True
'taskIsRunning = False
End Sub
Private Function ValidateControlValues()
ValidateControlValues = 0
If digitalLinesTextBox.Text = "" Then
MsgBox "Please fill in all empty fields.", , "Error"
ValidateControlValues = 1
End If
End Function
Private Sub Form_Load()
taskIsRunning = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
If taskIsRunning = True Then
StopTask
End If
End
End Sub
'********************************************************