Hi,

I need to make a software that communicates with an external digital device. The problem is that the device is utilising a special kind of protocol and I am not sure how can I implement it in Visual Basic. The details are as follows:

All communication is performed in a standard message format as shown below,

--------------------------------------------------------------------
STX | Address | Command | Sequence No | Data | BCS 2 | BCS 1 | ETX |
--------------------------------------------------------------------

Where,

STX = 1 byte (Hex code: 02h), Start of transmission marker

Address = 1 byte (A - Z), Address of the slave to which the message is relevant

command = 1 byte (Hex code: 30h - 5Ah), Command type. Specifies the command to be executed by the slave immediately or the data structure that follows in the data field.

Sequence No= 1 byte (0 or 1), Always 0 for single transmission command types or toggled for successive frames of the same command type, to enable detection of retransmissions.

Data= 0 - 1000 bytes, The data associated with the command type

BCS2 = 1 byte, Least significant digit of block check character <Checksum>

BCS1 = 1 byte, Most significant digit of block check character <Checksum>

ETX = 1 byte (Hex code: 03h), End of transmission marker.


Note - Transmission Block Checksum: It is the XORSUM of all bytes starting and including STX and ending with and including the last data character. The BCS is transmitted as ASCII Hex, the least significant digit transmitted first.

ASCII characters 02h (STX) and 03h (ETX) are used as communication block delimeters.

The communication buffer size is 13 bytes maximum for Transmitter and receiver (Half duplex).

I would like for example to send a request to the digital device asking it what is its status by sending it the command "?". To do that I need to send the following protocol command:

---------------------------------------------
STX | Address | Command | BCS2 | BCS1 | ETX |
---------------------------------------------

Where

Address= "A"
Command = "?"

The response from the digital device would be of the of the form:

--------------------------------------------------------------
STX | Address | X | Status Byte | Weight | BCS2 | BCS1 | ETX |
--------------------------------------------------------------

where X = "?" if there is a new A/D conversion since the last value measurement
X = " " if there is no A/D conversion since the last measurement
and Weight: 5 digits + decimal point if any (ASCII, MSD FIRST).


Could you please provide me with a sample code so that I can be started with the above? I am really confused and I don't really don't know how to implement the above protocol communication. I would be very grateful if you could send me some samples. I als don't know how can I transmit the STX and ETX.

Thanks,
H.