/// <summary> /// Console handler that simulates com port data receive /// </summary> /// <param name="s"></param> public static void SimulateComReceiveOnDevice(string s) { // devcomsim:1 xyzabc var match = Regex.Match(s, @"(\S*)\s*(.*)"); if (match.Groups.Count < 3) { CrestronConsole.ConsoleCommandResponse(" Format: devsimreceive:P <device key> <string to send>"); return; } //Debug.Console(2, "**** {0} - {1} ****", match.Groups[1].Value, match.Groups[2].Value); ComPortController com = GetDeviceForKey(match.Groups[1].Value) as ComPortController; if (com == null) { CrestronConsole.ConsoleCommandResponse("'{0}' is not a comm port device", match.Groups[1].Value); return; } com.SimulateReceive(match.Groups[2].Value); }
/// <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); }
/// <summary> /// Returns a comm method of either com port, TCP, SSH, and puts this into the DeviceManager /// </summary> /// <param name="deviceConfig">The Device config object</param> public static IBasicCommunication CreateCommForDevice(DeviceConfig deviceConfig) { EssentialsControlPropertiesConfig controlConfig = GetControlPropertiesConfig(deviceConfig); if (controlConfig == null) { return(null); } IBasicCommunication comm = null; try { var c = controlConfig.TcpSshProperties; switch (controlConfig.Method) { case eControlMethod.Com: comm = new ComPortController(deviceConfig.Key + "-com", GetComPort(controlConfig), controlConfig.ComParams); break; case eControlMethod.Cec: comm = new CecPortController(deviceConfig.Key + "-cec", GetCecPort(controlConfig)); break; case eControlMethod.IR: break; case eControlMethod.Ssh: { var ssh = new GenericSshClient(deviceConfig.Key + "-ssh", c.Address, c.Port, c.Username, c.Password); ssh.AutoReconnect = c.AutoReconnect; if (ssh.AutoReconnect) { ssh.AutoReconnectIntervalMs = c.AutoReconnectIntervalMs; } comm = ssh; break; } case eControlMethod.Tcpip: { var tcp = new GenericTcpIpClient(deviceConfig.Key + "-tcp", c.Address, c.Port, c.BufferSize); tcp.AutoReconnect = c.AutoReconnect; if (tcp.AutoReconnect) { tcp.AutoReconnectIntervalMs = c.AutoReconnectIntervalMs; } comm = tcp; break; } case eControlMethod.Udp: { var udp = new GenericUdpServer(deviceConfig.Key + "-udp", c.Address, c.Port, c.BufferSize); comm = udp; break; } case eControlMethod.Telnet: break; default: break; } } catch (Exception e) { Debug.Console(0, "Cannot create communication from JSON:\r{0}\r\rException:\r{1}", deviceConfig.Properties.ToString(), e); } // put it in the device manager if it's the right flavor var comDev = comm as Device; if (comDev != null) { DeviceManager.AddDevice(comDev); } return(comm); }