0

私の手順: 1.using System.IO.Ports;using system.Threading;

2.SerialPort mySerialPort=new SerialPort("Com1",9200,Parity.None,8,StopBits.One); 3.mySerialPort.Open(); //例外がキャッチされました:System.IO.IOException がスローされました:そのようなファイルまたはディレクトリはありません。

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

6.ReadPortThread(SerialPort serialPort() //シリアルポートからデータを受信。

問題に何か提案をいただければ幸いです。

4

1 に答える 1

0

I'am also working on a serialPort communication, and mine works:

            ///<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);
            }         
于 2013-03-11T08:01:38.837 に答える