c#中怎么用textbox控件接收com口读取到的数据 求详细代码,谢谢了!
2个回答
展开全部
原来使用的代码,你看能不能用。
private void 启动串口()
{
// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
// Allow the user to set the appropriate properties.
_serialPort.PortName = "COM1";
_serialPort.BaudRate = 9600;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.StopBits = StopBits.One;
_serialPort.Handshake = Handshake.None;
// Set the read/write timeouts
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;
_serialPort.Open();
_continue = true;
readThread = new Thread(Read);
readThread.Start();
}
public void Read()
{
while (_continue)
{
try
{
string s = _serialPort.ReadLine();
SynchronizationContext.Post(delegate
{
处理条码(s);
}, null);
}
catch{ }
}
}
private void 停止串口()
{
_continue = false;
if (readThread!= null)
{
readThread.Join();
}
_serialPort.Close();
}
private void 启动串口()
{
// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
// Allow the user to set the appropriate properties.
_serialPort.PortName = "COM1";
_serialPort.BaudRate = 9600;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.StopBits = StopBits.One;
_serialPort.Handshake = Handshake.None;
// Set the read/write timeouts
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;
_serialPort.Open();
_continue = true;
readThread = new Thread(Read);
readThread.Start();
}
public void Read()
{
while (_continue)
{
try
{
string s = _serialPort.ReadLine();
SynchronizationContext.Post(delegate
{
处理条码(s);
}, null);
}
catch{ }
}
}
private void 停止串口()
{
_continue = false;
if (readThread!= null)
{
readThread.Join();
}
_serialPort.Close();
}
2013-03-29
展开全部
好几个类了,你可以在网上找着源码,应该挺多的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询