I'm trying to read data from a COM port which is sniffing a standard receipt printer. I'm using the example from MSDN regarding the SerialPort.DataReceived
event found in the docs.
I'm getting data but it's garbled characters. How do I convert that to readable text? Is it encoded binary or something? Can please you offer insights into this kind of serial port programming?
I've searched on the Internet for hours trying figure out how to make it readable text but I'm missing some concepts somewhere between A and B.
I've read somewhere it could be the protocol not matching up. Is there a way to detect this?
Update 1
I'm trying something new from a thread I found here at StackOverflow (I used Update 1) and I'm not sure what I'm looking at now but I get no more weird characters:
So how do I get readable text from here?
Update 2
I am still a little confused.
private static void port_OnReceiveDatazz(object sender,
SerialDataReceivedEventArgs e)
{
SerialPort spL = (SerialPort)sender;
byte[] buf = new byte[spL.BytesToRead];
Console.WriteLine("DATA RECEIVED!");
spL.Read(buf, 0, buf.Length);
Console.WriteLine(Convert.ToBase64String(buf));
foreach (Byte b in buf)
{
//Console.Write(b.ToString());
}
Console.WriteLine();
}