I have a weighing machine that is connected to a computer using a serial port. It is a very old machine and we are trying to get the weights off it and save in a database.
The weight returned by the machine has some invalid characters like ?
, and the weight is displayed as ??2?0
, where it should have been 02220
.
I understand it has something to do with encoding as results on a web search suggest. But I can not figure out what exactly am I missing.
Here is my code:
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// This method will be called when there is data waiting in the port buffer
// Read all the data waiting in the buffer
// string data = comport.ReadExisting();
// Display the text to the user in the Rich Text Box
Log(LogMsgType1.Incoming, s);
}
public void OpenThisPort()
{
bool error = false;
// If the port is open, close it
if (comport.IsOpen)
{
comport.Close();
}
else
{
comport.BaudRate = int.Parse("1200");
comport.DataBits = int.Parse("8");
comport.StopBits = StopBits.One;
comport.Parity = Parity.None;
comport.PortName = "COM1";
delStart = 0;
delLength = 9;
comport.RtsEnable = true;
comport.DtrEnable = true;
comport.Encoding = System.Text.Encoding.GetEncoding(28591);
}
How do I determine exactly which encoding will be applied? Any idea what I'm missing here?
byte[]
and examine that. Post it here if you can't solve it. – Henk Holterman Jan 10 '13 at 8:42