void ControlSystem_SerialDataReceived(ComPort ReceivingComPort, ComPortSerialDataEventArgs args) { if (ReceivingComPort == myComPorts[2]) { rxQueue.Enqueue(args.SerialData); // Put all incoming data on the queue } }
void ControlSystem_SerialDataReceived(ComPort ReceivingComPort, ComPortSerialDataEventArgs args) { if (ReceivingComPort == ComPorts[2]) { rxQueue.Enqueue(args.SerialData); } }
public VividTouchComPortHandler(ComPort comPort) { _comPort = comPort; if (_comPort.Registered) { return; } _comPort.Register(); _comPort.SetComPortSpec(ComPort.eComBaudRates.ComspecBaudRate115200, ComPort.eComDataBits.ComspecDataBits8, ComPort.eComParityType.ComspecParityNone, ComPort.eComStopBits.ComspecStopBits1, ComPort.eComProtocolType.ComspecProtocolRS232, ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone, ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone, false); _comPort.SerialDataReceived += ComPortOnSerialDataReceived; CrestronEnvironment.ProgramStatusEventHandler += type => { if (type != eProgramStatusEventType.Stopping) { return; } _programStopping = true; _rxQueue.Enqueue(0x00); }; }
internal void QueueRequest(ServerRequest request) { RequestQueue.Enqueue(request); if (_dispatchThread != null && _dispatchThread.ThreadState == Thread.eThreadStates.ThreadRunning) { return; } _dispatchThread = new Thread(specific => { #if true Debug.WriteSuccess("AvediaServer", "Launching {0}.DispacthThread, Request Count = {1}", GetType().Name, RequestQueue.Count); Debug.WriteInfo("AvediaServer", "HttpClient Timeout = {0}, TimeoutEnabled = {1}", HttpClient.Timeout, HttpClient.TimeoutEnabled); #endif while (true) { var r = RequestQueue.Dequeue(); if (request == null) { CloudLog.Info("Exiting {0}", Thread.CurrentThread.Name); return(null); } #if true CrestronConsole.PrintLine("{0} {1}", r.RequestType.ToString(), r.Url); if (r.RequestType == RequestType.Post) { CrestronConsole.PrintLine(r.ContentString); } #endif try { var response = HttpClient.Dispatch(r); try { r.Callback(response, HTTP_CALLBACK_ERROR.COMPLETED); } catch (Exception e) { CloudLog.Exception(e); } } catch { r.Callback(null, HTTP_CALLBACK_ERROR.UNKNOWN_ERROR); } CrestronEnvironment.AllowOtherAppsToRun(); } }, null) { Name = "Avedia HTTP dispatch process" }; }
private void PortOnSerialDataReceived(IComPortDevice device, ComPortSerialDataEventArgs args) { var bytes = Encoding.ASCII.GetBytes(args.SerialData); #if DEBUG //Debug.WriteSuccess("Codec Rx Enqueue", Tools.GetBytesAsReadableString(bytes, 0, bytes.Length, true)); #endif _rxQueue.Enqueue(bytes); }
/// <summary> /// Adds a command from a child module to the queue /// </summary> /// <param name="commandToEnqueue">Command object from child module</param> public void EnqueueCommand(QueuedCommand commandToEnqueue) { _commandQueue.Enqueue(commandToEnqueue); Debug.Console(1, this, "Command (QueuedCommand) Enqueued '{0}'. CommandQueue has '{1}' Elements.", commandToEnqueue.Command, _commandQueue.Count); if (!_commandQueueInProgress) { SendNextQueuedCommand(); } }
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType) { switch (programEventType) { case eProgramStatusEventType.Stopping: RxQueue.Enqueue(null); break; default: break; } }
/// <summary> /// Adds (or returns) an object to the pool. /// </summary> /// <param name="obj"></param> public void AddToPool(T obj) { if (Interlocked.Increment(ref _currentCount) > MaxCapacity) { _queueReturnEvent.Wait(); } if (_disposed) { return; } _objectPool.Enqueue(obj); _queueAddEvent.Set(); }
public void Send(string line) { if (Connected) { #if DEBUG Debug.WriteWarn("Tesira Enqueued Message", line); #endif _sendQueue.Enqueue(line); } else { CloudLog.Warn("Could not send \"{0}\" to Tesira. No Connection", line); } }
public void Send(int id, MessageType messageType, byte[] bytes) { var message = new byte[bytes.Length + 5]; message[0] = 0x07; message[1] = (byte)id; message[2] = (byte)messageType; Array.Copy(bytes, 0, message, 3, bytes.Length); message[bytes.Length + 3] = 0x08; message[bytes.Length + 4] = 0x0d; #if DEBUG //CrestronConsole.Print("VT Board Tx: "); //Tools.PrintBytes(message, 0, message.Length, true); #endif _txQueue.Enqueue(message); if (_txThread == null || _txThread.ThreadState != Thread.eThreadStates.ThreadRunning) { _txThread = new Thread(specific => { while (!_txQueue.IsEmpty) { var m = _txQueue.Dequeue(); Send(m, 0, m.Length); Thread.Sleep(200); } return(null); }, null) { Name = string.Format("AvocorSocket Tx Handler"), Priority = Thread.eThreadPriority.MediumPriority }; } }
private void SendCmd(string data) { bool restartTimer = false; if (_PollTimer != null) { if (!_PollTimer.Disposed) { try { _PollTimer.Stop(); restartTimer = true; } catch { } } } byte[] data_arr = Encoding.ASCII.GetBytes(data); int data_len = Encoding.ASCII.GetByteCount(data); _Socket.SendData(data_arr, data_len); _SentMessages.Enqueue(data); if (restartTimer) { _PollTimer.Reset(30000); } }
private void ComPortOnSerialDataReceived(IComPortDevice receivingComPort, ComPortSerialDataEventArgs args) { var bytes = args.SerialData.ToByteArray(); #if DEBUG //Debug.WriteWarn("Lg Serial Rx"); //Tools.PrintBytes(bytes, 0, bytes.Length, true); #endif foreach (var b in bytes) { _rxQueue.Enqueue(b); } #if DEBUG //Debug.WriteWarn("Bytes in queue", _rxQueue.Count.ToString()); #endif if (_rxThread != null && _rxThread.ThreadState == Thread.eThreadStates.ThreadRunning) { return; } _rxThread = new Thread(ReceiveBufferProcess, null) { Priority = Thread.eThreadPriority.UberPriority, Name = string.Format("LG Display ComPort - Rx Handler") }; }
/// <summary> /// CCDDisplay Plugin device constructor for ISerialComport transport /// </summary> /// <param name="key"></param> /// <param name="name"></param> /// <param name="config"></param> /// <param name="display">Loaded and initialized instance of CCD Display driver instance</param> public ClearOneDSPDevice(string key, string name, ClearOneDSPConfig config, IBasicCommunication comm) : base(key, name) { Debug.Console(0, this, "Constructing new {0} instance", name); _config = config; _commandQueue = new CrestronQueue(100); _responseQueue = new CrestronQueue <string>(); _responseParseThread = new Thread(parseResponse, null, Thread.eThreadStartOptions.Running); _commandInProgressTimer = new CTimer((o) => { _commandInProgress = null; }, Timeout.Infinite); _devices = new Dictionary <string, ClearOneDSPDeviceInfo>(); Communication = comm; _portGather = new CommunicationGather(Communication, "\x0D\x0A"); _portGather.LineReceived += this.lineReceived; if (config.CommunicationMonitorProperties != null) { CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, config.CommunicationMonitorProperties); } else { //#warning Need to deal with this poll string CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 30000, 30000, 60000, new Action(() => { if (_devices.Count == 0) { _commandQueue.Enqueue("** VER"); } //sendLine("** VER"); foreach (var controlPoint in LevelControlPoints.Values) { controlPoint.Poll(); } })); } LevelControlPoints = new Dictionary <string, ClearOneDSPVolumeControl>(); foreach (KeyValuePair <string, ClearOneLevelControlBlockConfig> kvp in _config.LevelControlBlocks) { this.LevelControlPoints.Add(kvp.Key, new ClearOneDSPVolumeControl(kvp.Key, kvp.Value, this)); } CrestronConsole.AddNewConsoleCommand((s) => { StringBuilder sb = new StringBuilder(); sb.AppendLine("Devices:"); foreach (var kvp in _devices) { sb.AppendFormat("\tDevice: {0}\r\n", kvp.Key); sb.AppendFormat("\t\tModel: {0}\r\n", kvp.Value.DeviceType.ToString()); sb.AppendFormat("\t\tId: {0}\r\n", kvp.Value.DeviceId); sb.AppendFormat("\t\tFirmware: {0}\r\n", kvp.Value.Version); } CrestronConsole.ConsoleCommandResponse("{0}", sb.ToString()); }, Key + "INFO", "Print Driver Info", ConsoleAccessLevelEnum.AccessOperator); }
/// <summary> /// Recieve response message from DSP and queue for processing /// </summary> /// <param name="dev"></param> /// <param name="args"></param> private void lineReceived(object dev, GenericCommMethodReceiveTextArgs args) { Debug.Console(1, this, "RX: '{0}'", args.Text); try { if (String.IsNullOrEmpty(args.Text) || (args.Text == @"> ") || (args.Text == @"OK> ")) { //skip empty messages } else if (args.Text.IndexOf("ERROR", StringComparison.Ordinal) > -1) { // Error response Debug.Console(0, this, "Error From DSP: '{0}'", args.Text); } else { _responseQueue.Enqueue(args.Text); } } catch (Exception e) { if (Debug.Level == 2) { Debug.Console(2, this, "Error parsing response: '{0}'\n{1}", args.Text, e); } } }
public SamsungDisplayComPortHandler(IComPortDevice comPort) { _comPort = comPort; _rxQueue = new CrestronQueue <byte>(1000); CrestronEnvironment.ProgramStatusEventHandler += type => { if (type == eProgramStatusEventType.Stopping) { _programStopping = true; if (_txThread != null && _txThread.ThreadState == Thread.eThreadStates.ThreadRunning) { _txQueue.Enqueue(null); } if (_rxThread != null && _rxThread.ThreadState == Thread.eThreadStates.ThreadRunning) { _rxQueue.Enqueue(0x00); } } }; _txQueue = new CrestronQueue <byte[]>(50); }
public void Send(string str) { var bytes = new byte[str.Length + 1]; for (int i = 0; i < str.Length; i++) { bytes[i] = unchecked ((byte)str[i]); } bytes[str.Length] = 0x0a; _txQueue.Enqueue(bytes); if (_txThread == null || _txThread.ThreadState != Thread.eThreadStates.ThreadRunning) { _txThread = new Thread(specific => { Thread.CurrentThread.Name = string.Format("{0} Tx Handler", GetType().Name); while (_programRunning) { var qBytes = _txQueue.Dequeue(); if (qBytes != null) { #if DEBUG CrestronConsole.Print("QSys Tx: "); Tools.PrintBytes(qBytes, qBytes.Length, true); #endif ComPort.Send(qBytes, qBytes.Length); } } return(null); }, null); } }
public void Initialize() { if (_initialized) { return; } var port = _comPort as PortDevice; if (port != null && !port.Registered) { var result = port.Register(); if (result != eDeviceRegistrationUnRegistrationResponse.Success) { CloudLog.Error("Could not register {0} with ID {1}, {2}", port.GetType().Name, port.ID, result); } } var spec = new ComPort.ComPortSpec() { BaudRate = ComPort.eComBaudRates.ComspecBaudRate9600, DataBits = ComPort.eComDataBits.ComspecDataBits8, Parity = ComPort.eComParityType.ComspecParityNone, StopBits = ComPort.eComStopBits.ComspecStopBits1, Protocol = ComPort.eComProtocolType.ComspecProtocolRS232, HardwareHandShake = ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone, SoftwareHandshake = ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone, ReportCTSChanges = false }; _comPort.SetComPortSpec(spec); _comPort.SerialDataReceived += (device, args) => { var bytes = args.SerialData.ToByteArray(); #if DEBUG Debug.WriteSuccess("Samsung Rx", Debug.AnsiBlue + Tools.GetBytesAsReadableString(bytes, 0, bytes.Length, false) + Debug.AnsiReset); #endif foreach (var b in bytes) { _rxQueue.Enqueue(b); } if (_rxThread != null && _rxThread.ThreadState == Thread.eThreadStates.ThreadRunning) { return; } _rxThread = new Thread(ReceiveBufferProcess, null, Thread.eThreadStartOptions.CreateSuspended) { Priority = Thread.eThreadPriority.UberPriority, Name = string.Format("Samsung Display ComPort - Rx Handler") }; _rxThread.Start(); }; _initialized = true; }
/// <summary> /// Parse response from Q-Sys Core. /// </summary> /// <param name="data"></param> public static void ParseResponse(string data) { try { responseQueue.Enqueue(data); } catch (Exception e) { } }
public void Disconnect() { shouldReconnect = false; if (this.Connected) { #if DEBUG CrestronConsole.PrintLine("{0}.Disconnect(), rxQueue.Count = {1}, rxHandler.ThreadState = {2}", this.GetType().Name, rxQueue.Count, rxHandler.ThreadState); #endif Socket.DisconnectFromServer(); if (rxQueue.Count == 0 && rxHandler.ThreadState == Thread.eThreadStates.ThreadRunning) { rxQueue.Enqueue(0x00); } } }
public void EnqueueCommand(EtcCommand CommandToQueue) { CommandQueue.Enqueue(CommandToQueue); if (!CommandQueueInProgress) { SendNextQueuedCommand(); } }
private void ParseResponse(string data) { try { SendDebug(string.Format("Elk - Received and adding to queue: {0}", data)); responseQueue.Enqueue(data); } catch (Exception e) { ErrorLog.Error("ElkPanel {0} - Parse error: {1}", panelId, e.Message); } }
private void SendData(string msg) { if (txMsgs.IsFull) { CrestronConsole.PrintLine("can't enqueue tx - queue full"); } else { txMsgs.Enqueue(msg); } CheckThreadState(ref _tSendData, ref _tSendDataIL, tSendData, "tSendData"); }
public new void Send(string data) { _sendQueue.Enqueue(data); if (_sendThread == null || _sendThread.ThreadState != Thread.eThreadStates.ThreadRunning) { _sendThread = new Thread(SendProcess, null) { Priority = Thread.eThreadPriority.HighPriority }; } }
private void CoreModuleInit() { //Send login if needed if (this.loginUser.Length > 0 && this.loginPass.Length > 0) { this.SendLogin(); } this.heartbeatTimer = new CTimer(SendHeartbeat, null, 0, 15000); this.SendDebug("Initialized"); this.isInitialized = true; foreach (var item in this.SimplClients) { item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.IsRegistered, (SimplSharpString)"true", 1)); item.Value.Fire(new SimplEventArgs(eQscSimplEventIds.IsConnected, (SimplSharpString)"true", 1)); } this.SendDebug("Requesting all named components and controls"); this.commandQueue.Enqueue(JsonConvert.SerializeObject(new GetComponents())); if (Controls.Count() > 0) { AddControlToChangeGroup addControls; addControls = new AddControlToChangeGroup(); addControls.method = "ChangeGroup.AddControl"; addControls.ControlParams = new AddControlToChangeGroupParams(); addControls.ControlParams.Controls = new List <string>(); foreach (var item in Controls) { addControls.ControlParams.Controls.Add(item.Key); this.SendDebug(string.Format("Adding named control: {0} to change group", item.Key)); } this.commandQueue.Enqueue(JsonConvert.SerializeObject(addControls)); } if (Components.Count() > 0) { AddComponentToChangeGroup addComponents; foreach (var item in Components) { addComponents = new AddComponentToChangeGroup(); addComponents.method = "ChangeGroup.AddComponentControl"; addComponents.ComponentParams = new AddComponentToChangeGroupParams(); addComponents.ComponentParams.Component = item.Key; this.SendDebug(string.Format("Adding named component: {0} to change group", item.Key)); commandQueue.Enqueue(JsonConvert.SerializeObject(addComponents)); } } }
public SmartBoardComPortHandler(IComPortDevice comPort) { CrestronEnvironment.ProgramStatusEventHandler += type => { _programStopping = type == eProgramStatusEventType.Stopping; if (_rxThread != null && _rxThread.ThreadState == Thread.eThreadStates.ThreadRunning) { _rxQueue.Enqueue(0x00); } }; _comPort = comPort; var port = _comPort as CrestronDevice; if (port != null && !port.Registered) { var result = port.Register(); if (result != eDeviceRegistrationUnRegistrationResponse.Success) { CloudLog.Error("Could not register {0}, {1}", port, result); } } _comPort.SetComPortSpec(new ComPort.ComPortSpec() { BaudRate = ComPort.eComBaudRates.ComspecBaudRate19200, DataBits = ComPort.eComDataBits.ComspecDataBits8, StopBits = ComPort.eComStopBits.ComspecStopBits1, Parity = ComPort.eComParityType.ComspecParityNone, Protocol = ComPort.eComProtocolType.ComspecProtocolRS232, ReportCTSChanges = false, HardwareHandShake = ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone, SoftwareHandshake = ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone, }); _comPort.SerialDataReceived += PortOnSerialDataReceived; }
public ushort SendCommand(String Command) { try { SshCommand myCmd = myClient.RunCommand(Command); myQueue.Enqueue(myCmd.Execute()); return(1); } catch (Exception e) { ErrorLog.Error("Error Sending Command: {0}", e.Message); return(0); } }
public bool SendCommand(string cmd) { try { SshCommand tx = client.CreateCommand(cmd); cmdQueue.Enqueue(tx.Execute()); return(true); } catch (Exception e) { ErrorLog.Error("Failed to send command: {0} -- {1}", e.Message, e.StackTrace); } return(false); }
/// <summary> /// This event is triggered whenever a program event happens (such as stop, pause, resume, etc.) /// </summary> /// <param name="programEventType">These event arguments hold all the data to properly parse the event</param> void ControlSystem_ControllerProgramEventHandler(eProgramStatusEventType programStatusEventType) { switch (programStatusEventType) { case (eProgramStatusEventType.Paused): //The program has been paused. Pause all user threads/timers as needed. break; case (eProgramStatusEventType.Resumed): //The program has been resumed. Resume all the user threads/timers as needed. break; case (eProgramStatusEventType.Stopping): //The program has been stopped. //Close all threads. //Shutdown all Client/Servers in the system. //General cleanup. //Unsubscribe to all System Monitor events RxQueue.Enqueue(null); // The RxThread will terminate when it receives a null break; } }
public ushort SendCommand(String strCommand) { try { SshCommand myCmd = myClient.RunCommand(strCommand); myQueue.Enqueue(myCmd.Execute()); return(1); } catch (Exception ex) { ErrorLog.Error(String.Format("Error Sending Command: {0} -- {1}", strCommand, ex.Message)); return(0); } }
public void DataReceived(string data) { try { _receivedData.Enqueue(data); } catch (Exception e) { if (_debug) { ErrorLog.Exception("Exception occured in WattstopperDLM.Processor.DataReceived", e); } } }