Discussion:
Visual Basic 6.0 buffered acess to NI 6534
(too old to reply)
braunb
2006-10-04 12:40:09 UTC
Permalink
Hello,

I want to write data in to the fifo of the  NI6534 I/0-card. 
After then I will  generate an  data outpu stream  with
by using the internal clock source.
I use Visual Basic 6.0 from Microsoft Excel.

My example compiles well, but I got a runtime error by following function call:

DAQmxErrChk
DAQmxCfgSampClkTiming(taskHandle, "", 1000, DAQmx_Val_Rising,
DAQmx_Val_AcquisitionType_FiniteSamps, 32)



Who has an idea, which would be the reason for this runtime
error! I guess it is a variable presentation problem of the variable
rate. Is that function usable in VB6.0 or works this function only in a
C enviroment?


 the whole example below:

Dim sampsPerChanWritten As Long
Dim test As Long
Dim taskHandle As
Long
Dim delay As Double
Dim status As Integer
Dim data(256)
As Byte

Private Sub
Port_Out_Click()

    DAQmxErrChk
DAQmxCreateTask("", taskHandle)
    DAQmxErrChk
DAQmxCreateDOChan(taskHandle, "Dev3/port0", "",
DAQmx_Val_ChanForAllLines)
    DAQmxErrChk
DAQmxCfgSampClkTiming(taskHandle, "", 1000, DAQmx_Val_Rising,
DAQmx_Val_AcquisitionType_FiniteSamps, 32)
   

    For i = 0 To 255
        data(i) = 1
     Next
i
     
   
DAQmxErrChk DAQmxWriteDigitalLines(taskHandle, 32, False, 10#,
DAQmx_Val_GroupByChannel, data(0), sampsPerChanWritten, ByVal
0&)
   
 
  DAQmxErrChk DAQmxStartTask(taskHandle)
   
DAQmxErrChk DAQmxWaitUntilTaskDone(taskHandle, 10)
    DAQmxErrChk DAQmxClearTask(taskHandle)

End Sub


Public Sub
DAQmxErrChk(errorCode As Long)
'

'   Utility function to handle errors by recording the
DAQmx error code
'   and message.

'
    Dim errorString As
String
    Dim bufferSize As Long

    Dim status As Long
   
If (errorCode < 0) Then
        ' Find out
the error message length.
        bufferSize =
DAQmxGetErrorString(errorCode, 0, 0)
        '
Allocate enough space in the string.
       
errorString = String$(bufferSize, 0)
        '
Get the actual error message.
        status =
DAQmxGetErrorString(errorCode, errorString, bufferSize)
        ' Trim it to the actual length, and display the
message
        errorString = Left(errorString,
InStr(errorString, Chr$(0)))
        Err.Raise
errorCode, , errorString
    End If


   
End
Sub
braunb
2006-10-05 11:10:09 UTC
Permalink
Sorry Robert,

that will not remove the runtime error !!

DAQmxErrChk DAQmxSetBufOutputBufsize(taskHandle,4)

I put the instruction just before the function call where the runtime error occurs.

Please could you run my code fragment on your computer by using VisualBasic 6.0
and post me what happens.

Thank you

Bernd Braun
braunb
2006-10-05 13:10:11 UTC
Permalink
Hello Robert,

it makes no sense to put the instruction below. Because the program stops with runtime error before reading
that statement.

I don't know why my example runs on your environment and not on my computer. I use Visual Basic 6.0 from
Excel mybe that will be the different.

I tried it out burt with no success


best regards

Bernd Braun
braunb
2006-10-06 09:10:09 UTC
Permalink
Hello Robert,

I have extracted the code which manages the IO acess to NI 6534. In the example the output to the
IIO card works in unbuffered mode for an IO-acess for  one byte (8 bit)

Following code works on my computer:

Public Sub write_port(port, writeValue)
   ' Write zeros or ones to the digital lines
    Dim writeArray(0 To 7) As Byte
    Dim wert As Byte
    Dim sampsPerChanWritten As Long
   
  ' Configure port
    configure_write_port (port)
   
    For i = 0 To 7
     wert = Dec2BinLine(writeValue, i)
     If wert = 1 Then
       writeValue = writeValue - 2 ^ (7 - i)
     End If
     writeArray(i) = wert
    Next
    DAQmxErrChk DAQmxWriteDigitalLines(taskHandle, 1,
True, 10#, DAQmx_Val_GroupByChannel, writeArray(0),
sampsPerChanWritten, ByVal 0&)
  'Clear Task
  DAQmxStopTask (taskHandle)
  DAQmxClearTask (taskHandle)
End Sub
--------------------------------------------------------------------------------------------------
Comments :

The subroutine write_port(port,value) is called from main with the parameter

Public Sub configure_write_port(port)


' Configure port


    DAQmxErrChk DAQmxCreateTask("", taskHandle)


    DAQmxErrChk DAQmxCreateDOChan(taskHandle, port, "", DAQmx_Val_ChanForAllLines)


    DAQmxErrChk DAQmxStartTask(taskHandle)


End Sub

The function Dec2BinLine(writeValue, i) converts the value into binary. So each of the 8 bytes contents the value "0" or "1"



'Rückgabe von 0 bzw. 1 aus einer Zahl 0 ..255

Public Function Dec2BinLine(dwert, position)

 Dim val As Byte

 

  If dwert >= 2 ^ (7 - position) Then

   val = 1

  Else

   val = 0

  End If

  Dec2BinLine = val

End Function

port = "Dev3/port0"     because the NI 6534 is Dev3
writeValue                    is integer  (0 to 255)

 
That will work sucessful, I had checked it with the Logic Analyzer on the outputs of port0

In a version which the writeArray is filled with values type of integer an error occurs.

May be you can give me answers to following question:

1. Why have I to convert the integer value into bytes ?

Thanks you for your answer

best regards

Bernd

Loading...