大家救命啊,我的程序在使用扫描枪读取读取qr条码时总出现乱码
代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace RSR232
{
public partial class Form1 : Form
{
private delegate void SetlabelCallback(string text);
private string str = ""; public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
this.label1.AutoSize = true;
this.label1.AutoEllipsis = true;
}
private void SetLabel(string text)
{
if (label1.InvokeRequired)
{
SetlabelCallback d = new SetlabelCallback(SetLabel);
this.Invoke(d, new object[] { text });
}
else
{
label1.Text = text;
richTextBox1.Text = label1.Text;
}
} private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
str += this.serialPort1.ReadExisting();
SetLabel(str);
}
catch
{
MessageBox.Show("请选择你的com端口!");
}
} private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//MessageBox.Show(comboBox1.Text);
this.serialPort1.Close();
this.serialPort1.PortName = comboBox1.Text;
this.serialPort1.RtsEnable = true;
try
{
this.serialPort1.Open();
}
catch
{
MessageBox.Show("您选择的com口不存在!");
}
this.serialPort1.Encoding = Encoding.Default;
} }
}
代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace RSR232
{
public partial class Form1 : Form
{
private delegate void SetlabelCallback(string text);
private string str = ""; public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
this.label1.AutoSize = true;
this.label1.AutoEllipsis = true;
}
private void SetLabel(string text)
{
if (label1.InvokeRequired)
{
SetlabelCallback d = new SetlabelCallback(SetLabel);
this.Invoke(d, new object[] { text });
}
else
{
label1.Text = text;
richTextBox1.Text = label1.Text;
}
} private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
str += this.serialPort1.ReadExisting();
SetLabel(str);
}
catch
{
MessageBox.Show("请选择你的com端口!");
}
} private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//MessageBox.Show(comboBox1.Text);
this.serialPort1.Close();
this.serialPort1.PortName = comboBox1.Text;
this.serialPort1.RtsEnable = true;
try
{
this.serialPort1.Open();
}
catch
{
MessageBox.Show("您选择的com口不存在!");
}
this.serialPort1.Encoding = Encoding.Default;
} }
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货