// set any command to device public void SetValue(WriteCommands command, byte payload) { byte[] data = new byte[2]; data[0] = COMMUNICATION_WRITE; data[0] |= (byte)command; data[0] |= (1 << 5); data[1] = payload; dataToWrite.Enqueue(data); }
// set any command to device public void SetValue(WriteCommands command, UInt16 payload) { byte[] data = new byte[3]; data[0] = COMMUNICATION_WRITE; data[0] |= (byte)command; data[0] |= (2 << 5); data[1] = Convert.ToByte(payload & 0xFF); data[2] = Convert.ToByte((payload >> 8) & 0xFF); dataToWrite.Enqueue(data); }
public void Initialize() { MMWindow.Manager = this; ReadModels.Clear(); WriteModels.Clear(); ReadCommands.Clear(); WriteCommands.Clear(); _Add(LadderModels); if (MMWindow != null) { foreach (MonitorVariableTable mvtable in MMWindow.tables) { Initialize(mvtable); } } Arrange(); }
private void _Thread_Run() { _Thread_IsAlive = true; while (_Thread_Alive) { while (_Thread_Alive && _Thread_Active) { if (CurrentCommand == null) { if (WriteCommands.Count() > 0) { CurrentCommand = WriteCommands.Dequeue(); } else { if (ReadCommands.Count() == 0) { CurrentCommand = null; } else { if (ReadCommandIndex >= ReadCommands.Count()) { ReadCommandIndex = 0; } CurrentCommand = ReadCommands[ReadCommandIndex++]; } } } bool hassend = false; bool hasrecv = false; int sendtime = 0; int recvtime = 0; if (CurrentCommand != null) { while (_Thread_Alive && _Thread_Active && sendtime < 5) { if (Send(CurrentCommand)) { hassend = true; break; } sendtime++; } int itvtime = 20; if (CurrentCommand is GeneralWriteCommand || CurrentCommand is IntrasegmentWriteCommand) { itvtime = 100; } //_Thread_WaitForActive(itvtime); Thread.Sleep(itvtime); while (hassend) { try { if (Recv(CurrentCommand)) { hasrecv = true; break; } } catch (Exception e) { } recvtime++; } } if (_Thread_Alive && hassend && hasrecv) { Execute(CurrentCommand); CurrentCommand = null; } Thread.Sleep(10); } _Thread_WaitForActive(); } _Thread_IsAlive = false; }