First of all because you need a
binary communication consider that you cannot use the string methods.
It seems that the problem is the
Encoding that is set by default to
ASCIIEncoding that sets to '0' the MSbit of each sent or received bytes. The solution is to set it to a codepage 28591 or 1252:
SerialPort.Encoding = System.Text.Encoding.GetEncoding(28591)
SerialPort.Encoding = System.Text.Encoding.GetEncoding(1252)
The same problem in C#.
For more details
see[
^].
To code hex values in VB the correct syntax is:
Dim data As Byte() = {&HC0, &H63, &H07, &H66, &H00, &H01}
To send data use the
Write method and to read use the
Read or
ReadByte methods. The first if you expect a known lenght stream of bytes or the second if you want to read a byte at time and do other controls (i.e. time-ot, EOT End Of Transmission code, etc).