シリアルポートを使用してコンピュータに接続された体重計があります。これは非常に古いマシンであり、重量を軽減してデータベースに保存しようとしています。
マシンから返された重量には のような無効な文字?
が含まれており、重量が と表示され??2?0
ているはず02220
です。
Web検索の結果が示唆するように、エンコードと関係があることを理解しています。しかし、何が欠けているのか正確にはわかりません。
これが私のコードです:
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);
}
どのエンコーディングが適用されるかを正確に判断するにはどうすればよいですか? ここで何が欠けているか分かりますか?