I'm writing a C# application that will receive serial data from 3 different COM ports configure with 8-bit UART with no parity. The other devices will be sending and receiving binary encoded HEX ex. AF01h = 10101010 00000001 two characters for each byte. I have set up virtual COM ports and a simple application for testing purposes and am sending data back and forth before I hook the devices up. I found that data is ASCII encoded by default on transmission and reception but I need both to be binary encoded HEX. I do not see that option in the encoding class and would rather not have the application using a complete different encoding than the 3 other devices. Right now I am using this code to convert the string when it is sent
string binarystring = String.Join(String.Empty, hexstring.Select(c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')));
sport.Write(binarystring);
txtReceive.AppendText("[" + dtn + "] " + "Sent: " + binarystring + "\n");
This works for testing transmission for now but i will eventually change the code to place the two digit hex number directly into a byte array.
This code will allow me to enter AF01h = 1010101000000001, but on the receiving end of the application I get 16 bytes of ASCII encoded characters. Is there a way I can get the app on the same page as the other devices?