【问题标题】:serialPort communicatin with thread ,in monodevelop IDE ,using C#serialPort 与线程通信,在 monodevelop IDE 中,使用 C#
【发布时间】:2013-02-26 03:04:17
【问题描述】:

我的步骤: 1.使用System.IO.Ports;使用system.Threading;

2.SerialPort mySerialPort=new SerialPort("Com1",9200,Parity.None,8,StopBits.One); 3.mySerialPort.Open(); //Exception Caught:System.IO.IOException has been throwed :has no such file or directory.

4.myThread=new Thread(new ParameterizedThreadStart(ReadPortThread)); 5.myThread.Start(mySerialPort);

6.ReadPortThread(SerialPort serialPort() //从串口接收数据。

希望您对问题提出一些建议。

【问题讨论】:

  • 也许 Com1 需要是 COM1

标签: c# thread-safety serial-port monodevelop


【解决方案1】:

我也在进行串行端口通信,我的工作:

            ///<summary>
            ///creating new serialPort, fill it with a portname and give it BaudRate value 9600.
            ///</summary>
            _serialPort = new SerialPort();
            _serialPort.PortName = portname;
            _serialPort.BaudRate = 9600;
            _serialPort.Parity = Parity.None;
            _serialPort.StopBits = StopBits.One;

            try
            {
                if (!_serialPort.IsOpen)
                {
                    //open the port.
                    _serialPort.Open();
                }
                //when the port is open
                if (_serialPort.IsOpen)
                {          
                    _serialUsbThread = new Thread(SerialWorker);
                    _serialUsbThread.Priority = ThreadPriority.Highest;
                    _serialUsbThread.Start();
                }   
            }
            catch (Exception ex)
            {
                Debug.WriteLine(DateTime.UtcNow + " SERIAL: " + ex.Message);
            }         

【讨论】:

  • 谢谢。你的代码对我很有帮助。因为我在 Ubuntu 系统中,这是一个 Linux 系统,我应该将端口名设置为“/dev/ttyS0”,而不是“COM1”。我使用这个序列号端口:“/dev/ttyS0”。
  • 然后选择它作为答案:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-28
  • 1970-01-01
  • 2011-09-01
  • 2012-01-20
  • 2014-01-07
  • 1970-01-01
相关资源
最近更新 更多