Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Visual Basic 6.0 buffered acess to NI 6534

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





0 Kudos
Message 1 of 10
(4,964 Views)
hello braunb,

could you provide the runtime error, which occurs?

regards,

robert h
NI germany
0 Kudos
Message 2 of 10
(4,950 Views)
The following error message  occurs

runtime error '-200077(ffcd273)':

Requested valuse is not a supported value for this property
0 Kudos
Message 3 of 10
(4,948 Views)
hello braunb,

the error occurs because of a too small output buffer size.
the minimum value, which could be set is 4.

you can do this by calling:
DAQmxSetBufOutputBufSize(TaskHandle taskHandle, uInt32 data);
before you call the write function.

hope this helps,
regards,

robert h
NI germany
0 Kudos
Message 4 of 10
(4,945 Views)
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


0 Kudos
Message 5 of 10
(4,943 Views)
hello braunb,

you must insert the function call after the timing is configured.

on my Visual Basic 6 it runs without problems.

regards,

robert h
0 Kudos
Message 6 of 10
(4,942 Views)
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



0 Kudos
Message 7 of 10
(4,939 Views)
hello bernd,

could you test the example, which is shipping with DAQmx?
it's located at:
"C:\Programme\National Instruments\NI-DAQ\Examples\Visual Basic 6.0\Digital\Generate Values\Write Dig Chan"

regards,

robert
0 Kudos
Message 8 of 10
(4,934 Views)
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

0 Kudos
Message 9 of 10
(4,925 Views)
hello bernd,

usually a digital port has 8 lines. so you have to pass a value of one byte in order to have one bit for each line.

regards,

robert
0 Kudos
Message 10 of 10
(4,875 Views)