public bool SwitchDetector(DataModelLaserInnolas.InnolasChannelSwitch channelNumber, string calibrationFilePath) { try { _laserCalibrationFile = new LaserCalibrationTable(); string errorMessage; if (!_laserCalibrationFile.LoadFile(calibrationFilePath, out errorMessage)) { /**/ // HardwareMonitorReport((ulong)DeviceErrorCode.CalibrationFileError, new string[] { errorMessage }); GUI_Communicator.sendStatus("Laser", "HardwareMonitor", errorMessage); } else { if (_previousUndividedTriggerRate != 0) { if (_previousUndividedTriggerRate != _laserCalibrationFile.LaserUndividedTriggerRate) { /**/ // MSOTService.IMSOTLog.HandleError(EnumLogType.Warning, DisplayName, /**/ // "Laser Calibration file defines a different undivided trigger rate than the previous file, new: " + _laserCalibrationFile.LaserUndividedTriggerRate + /**/ // " old: "+_previousUndividedTriggerRate); GUI_Communicator.sendError("Laser", "ErrorDisplay", "Laser Calibration file defines a different undivided trigger rate than the previous file, new: " + _laserCalibrationFile.LaserUndividedTriggerRate + " old: " + _previousUndividedTriggerRate); } } _previousUndividedTriggerRate = _laserCalibrationFile.LaserUndividedTriggerRate; /**/ // MSOTService.IMSOTLog.HandleError(EnumLogType.Info, DisplayName, "Laser Calibration file info: " + _laserCalibrationFile.Description); GUI_Communicator.sendStatus("Laser", "ErrorDisplay", "Laser Calibration file info: " + _laserCalibrationFile.Description); string laserFileSummary; AvailableTriggerRates = new ObservableCollection <double>(_laserCalibrationFile.GetTriggerRates(out laserFileSummary)); switchChannel(channelNumber); /**/ // MSOTService.IMSOTLog.HandleError(EnumLogType.Info, DisplayName, laserFileSummary); GUI_Communicator.sendStatus("Laser", "ErrorDisplay", laserFileSummary); return(true); }
public async void Connect_(IPAddress proxyIP, int port) { int errorCode = 0; _msgCounter = 0; // message = ""; _exchangeCommandActive = false; GUI_Communicator.sendStatus("Laser", "HardwareMonitor", "Step 1"); try { _proxyIp = proxyIP; errorCode = 0; _innolasProxy = new System.Net.Sockets.TcpClient(); await _innolasProxy.ConnectAsync(_proxyIp, Convert.ToInt32(port)); if (_innolasProxy.Connected) { _innolasStream = _innolasProxy.GetStream(); System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(receiveThread)); } else { errorCode = -1; // message = "Unable to connect"; } } catch { errorCode = -2; // message = "Exception : " + ex.Message; } // return errorCode; }
protected void checkWavelengthRange() { /**/ string presetRange = LaserParameter.SystemMinAllowedWavelength.ToString("F1") + "nm-" + LaserParameter.SystemMaxAllowedWavelength.ToString("F1") + "nm"; string laserRange = LaserParameter.LaserMinAllowedWavelength.ToString("F1") + "nm-" + LaserParameter.LaserMaxAllowedWavelength.ToString("F1") + "nm"; string diagnosticMessage = "System allowed wavelength range (" + presetRange + "). Laser capabilities (" + laserRange + ")"; //if (laserTrace.TraceVerbose) /**/ // Xvue.MSOT.ViewModels.Log.ViewModelLog.MsotTrace(diagnosticMessage, laserTrace); GUI_Communicator.sendStatus("Laser", "DiagnosticDisplay", diagnosticMessage); //if ((MSOTService.LaserMinAllowedWavelength < MinWaveLength) || // (MSOTService.LaserMaxAllowedWavelength > MaxWaveLength)) //{ // MSOTService.NotifyUserOnAction("Preset wavelength range (" + presetRange + ") exceeds laser capabilities (" + laserRange + ").\n Presets may cause errors.", DisplayName, false, true); //} //else //{ // MSOTService.IMSOTLog.HandleError(Services.Log.EnumLogType.Info,DisplayName,"Preset wavelength range (" + presetRange + "). Laser capabilities (" + laserRange + ")"); //} }
public int Connect(IPAddress proxyIP, int port) { int errorCode = 0; _msgCounter = 0; //message = ""; _exchangeCommandActive = false; GUI_Communicator.sendStatus("Laser", "HardwareMonitor", "Connecting - Step 1"); try { //IPAddress _proxyIP = IPAddress.Parse(proxyIP); GUI_Communicator.sendStatus("Laser", "HardwareMonitor", "Connecting - Step 2"); errorCode = 0; _innolasProxy = new System.Net.Sockets.TcpClient(); GUI_Communicator.sendStatus("Laser", "HardwareMonitor", "Connecting - Step 3"); _innolasProxy.Connect(proxyIP, Convert.ToInt32(port)); GUI_Communicator.sendStatus("Laser", "HardwareMonitor", "Connecting - Step 4"); if (_innolasProxy.Connected) { _innolasStream = _innolasProxy.GetStream(); System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(receiveThread)); GUI_Communicator.sendStatus("Laser", "HardwareMonitor", "Could Connect"); } else { errorCode = -1; GUI_Communicator.sendStatus("Laser", "HardwareMonitor", "Unable to Connect"); //message = "Unable to connect"; } } catch (Exception ex) { errorCode = -2; GUI_Communicator.sendStatus("Laser", "HardwareMonitor", "Connecting Error:" + ex.Message); //message = "Exception : " + ; } return(errorCode); }
/* * private void handleLaserStatusMessage_(string sender, string receiver, string message) * { * System.Windows.Application.Current.Dispatcher.Invoke( * System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate * { * * if (receiver == "OpoDataHandler" && sender == "OPO") * { * actualShotCount++; * string[] stringSeparators = new string[] { "," }; * string[] values = message.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries); * int shotcounter = Convert.ToInt32(values[0]); * int position = Convert.ToInt32(values[1]); * double energy = Convert.ToDouble(values[2]); * DateTime timestamp = DateTime.Now; * myOpoData.Add(new OPOData() { Timestamp = timestamp, Shotcounter = shotcounter, Position = position, Energy = energy, Sweep=sweepCount, PulseDivider=pulseDividerCount }); * * if (position != last_position)// new wavelength * { * if(position!=0)// not for first shot * { * GUI_Communicator.sendStatus("OPO_DATA_HANDLER","COHERENT","NEW_WL_INDEX="+position); * actualShotCount = 0; * //last_position++; * } * else // if sweep starts from the beginning * { * sweepCount++; * GUI_Communicator.sendStatus("OPO_DATA_HANDLER", "COHERENT", "NEW_WL_INDEX=0"); * GUI_Communicator.sendStatus("OPO_DATA_HANDLER", "COHERENT", "NEW_SWEEP=" + sweepCount); * * } * } * * * last_position = position; * * * } * * //LogTextBox.Text += data.Timestamp + ": " + data.Energy + "\n"; * * }); * * } */ private void handleLaserStatusMessage(string sender, string receiver, string message) { if (receiver == "OpoDataHandler" && sender == "OPO") { DateTime stamp1 = DateTime.Now; actualShotCount++; string[] stringSeparators = new string[] { "," }; string[] values = message.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries); int shotcounter = Convert.ToInt32(values[0]); int position = Convert.ToInt32(values[1]); double energy = Convert.ToDouble(values[2]); DateTime timestamp = DateTime.Now; myOpoData.Add(new OPOData() { Timestamp = timestamp, Shotcounter = shotcounter, Position = position, Energy = energy, Sweep = sweepCount, PulseDivider = pulseDividerCount }); DateTime stamp2 = DateTime.Now; System.Diagnostics.Trace.WriteLine("handle OPO Data : " + ((TimeSpan)(stamp2 - stamp1)).Milliseconds); if (position != last_position) // new wavelength { if (position != 0) // not for first shot { GUI_Communicator.sendStatus("OPO_DATA_HANDLER", "COHERENT", "NEW_WL_INDEX=" + position + "," + shotcounter); actualShotCount = 0; //last_position++; } else // if sweep starts from the beginning position==0 { if (PockelsCellDelaysCount == 1) { sweepCount++; GUI_Communicator.sendStatus("OPO_DATA_HANDLER", "COHERENT", "NEW_SWEEP=" + sweepCount); } else // PockelsCellDelaysCount>1 { if (sweepCount < PockelsCellDelaysCount - 1) // in PockelsCellSchleife { sweepCount++; //GUI_Communicator.sendStatus("OPO_DATA_HANDLER", "COHERENT", "NEW_WL_INDEX=0"); GUI_Communicator.sendStatus("OPO_DATA_HANDLER", "COHERENT", "NEW_SWEEP=" + sweepCount); } else if (sweepCount >= PockelsCellDelaysCount - 1) //PockelsCellSchleife Durchlaufen => setzte neuen Pulse Divider { sweepCount = 0; pulseDividerCount++; //GUI_Communicator.sendStatus("OPO_DATA_HANDLER", "COHERENT", "NEW_WL_INDEX=0"); //GUI_Communicator.sendStatus("OPO_DATA_HANDLER", "COHERENT", "NEW_SWEEP=0"); GUI_Communicator.sendStatus("OPO_DATA_HANDLER", "COHERENT", "NEW_PULSE_DIVIDER=" + pulseDividerCount); } } } } last_position = position; } //LogTextBox.Text += data.Timestamp + ": " + data.Energy + "\n"; }
void receiveThread(object input) { byte[] inputArray = new byte[50]; List <String> newMessages; IncomingMessageType errorLevel; StringBuilder myCompleteMessage = new StringBuilder(_maxCommandLength, _maxCommandLength); while (_innolasProxy.Connected) { try { int readCount = -1; Array.Clear(inputArray, 0, inputArray.Length); if (!_innolasStream.CanRead) { break; } if ((readCount = _innolasStream.Read(inputArray, 0, inputArray.Length)) > 0) { newMessages = parseSubMessage(inputArray, readCount, ref myCompleteMessage); foreach (string msgItem in newMessages)//we have some complete commands { //if (msgItem.Contains("\r") || msgItem.Contains("\n")) // System.Diagnostics.Trace.WriteLine("Error deb1: " + msgItem); errorLevel = IncomingMessageType.Normal; _msgCounter++; string dbgMsg = "[" + _msgCounter.ToString() + "] " + msgItem; //System.Diagnostics.Debug.WriteLine("@:" + DateTime.Now.ToLongTimeString() + " Parsed command: " + dbgMsg); //------------------------------------------- // check here for any general response actions //------------------------------------------ lock (_incomingMessages) { if (_exchangeCommandActive) { _incomingMessages.Enqueue(msgItem); } } //trygetvalue returns 0 if not found which means no error... if (!_errorTable.TryGetValue(msgItem, out errorLevel)) { //no errors, check if LaserState string LaserStateReady = "LASER_STATE=READY"; if (msgItem.StartsWith(LaserStateReady)) { GUI_Communicator.sendStatus("LASER_STATE", "GUI", "LaserReady"); } string LaserStateOff = "LASER_STATE=OFF"; if (msgItem.StartsWith(LaserStateOff)) { GUI_Communicator.sendStatus("LASER_STATE", "GUI", "LaserOff"); } string LaserCharged = "LASER_STATE=CBANK.Wait"; if (msgItem.StartsWith(LaserCharged)) { GUI_Communicator.sendStatus("LASER_STATE", "GUI", "LaserCharged"); } string LaserNotCharged = "LASER_STATE=CBANK.Off"; if (msgItem.StartsWith(LaserNotCharged)) { GUI_Communicator.sendStatus("LASER_STATE", "GUI", "LaserConnectedNotCharged"); } string LaserStateWarmUp = "LASER_STATE=WARMUP"; if (msgItem.StartsWith(LaserStateWarmUp)) { GUI_Communicator.sendStatus("LASER_STATE", "GUI", "LaserWarmingUp"); } string LaserStateSwitchOff = "LASER_STATE=SWITCH_OFF"; if (msgItem.StartsWith(LaserStateSwitchOff)) { GUI_Communicator.sendStatus("LASER_STATE", "GUI", "LaserSwitchingOff"); } //no errors,check if it is A LaserParameter string FPGA = "FPGA_SW_VERSION="; if (msgItem.StartsWith(FPGA)) { string msgBody = msgItem.Replace(FPGA, ""); errorLevel = IncomingMessageType.OpoData; dbgMsg = msgBody; GUI_Communicator.sendStatus("FPGA_SW_VERSION", "VERSION_NUMBERS", dbgMsg); } string Controller = "CONTROLLER_SW_VERSION="; if (msgItem.StartsWith(Controller)) { string msgBody = msgItem.Replace(Controller, ""); errorLevel = IncomingMessageType.OpoData; dbgMsg = msgBody; GUI_Communicator.sendStatus("CONTROLLER_SW_VERSION", "VERSION_NUMBERS", dbgMsg); } string HW = "HW_VERSION="; if (msgItem.StartsWith(HW)) { string msgBody = msgItem.Replace(HW, ""); errorLevel = IncomingMessageType.OpoData; dbgMsg = msgBody; GUI_Communicator.sendStatus("HW_VERSION", "VERSION_NUMBERS", dbgMsg); } string GUI = "GUI_VERSION="; if (msgItem.StartsWith(HW)) { string msgBody = msgItem.Replace(GUI, ""); errorLevel = IncomingMessageType.OpoData; dbgMsg = msgBody; GUI_Communicator.sendStatus("GUI", "VERSION_NUMBERS", dbgMsg); } string Proxy = "PROXY_VERSION="; if (msgItem.StartsWith(HW)) { string msgBody = msgItem.Replace(Proxy, ""); errorLevel = IncomingMessageType.OpoData; dbgMsg = msgBody; GUI_Communicator.sendStatus("PROXY_VERSION", "VERSION_NUMBERS", dbgMsg); } string Opo = "OPO_VERSION="; if (msgItem.StartsWith(HW)) { string msgBody = msgItem.Replace(Opo, ""); errorLevel = IncomingMessageType.OpoData; dbgMsg = msgBody; GUI_Communicator.sendStatus("OPO_VERSION", "VERSION_NUMBERS", dbgMsg); } string EnergyMon = "ENERGY_MONITOR_VERSION="; if (msgItem.StartsWith(EnergyMon)) { string msgBody = msgItem.Replace(EnergyMon, ""); errorLevel = IncomingMessageType.OpoData; dbgMsg = msgBody; GUI_Communicator.sendStatus("ENERGY_MONITOR_VERSION", "VERSION_NUMBERS", dbgMsg); } //no errors, check if it is SweepState string sweepState = "SWEEP_STATE="; if (msgItem.StartsWith(sweepState)) { string opoBody = msgItem.Replace(sweepState, ""); errorLevel = IncomingMessageType.OpoData; dbgMsg = opoBody; GUI_Communicator.sendStatus("SWEEP_STATE", "GUI", dbgMsg); } //no errors, check if it is OPO3 string opoCommand = "OPO3_MEASURE="; if (msgItem.StartsWith(opoCommand)) { string opoBody = msgItem.Replace(opoCommand, ""); errorLevel = IncomingMessageType.OpoData; dbgMsg = opoBody; GUI_Communicator.sendStatus("OPO", "OpoDataHandler", dbgMsg); } else { opoCommand = "SHOT_COUNTER="; if (msgItem.StartsWith(opoCommand)) { string opoBody = msgItem.Replace(opoCommand, ""); errorLevel = IncomingMessageType.FlashLampShotCounter; dbgMsg = opoBody; } else { opoCommand = "SHOT_COUNTER_2="; if (msgItem.StartsWith(opoCommand)) { string opoBody = msgItem.Replace(opoCommand, ""); errorLevel = IncomingMessageType.PockelScellCounter; dbgMsg = opoBody; } else { opoCommand = "WATER_FLOW="; if (msgItem.StartsWith(opoCommand)) { string opoBody = msgItem.Replace(opoCommand, ""); errorLevel = IncomingMessageType.WaterFlow; dbgMsg = opoBody; } else { opoCommand = "TEMPERATURE="; if (msgItem.StartsWith(opoCommand)) { string opoBody = msgItem.Replace(opoCommand, ""); errorLevel = IncomingMessageType.WaterTemperature; dbgMsg = opoBody; } else { opoCommand = "WARNING="; if (msgItem.StartsWith(opoCommand)) { string opoBody = msgItem.Replace(opoCommand, ""); errorLevel = IncomingMessageType.Warning; dbgMsg = "Unknown warning reported by Innolas:" + opoBody; } else { opoCommand = "ERROR="; if (msgItem.StartsWith(opoCommand)) { string opoBody = msgItem.Replace(opoCommand, ""); errorLevel = IncomingMessageType.Error; dbgMsg = "Unknown error reported by Innolas:" + opoBody; } } } } } } } } //if (dbgMsg.Contains("\r") || dbgMsg.Contains("\n")) System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("o") + "-Received: " + msgItem); GUI_Communicator.sendStatus("Laser", "StatusDisplay", "EMPFANGE: " + dbgMsg + " (" + errorLevel + ")"); OnNewInnolasMessageEvent(new InnolasMessageEventArgs(dbgMsg, errorLevel)); } } } catch { /* * if (ViewModelLaserBase.laserTrace.TraceWarning) * Xvue.MSOT.ViewModels.Log.ViewModelLog.MsotTrace("Innolas receive thread: " + ex.Message, ViewModelLaserBase.laserTrace); */ } } }