public ComPortController(string key, IComPorts ComDevice, uint comPortNum, ComPort.ComPortSpec spec) : base(key) { Port = ComDevice.ComPorts[comPortNum]; Spec = spec; Debug.Console(2, "Creating com port '{0}'", key); Debug.Console(2, "Com port spec:\r{0}", JsonConvert.SerializeObject(spec)); }
/// <summary> /// Creates a ComPort if the parameters are correct. Returns and logs errors if not /// </summary> public static ComPortController GetComPortController(string key, IComPorts comDevice, uint comPortNum, ComPort.ComPortSpec spec) { Debug.Console(1, "Creating com port '{0}'", key); if (comDevice == null) { throw new ArgumentNullException("comDevice"); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (comPortNum > comDevice.NumberOfComPorts) { Debug.Console(0, "[{0}] Com port {1} out of range on {2}", key, comPortNum, comDevice.GetType().Name); return(null); } var port = new ComPortController(key, comDevice, comPortNum, spec); return(port); }