Help with Asynchronous Communication with U3-HV | LabJack

Help with Asynchronous Communication with U3-HV

2 posts / 0 new
Last post
mulia's picture
Help with Asynchronous Communication with U3-HV

Hi..Im new with LabJack

Currently i try to acquire some data streamed from an analyzer. It needs some string like " ?SEND:XX " for it to return some data to be read by my U3-HV 1.30. Im using VB6 and managed to send the required string to the analizer. The problem is that my application cannot properly reads the reply from the analyzer. Most of the time the app reads some random characters instead of the desired numbers of 20 to 30 characters length, it is rarely to have correct reply. FYI my comm. setup is: 8-n-1 at 9600 kbps and IC MAX232 added to the line.

Please help regarding how can my vb6 app can read the correct replies from the analyzer instead random characters. Thank you very much

My source code is the modifed sample code from Labjack as follows:

'  U3_Asynch.vb
'   Demonstrates asynchronous communication using a loopback from
'   FIO4 to FIO5 on a U3 rev 1.30.  On earlier hardware revisions
'  use SDA and SCL.
[email protected]
'  July 1, 2009

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

'Not sure if there is any reason not to do Option Explicit.  It helps
'avoid typo related errors.
Option Explicit

Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Command1_Click()

'On Error GoTo ErrorMessage
    Dim lngError As Long
    'long lngGetNextIteration
    'long lngIOType=0, lngChannel=0
    'double dblValue=0
    Dim lngHandle As Long
    lngHandle = 0
    Dim i As Integer
    i = 0
    'double numI2CBytesToWrite
    Dim numBytes As Double
    Dim datArray(10) As Byte
    Dim datArrayR(100) As Byte
    'Open the LabJack.
    lngError = OpenLabJack(LJ_dtU3, LJ_ctUSB, "1", 1, lngHandle)
    If lngError <> 0 Then Err.Raise lngError + 50000

    'Start by using the pin_configuration_reset IOType so that all
    'pin assignments are in the factory default condition.
    lngError = ePut(lngHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0)
    If lngError <> 0 Then Err.Raise lngError + 50000

    ' 1 MHz timer clock base.
    ''lngError = ePut(lngHandle, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_BASE, LJ_tc48MHZ, 0)
    ''If lngError <> 0 Then Err.Raise lngError + 50000

    ' Set clock divisor to 1, so timer clock is 1 MHz.
    ''lngError = ePut(lngHandle, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_DIVISOR, 0, 0)
    ''If lngError <> 0 Then Err.Raise lngError + 50000

    ' Set timer/counter pin offset to 4. TX and RX appear after any timers and counters on U3
    ' hardware rev 1.30.  We have no timers or counters enabled, so TX=FIO4 and RX=FIO5.
    lngError = ePut(lngHandle, LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 4, 0)
    If lngError <> 0 Then Err.Raise lngError + 50000

    ' Set data rate for 9600 bps communication.
    lngError = ePut(lngHandle, LJ_ioPUT_CONFIG, LJ_chASYNCH_BAUDFACTOR, 63000, 0)
    If lngError <> 0 Then Err.Raise lngError + 50000

    ' Enable UART.
    lngError = ePut(lngHandle, LJ_ioASYNCH_COMMUNICATION, LJ_chASYNCH_ENABLE, 1, 0)
    If lngError <> 0 Then Err.Raise lngError + 50000

    ' Transmit
    numBytes = 6
    datArray(0) = 95
    datArray(1) = 83
    datArray(2) = 69
    datArray(3) = 78
    datArray(4) = 68
    lngError = eGet_ByRef(lngHandle, LJ_ioASYNCH_COMMUNICATION, LJ_chASYNCH_TX, numBytes, datArray(0))
    If lngError <> 0 Then Err.Raise lngError + 50000
    numBytes = 100  'Dummy values so we can see them change.
    i = 0
    lngError = eGet_ByRef(lngHandle, LJ_ioASYNCH_COMMUNICATION, LJ_chASYNCH_RX, numBytes, datArrayR(i))
    If lngError <> 0 Then Err.Raise lngError + 50000
    Text1.Text = i
    i = i + 1
    Loop Until i = 30
    i = 0
    'Display the read data.
        If numBytes <> 0 Then
            preReadDisplay.Text = numBytes
            readDisplay.Text = Chr(datArrayR(0)) + Chr(datArrayR(1)) + Chr(datArrayR(2)) + Chr(datArrayR(3)) + Chr(datArrayR(4))......
        End If
End Sub

Private Sub Form_Load()
 readDisplay.Text = "                                                                                          "
End Sub


LabJack Support
LabJack Support's picture
So you send an asynchronous

So you send an asynchronous serial command to your device, and you expect it to immediately respond with a bunch of data?  How much data?

I suggest you do a loop back test where you remove the connections to your device and instead just connect Tx to Rx.  Try it with and without the MAX233.  Transmit data that mimics the data you expect to receive back, and see if you get the proper data back.  If that works right, you might then need to use a scope or logic analyzer to see what is different about the signal in the loopback test compared to the signal sent by your device.