Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

serial port with binary data


uta Jun 29, 2010 01:17 PM

Hi,
I have a sensor that communicates via serial port with binary data. It sends automatically without polling.

Using the terminal emulator function I get the following data (ASCII=no):

23 00 00 00 00 00 00 80 0D 01

this is correct data

23 = # -> start character
the next 6 bytes are always 00
8 -> configuration information from sensor
the following 3 halv bytes (here 0 0D) are the measurement value
last byte, 01 -> checkbyte, seems to be always 01

I use SerialOpen with mode 3 -> binary 8N1

I tried to use SerialIn and SerialInRecord with no success. There seems to be some data coming in, but not correct. There is well a problem with reading zero's (null character) ?!

I am trying to use SerialInBlock and MoveBytes but don't know how to use it correctly. How do I know where my start and end of the datastream is?

I am thinking about putting the 10 bytes in an array and picking out the right ones and convert them to decimal. But don't know how.

Any idea/sample code that can help me?
Thanks and best regards,

Uta


uta Jul 1, 2010 01:59 PM

Hi again,

now a bit more specific. I tried this:

Public NBytesReturnedCDOM
Public CDOMInLong(100) As Long
Public test

SequentialMode

BeginProg
SerialOpen (COM1,9600,3,0,100) '9600baud, binary, no parity 1 stopbit, 8 databits

Scan(2,Sec,1,0)

... some analog measurements....

Delay (1,500,msec)
test = SerialInChk (COM1)
NbytesReturnedCDOM = SerialInBlock(COM1,CDOMInLong,10)

NextScan
EndProg

I get e.g. the following:
CDOMInLong(1) = 587202560 = H23000000 always the same
CDOMInLong(2) = 128 = H80
CDOMInLong(3) = 721420288 = H2B012300 example

this is the whole string that is sendt (10 hex pairs)
23 00 00 00 00 00 00 80 0D 01

You can see that the program picks out som correct data.
I understand that the LONG type variable can just be 31 bits. How can I get my 10 bytes divided into reasonable parts?

Uta


uta Jul 2, 2010 09:09 AM

Thanks to some hints from Campbells technical support I got it done.

NbytesReturnedCDOM = SerialInBloc(COM1,CDOMInString,100)
ResultString1 = ASCII (CDOMInString(1,1,8))
ResultString2 = ASCII (CDOMInString(1,1,9))

If Resultstring1 >= 128 Then
range = 200 '200mg/l max range
ElseIf Resultstring1 < 128 Then
range = 20
Else
EndIf

part1 = ResultString1 - 128
part2 = ResultString2
Value1 = part1*256
Value2 = part2
CDOMdigital = Value1+Value2
CDOMdigitalFinal = range*(CDOMdigital/4095)

Log in or register to post/reply in the forum.