Beispiel #1
0
        /// <summary>
        /// Opens a Serial COM Port
        /// </summary>
        /// <param name="port">Port name. Use <see cref="GetAllPorts()"/> to get all ports</param>
        public static COMPort Open(string port)
        {
            var com = new COMPort();

            com._port = new SerialPort(port);
            if(com._port.IsOpen == false) //if not open, open the port
                com._port.Open();

            com._port.DataReceived += (sender, e) => OnDataReceived(com, com._port.ReadExisting());

            return com;
        }
Beispiel #2
0
 /// <summary>
 /// Event triggerer for data being recived by the COM port
 /// </summary>
 /// <param name="port">COM Port class</param>
 /// <param name="data">Data that was received</param>
 static void OnDataReceived(COMPort port, string data)
 {
     if(DataReceived != null)
         DataReceived(port, new COMEvent(data));
 }