Question Serial Port Truncating

computer guy

Member
Joined
Feb 12, 2008
Messages
18
Programming Experience
Beginner
I am using the .Net Com port control to send &HFF (255) to another device however it appears to be truncating it. At the other end I get &H35 (53).
If I send &H0 (0) At the other end I get &H30 (48).

Does anyone know what may be causing this. I have the following settings:

PortName = "Com4"
Parity = IO.Ports.Parity.None
Handshake = IO.Ports.Handshake.None
StopBits = IO.Ports.StopBits.One
DataBits = 8
BaudRate = 9600
WriteBufferSize = 2048
WriteTimeout = -1
ParityReplace = 63


Thank you :)
 
Last edited:

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,334
Location
Norway
Programming Experience
10+
I sounds to me you are using Write(string), then know that default Encoding for SerialPort is ASCII, which goes to 127. Change Encoding.
 

computer guy

Member
Joined
Feb 12, 2008
Messages
18
Programming Experience
Beginner
What encoding should I be using for sending bytes 0 to 255?

Thank you :)
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,334
Location
Norway
Programming Experience
10+
I don't know what encoding your protocol requires, most encodings except ascii would have a character for that value. You could also send byte values if that is what your protocol expects. Use the programming documentation for your serial device.
 

computer guy

Member
Joined
Feb 12, 2008
Messages
18
Programming Experience
Beginner
Thank you. I worked it out just before you replied.
I can't believe I have been working on this for several hours.
 
Top Bottom