Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

multiple thread DAQMAx operation in Visual Basic 6

I am running a two thread application using VB6 in a window Xp OS. Both thread access two PCI  (6704 and 6025E) running on DaqMax 7.8 driver. Access from the two thread is asynchronous with potential for collision. Is DaqMax equipped to handle this situation. I am getting some error when attempting to read an onput voltage to PCI 6025E. Any suggestion as to why this happening, if DaqMax is indeed designed for multi thread operation as claimed by NI?
0 Kudos
Message 1 of 4
(3,476 Views)
Hi MoShaz,

What is the exact error that you get?  I'm curious to know whether the error you get is indeed due to something with regards to multi thread operations.  What exactly are you executing in both threads (reads, writes, file I/O, etc)?  Please provide more specifics so we can assist you further. 


Best Regards

Hani R.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,457 Views)
Hello Hani
 
The error I am getting is a run time error, VB does not give you reason, but ask you if you want to debug or run. If i choose debug. it shows where it stopped, it is always the Daqmax driver where it either read from PCI 6025E or write to PCI 6704, the result of reading volt process after error is 0 volt, which tells me that the process did not have the chance to finish. The two threads implements a simple ReadingVolt from PCI 6025E every two seconds to monitor temperature rise, while the other thread asynchronously writting volt to PCI 6704  to control a set of switchs by writing some voltages to them.
 
Again, I am not sure if DAqMax is equipped to handle this situation by queuing one instruction until the other is implemented?
 
I am including the two routines for evaluation:
 
1_Reading volt:
 
DAQmx_Val_NRSE = 10078
try:
    On Error GoTo catch
    mlngErrIdx = EnumDaqError.DaqErrWriting
    'Read the Device number
    intDevice = mDriversDefinitions.DefineDaqR
    'Compose the string representing the Cahannel string
    StrChnl = "Dev" & intDevice & "/ai" & Channel
    ' Clear before reading
'    lngStatus = AI_Clear(mintDevice)
   
    'First we create the Task
    DAQmxErrChk (DAQmxCreateTask("", taskHandle))

    'Next  we need to create a channel
    DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle, StrChnl, "", DAQmx_Val_NRSE, minVoltage, _
                                    maxVoltage, DAQmx_Val_VoltageUnits2_Volts, vbNullString))
    
    DAQmxErrChk (DAQmxReadAnalogScalarF64(taskHandle, 10, Voltage, ByVal 0))
 
I added this section, which I did not have the chance to try yet:

 '  Here we need to inquire if task is done before stopping
    DAQmxErrChk DAQmxIsTaskDone(taskHandle, BlnTaskDone)
    If BlnTaskDone Then
      DAQmxErrChk DAQmxStopTask(taskHandle)
      DAQmxErrChk DAQmxClearTask(taskHandle)
      GoTo finally
    Else
'      DAQmxErrChk DAQmxTaskControl(taskHandle, DAQmx_Val_Task_Abort)
       IntResponse = MsgBox("Read Task not Done", vbOKOnly)
       DAQmxErrChk DAQmxStopTask(taskHandle)
       DAQmxErrChk DAQmxClearTask(taskHandle)
    End If
 
 
2_The Volt Writting routine :
 
 ' Create task
    DAQmxErrChk DAQmxCreateTask("", taskHandle)
   
    If Channel > 15 Then ' current channel
        StrChnl = "Dev" & mintDevice & "/ao" & Channel
        DAQmxErrChk DAQmxCreateAOCurrentChan(taskHandle, StrChnl, "", 0#, 0.003, DAQmx_Val_CurrentUnits2_Amps, "")
        DAQmxErrChk DAQmxWriteAnalogScalarF64(taskHandle, 1, 10#, (Voltage / 1000), ByVal 0&)
    Else                  'Voltage channel
        StrChnl = "Dev" & mintDevice & "/ao" & Channel
        DAQmxErrChk DAQmxCreateAOVoltageChan(taskHandle, StrChnl, "", -5#, 5#, DAQmx_Val_VoltageUnits2_Volts, "")
        DAQmxErrChk DAQmxWriteAnalogScalarF64(taskHandle, 1, 10#, Voltage, ByVal 0&)
    End If
 
Again, I added this but did not try.

 '  Here we need to inquire if task is done before stopping
    DAQmxErrChk DAQmxIsTaskDone(taskHandle, BlnTaskDone)
    If BlnTaskDone Then
      DAQmxErrChk DAQmxStopTask(taskHandle)
      DAQmxErrChk DAQmxClearTask(taskHandle)
      GoTo finally
    Else
'      DAQmxErrChk DAQmxTaskControl(taskHandle, DAQmx_Val_Task_Abort)
       IntResponse = MsgBox("Write Task not Done", vbOKOnly)
       DAQmxErrChk DAQmxStopTask(taskHandle)
       DAQmxErrChk DAQmxClearTask(taskHandle)
    End If
0 Kudos
Message 3 of 4
(3,417 Views)

Hi MoShaz,

Please verify what version of DAQmx you are using by opening National Instruments Measurement & Automation Explorer (MAX), expanding the software tab on the left side and selecting NI-DAQmx. The 7.x series ended with 7.5 and then we started the 8.x series.

There is no problem running two sections of code simultaneously. They will automatically be multi-threaded. Your error most likely lies in the portion of code that is writing the analog out. My recommendation is to run the shipping examples for analog in and analog out simultaneously to verify functionality. Then work on combining them and making modifications to your code.

You can find the examples here.

Mark E.
Precision DC Product Support Engineer
National Instruments

0 Kudos
Message 4 of 4
(3,399 Views)