public SerialWorker(string serialPort, ParseIncomingMessage parseMessage) { this._parseMessage = parseMessage; this._port = new SerialPort(serialPort, 9600, Parity.None, 8, StopBits.One); }
public SerialWorker(string serialPort, ParseIncomingMessage parseMessage, char messageStartBit, char messageEndBit) : this(serialPort, parseMessage) { this._terminators = new Tuple<char, char>(messageStartBit, messageEndBit); }
public SerialWorker(string serialPort, ParseIncomingMessage parseMessage, char messageStartBit, char messageEndBit) : this(serialPort, parseMessage) { this._terminators = new Tuple <char, char>(messageStartBit, messageEndBit); }
static void Main(string[] args) { SerialWorker serialDevice = null; LyncClientWorker lyncHandler = null; bool isFromDevice = false; // this tells the handler that the trigger made from device will not trigger another updateAvailability // delegate when a message from the device arrives ParseIncomingMessage parseMessage = new ParseIncomingMessage(delegate(string message) { isFromDevice = true; switch (message) { case "FREE": Console.WriteLine("I am Free"); lyncHandler.UpdateLyncAvailability(LyncAvailabilityState.Free); break; case "BUSY": Console.WriteLine("I am Busy"); lyncHandler.UpdateLyncAvailability(LyncAvailabilityState.Busy); break; case "AWAY": Console.WriteLine("I am Away"); lyncHandler.UpdateLyncAvailability(LyncAvailabilityState.Away); break; case "DND": Console.WriteLine("DND"); lyncHandler.UpdateLyncAvailability(LyncAvailabilityState.DND); break; } }); SetDeviceAvailability updateAvailability = new SetDeviceAvailability(delegate(LyncAvailabilityState state) { if (!isFromDevice) { // process the callback here if (serialDevice != null) { switch (state) { case LyncAvailabilityState.Free: serialDevice.SendMessage("FREE"); break; case LyncAvailabilityState.Away: serialDevice.SendMessage("AWAY"); break; case LyncAvailabilityState.Busy: serialDevice.SendMessage("BUSY"); break; case LyncAvailabilityState.DND: serialDevice.SendMessage("DND"); break; case LyncAvailabilityState.Offline: serialDevice.SendMessage("OFF"); break; default: break; } } } else { isFromDevice = false; } }); // create the SerialWorker along with the delegate and message terminators serialDevice = new SerialWorker("COM8", parseMessage, '[', ']'); // trigger the listener, this starts the process serialDevice.ListenPort(); // --> this has a thread in it, and this app will run until thread is destroyed // create the LyncClient along with the callback lyncHandler = new LyncClientWorker(updateAvailability); }