我想从 USB 扫描仪读取条形码。
我收到类似 héà&"à')&'_h
或qà&é"'(èq
使用 SerialPort 连接时的代码。
有没有办法解码这个值?
private void Form1_Load(Object sender, EventArgs e)
{
_serialPort = new SerialPort("COM1", 19200, Parity.None, 8, StopBits.One);
_serialPort.Handshake = Handshake.None;
_serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;
_serialPort.Open();
}
/*
*/
private void btnStart_Click(Object sender, EventArgs e)
{
try
{
if (!_serialPort.IsOpen)
_serialPort.Open();
_serialPort.Write("SI\r\n");
}
catch (Exception ex)
{
MessageBox.Show("Error opening/writing to serial port :: " + ex.Message, "Error!");
}
}
void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Thread.Sleep(500);
String data = _serialPort.ReadLine();
this.BeginInvoke(new SetTextDeleg(si_DataReceived), new Object[] { data });
}
private void si_DataReceived(String data)
{
textBox1.Text = data.Trim().ToString();
}
谢谢