Posts: 1
Joined: Wed Oct 26, 2011 1:06 pm

Issue with starttrigger / endtrigger

Wed Oct 26, 2011 1:19 pm


I'm trying to parse a binary datastream. First 2 bytes are HEX 8181 and last 2 bytes are HEX 8282. I use the following code (in Visual Studio 2008, W7 X64) to define the triggers:

Dim bin_start As Byte() = {&H81, &H81}
Dim bin_end As Byte() = {&H82, &H82}
objPort.StartTrigger = SerialNET.Port.ByteArrayToString(bin_start)
objPort.EndTrigger = SerialNET.Port.ByteArrayToString(bin_end)

When i debug the program and check the trigger values i see that Starttrigger is "8181" and Endtrigger is "3F3F".

So somehow Starttrigger is set correctly but Endtrigger not. I use objport.OnRead to get the data and SerialNET.Port.StringToByteArray to convert to a byte array but no data come in. It seems OnRead does not fire.

Anyone suggestions?


EDIT: I suspect this has to do with the encoding that is used for strings in VB.NET 2.0 (Unicode). All bytes above h7F are converted to either h3F or a multiple-byte Unicode. It would be better to use an array of bytes to receive the binary data but then the Franson SerialTools are out of the window. Alternative is the SerialPort class.
It seems if i still want to use SerialTools i should change the Code Page:
System.Text.Encoding.GetEncoding(1252) or System.Text.Encoding.GetEncoding(28591) or System.Text.Encoding.Default
Not sure how to implement this yet. Any ideas?

Return to “SerialTools”