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