private void ReportKeyActivityEventHandler(LCDPacket packet) { if (1 != packet.DataLength) { return; } switch (packet.Data[0]) { case 1: Key = LCDKey.Up; break; case 2: Key = LCDKey.Down; break; case 3: Key = LCDKey.Left; break; case 4: Key = LCDKey.Right; break; case 5: Key = LCDKey.Enter; break; case 6: Key = LCDKey.Exit; break; case 7: case 8: case 9: case 10: case 11: case 12: break; default: throw new ArgumentException("Invalid packet data"); } }
//---------------------------------------------------------------------------------------// private void ReportThread() { const String methodName = "ReportThread"; Logfile.WriteCalled(logLevel, STR_ClassName, methodName); try { this.reportRunning = true; while (this.reportRunning == true) { lock (this.reportSignal) { if (Monitor.Wait(this.reportSignal, 1000) == false) { /* * Signal not received before timout */ continue; } Trace.WriteLine(String.Format("{0:s}: ReportQueue.Count={1:d}", methodName, reportQueue.Count)); } /* * Get packets from the queue and process */ while (reportQueue.Count > 0) { LCDPacket packet = reportQueue.Dequeue(); switch (packet.Type) { case PKTRPT_CAPTURE_DATA: int value = packet.Data[1]; value = (value << 8) + packet.Data[0]; this.captureCount = value; this.captureCompleted = true; Trace.WriteLine(String.Format("CaptureData={0:d}", value)); break; case PKTRPT_KEY_ACTIVITY: if (packet.DataLength == 1) { switch (packet.Data[0]) { case 5: this.lcdKey = LCDKey.Enter; break; case 6: this.lcdKey = LCDKey.Exit; break; } } break; case PKTRPT_TEMP_SENSOR: break; } } } } catch (Exception ex) { Logfile.WriteError(ex.Message); } Logfile.WriteCompleted(logLevel, STR_ClassName, methodName); }
//---------------------------------------------------------------------------------------// private void ReportHandler() { const string STRLOG_MethodName = "ReportHandler"; Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName); try { this.reportRunning = true; while (this.reportRunning == true) { lock (this.reportSignal) { if (Monitor.Wait(this.reportSignal, 1000) == false) { // Signal not received before timout continue; } Trace.WriteLine("ReportHandler: reportSignal received - reportQueue.Count=" + reportQueue.Count.ToString()); } // // Get packets from the queue and process // while (reportQueue.Count > 0) { LCDPacket packet = reportQueue.Dequeue(); switch (packet.Type) { case PKTRPT_CAPTURE_DATA: int value = packet.Data[1]; value = (value << 8) + packet.Data[0]; CaptureData = value; Trace.WriteLine("CaptureData=" + value.ToString()); break; case PKTRPT_KEY_ACTIVITY: if (packet.DataLength == 1) { switch (packet.Data[0]) { case 5: Key = LCDKey.Enter; break; case 6: Key = LCDKey.Exit; break; } } break; case PKTRPT_TEMP_SENSOR: break; } } } } catch (Exception ex) { Logfile.WriteError(ex.Message); } Trace.WriteLine(STRLOG_MethodName + ": Exiting"); Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName); }
//---------------------------------------------------------------------------------------// public SerialLcd(XmlNode xmlNodeEquipmentConfig) { const string STRLOG_MethodName = "SerialLcd"; Logfile.WriteCalled(null, STRLOG_MethodName); // // Initialise local variables // this.disposed = true; this.initialised = false; this.lastError = null; this.reportRunning = false; this.captureData = -1; this.lcdKey = LCDKey.None; // // Initialise properties // this.online = false; this.statusMessage = STRLOG_NotInitialised; // // Determine the logging level for this class // try { this.logLevel = (Logfile.LoggingLevels)Utilities.GetIntAppSetting(STRLOG_ClassName); } catch { this.logLevel = Logfile.LoggingLevels.Minimum; } Logfile.Write(Logfile.STRLOG_LogLevel + this.logLevel.ToString()); // // Get initialisation delay // XmlNode xmlNodeSerialLcd = XmlUtilities.GetXmlNode(xmlNodeEquipmentConfig, Consts.STRXML_serialLcd); try { this.initialiseDelay = XmlUtilities.GetIntValue(xmlNodeSerialLcd, Consts.STRXML_initialiseDelay); if (this.initialiseDelay < 0) { throw new ArgumentException(STRERR_NumberIsNegative); } } catch (ArgumentNullException) { throw new ArgumentException(STRERR_InitialiseDelayNotSpecified); } catch (FormatException) { // Value cannot be converted throw new ArgumentException(STRERR_NumberIsInvalid, Consts.STRXML_initialiseDelay); } catch (Exception ex) { Logfile.WriteError(ex.Message); throw new ArgumentException(ex.Message, Consts.STRXML_initialiseDelay); } // // Get WriteLine() time // try { this.writeLineTime = XmlUtilities.GetRealValue(xmlNodeSerialLcd, Consts.STRXML_writeLineTime, 0.0); } catch (Exception ex) { Logfile.WriteError(ex.Message); throw new ArgumentException(ex.Message, Consts.STRXML_writeLineTime); } // // Create the receive and report objects // this.receiveDataInfo = new ReceiveDataInfo(); this.reportQueue = new Queue <LCDPacket>(); this.reportSignal = new Object(); this.responseSignal = new Object(); Logfile.WriteCompleted(null, STRLOG_MethodName); }
//---------------------------------------------------------------------------------------// public SerialLcd(XmlNode xmlNodeEquipmentConfig) { const string STRLOG_MethodName = "SerialLcd"; Logfile.WriteCalled(null, STRLOG_MethodName); // // Initialise local variables // this.disposed = true; this.initialised = false; this.lastError = null; this.reportRunning = false; this.captureData = -1; this.lcdKey = LCDKey.None; // // Initialise properties // this.online = false; this.statusMessage = STRLOG_NotInitialised; // // Determine the logging level for this class // try { this.logLevel = (Logfile.LoggingLevels)Utilities.GetIntAppSetting(STRLOG_ClassName); } catch { this.logLevel = Logfile.LoggingLevels.Minimum; } Logfile.Write(Logfile.STRLOG_LogLevel + this.logLevel.ToString()); // // Get initialisation delay // XmlNode xmlNodeSerialLcd = XmlUtilities.GetXmlNode(xmlNodeEquipmentConfig, Consts.STRXML_serialLcd); try { this.initialiseDelay = XmlUtilities.GetIntValue(xmlNodeSerialLcd, Consts.STRXML_initialiseDelay); if (this.initialiseDelay < 0) { throw new ArgumentException(STRERR_NumberIsNegative); } } catch (ArgumentNullException) { throw new ArgumentException(STRERR_InitialiseDelayNotSpecified); } catch (FormatException) { // Value cannot be converted throw new ArgumentException(STRERR_NumberIsInvalid, Consts.STRXML_initialiseDelay); } catch (Exception ex) { Logfile.WriteError(ex.Message); throw new ArgumentException(ex.Message, Consts.STRXML_initialiseDelay); } // // Get WriteLine() time // try { this.writeLineTime = XmlUtilities.GetRealValue(xmlNodeSerialLcd, Consts.STRXML_writeLineTime, 0.0); } catch (Exception ex) { Logfile.WriteError(ex.Message); throw new ArgumentException(ex.Message, Consts.STRXML_writeLineTime); } // // Create the receive and report objects // this.receiveDataInfo = new ReceiveDataInfo(); this.reportQueue = new Queue<LCDPacket>(); this.reportSignal = new Object(); this.responseSignal = new Object(); Logfile.WriteCompleted(null, STRLOG_MethodName); }