I'm new to .NET. I have an application that is running in VB6. It sends text through COM1 port to another device.
When I converted the VB6 code to .NET the string it sends out is different! I have tried so many things and don't know what to do. I used a serial data analyzer and found the two strings are different even the the source code is the same.
when I convert a number using System.Convert.ToChar(X) and sends it through serial the X can only be hex: 0 to hex:3F if I want to get the correct value from the other side. Any value greater than hex:3F will not be hex:3F.
for example if I send
hex:64 you will get hex:3F
send hex:E8 you will get hex:3F
It seems like it max out with a 6 bit register value,
Please help me correct this mess ...
By default, SerialPort uses ASCIIEncoding to encode the characters. ASCIIEncoding encodes all characters greater then 127 as (char)63 or '?'. To support additional characters in that range, set Encoding to UTF8Encoding, UTF32Encoding, or UnicodeEncoding.
TCP Sockets do the same thing.
If you read the data from a file using Binaryreader and send it to the port as binary no encoding takes place.
I struggled with this for a while before I found the binary method. I have not tryed the convert to byte method, Instead I had used read bytes and sent the bytes to the port. I was able to get an exact file copy through the port using that method whereas in VB6 there was no need to read the file as binary.