コード例 #1
0
        public SerialPortObject(string portName, TYPE type) : base(portName)
        {
            try
            {
                this.Open();
            } catch (Exception ex) {
                Console.WriteLine("Error opening my port: {0}", ex.Message);
            }

            if (IsOpen)
            {
                _isEnabled = true;
                if (type.Equals(TYPE.LISTENER))
                {
                    this.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
                }
                else
                {
                    new Thread(DataSentThread).Start(cts.Token);
                }
            }
        }