Пример #1
0
 public void ForceGoodReadTone()
 {
     try
     {
         if (!this.IsReady)
         {
             return;
         }
         this._serialDevice?.Write(this.GetCommand("334"));
     }
     catch (Exception ex)
     {
         ILogger <Magellan9300S> logger = this._logger;
         if (logger != null)
         {
             logger.LogError(ex, ex.Message);
         }
         Action <DeviceLog> onDeviceWarning = this.OnDeviceWarning;
         if (onDeviceWarning == null)
         {
             return;
         }
         BarcodeScannerLog barcodeScannerLog = new BarcodeScannerLog();
         barcodeScannerLog.Category = TerminalLogCategory.Warning;
         barcodeScannerLog.Message  = "Cannot make beep";
         onDeviceWarning((DeviceLog)barcodeScannerLog);
     }
 }
Пример #2
0
 public Task <DeviceConnectionStatus> TestDevice()
 {
     lock (this._locker)
     {
         this.CloseIfOpen();
         try
         {
             this._serialDevice.Open();
             this._serialDevice.OnReceivedData = (Func <byte[], bool>)null;
             DeviceConnectionStatus result = DeviceConnectionStatus.InitializationError;
             this.GetReadDataSync("3p=", (Action <string>)(res =>
             {
                 if (!res.ContainsIgnoreCase("OK"))
                 {
                     result = DeviceConnectionStatus.InitializationError;
                 }
                 else
                 {
                     this.ForceGoodReadTone();
                     result = DeviceConnectionStatus.Enabled;
                 }
             }));
             StaticTimer.Wait((Func <bool>)(() => result == DeviceConnectionStatus.InitializationError), 2);
             if (result == DeviceConnectionStatus.InitializationError)
             {
                 return(Task.FromResult <DeviceConnectionStatus>(result));
             }
             result = DeviceConnectionStatus.InitializationError;
             this.GetReadDataSync("14", (Action <string>)(res =>
             {
                 if (!res.StartsWith("S14"))
                 {
                     result = DeviceConnectionStatus.InitializationError;
                 }
                 else
                 {
                     res = res.Substring(3);
                     if (!res.StartsWith("3") && !res.StartsWith("5"))
                     {
                         result = DeviceConnectionStatus.InitializationError;
                     }
                     else
                     {
                         result = DeviceConnectionStatus.Enabled;
                     }
                 }
             }));
             StaticTimer.Wait((Func <bool>)(() => result == DeviceConnectionStatus.InitializationError), 2);
             return(Task.FromResult <DeviceConnectionStatus>(result));
         }
         catch (Exception ex)
         {
             ILogger <Magellan9300S> logger = this._logger;
             if (logger != null)
             {
                 logger.LogError(ex, ex.Message);
             }
             if (ex.Message.ContainsIgnoreCase("port"))
             {
                 Action <DeviceLog> onDeviceWarning = this.OnDeviceWarning;
                 if (onDeviceWarning != null)
                 {
                     BarcodeScannerLog barcodeScannerLog = new BarcodeScannerLog();
                     barcodeScannerLog.Category = TerminalLogCategory.Critical;
                     barcodeScannerLog.Message  = "Device not connected";
                     onDeviceWarning((DeviceLog)barcodeScannerLog);
                 }
                 return(Task.FromResult <DeviceConnectionStatus>(DeviceConnectionStatus.NotConnected));
             }
             Action <DeviceLog> onDeviceWarning1 = this.OnDeviceWarning;
             if (onDeviceWarning1 != null)
             {
                 BarcodeScannerLog barcodeScannerLog = new BarcodeScannerLog();
                 barcodeScannerLog.Category = TerminalLogCategory.Critical;
                 barcodeScannerLog.Message  = "Initialization error";
                 onDeviceWarning1((DeviceLog)barcodeScannerLog);
             }
             return(Task.FromResult <DeviceConnectionStatus>(DeviceConnectionStatus.InitializationError));
         }
         finally
         {
             this._serialDevice.OnReceivedData = new Func <byte[], bool>(this.OnDataReceived);
         }
     }
 }
Пример #3
0
 public DeviceConnectionStatus Init()
 {
     lock (this._locker)
     {
         try
         {
             this._tmpStr = string.Empty;
             if (this._currentStatus == DeviceConnectionStatus.Enabled)
             {
                 return(DeviceConnectionStatus.Enabled);
             }
             Action <DeviceLog> onDeviceWarning1 = this.OnDeviceWarning;
             if (onDeviceWarning1 != null)
             {
                 BarcodeScannerLog barcodeScannerLog = new BarcodeScannerLog();
                 barcodeScannerLog.Category = TerminalLogCategory.All;
                 barcodeScannerLog.Message  = "[Magellan9300S] - Start Initialization";
                 onDeviceWarning1((DeviceLog)barcodeScannerLog);
             }
             this.CloseIfOpen();
             this._serialDevice.OnReceivedData = (Func <byte[], bool>)null;
             this._serialDevice.Open();
             this._serialDevice.Write(this.GetCommand("01"));
             this._serialDevice.Write(this.GetCommand("339"));
             byte[] buffer = new byte[this._serialDevice.ReadBufferSize];
             this._serialDevice.Read(buffer, 0, buffer.Length);
             this._serialDevice.DiscardInBuffer();
             this._serialDevice.DiscardOutBuffer();
             this._serialDevice.Write(this.GetCommand("3p="));
             Action <DeviceLog> onDeviceWarning2 = this.OnDeviceWarning;
             if (onDeviceWarning2 != null)
             {
                 BarcodeScannerLog barcodeScannerLog = new BarcodeScannerLog();
                 barcodeScannerLog.Category = TerminalLogCategory.All;
                 barcodeScannerLog.Message  = "[Magellan9300S] - Get info about scanner";
                 onDeviceWarning2((DeviceLog)barcodeScannerLog);
             }
             for (int index = 0; this._serialDevice.ReadBufferSize < 1 && index < 10; ++index)
             {
                 Thread.Sleep(100);
             }
             byte[] numArray = new byte[this._serialDevice.ReadBufferSize];
             this._serialDevice.Read(numArray, 0, numArray.Length);
             string str = Encoding.ASCII.GetString(numArray);
             if (_logger != null)
             {
                 _logger.LogDebug("[Magellan9300S] - Initialization message - " + str);
             }
             bool flag = str.ContainsIgnoreCase("OK");
             Action <DeviceLog> onDeviceWarning3 = this.OnDeviceWarning;
             if (onDeviceWarning3 != null)
             {
                 BarcodeScannerLog barcodeScannerLog = new BarcodeScannerLog();
                 barcodeScannerLog.Category = TerminalLogCategory.All;
                 barcodeScannerLog.Message  = string.Format("[Magellan9300S] - Initialization result {0}", (object)flag);
                 onDeviceWarning3((DeviceLog)barcodeScannerLog);
             }
             this._currentStatus = flag ? DeviceConnectionStatus.Enabled : DeviceConnectionStatus.InitializationError;
             return(this._currentStatus);
         }
         catch (Exception ex)
         {
             ILogger <Magellan9300S> logger = this._logger;
             if (logger != null)
             {
                 logger.LogError(ex, ex.Message);
             }
             if (ex.Message.ContainsIgnoreCase("port"))
             {
                 Action <DeviceLog> onDeviceWarning = this.OnDeviceWarning;
                 if (onDeviceWarning != null)
                 {
                     BarcodeScannerLog barcodeScannerLog = new BarcodeScannerLog();
                     barcodeScannerLog.Category = TerminalLogCategory.Critical;
                     barcodeScannerLog.Message  = "Device not connected";
                     onDeviceWarning((DeviceLog)barcodeScannerLog);
                 }
                 return(DeviceConnectionStatus.NotConnected);
             }
             Action <DeviceLog> onDeviceWarning1 = this.OnDeviceWarning;
             if (onDeviceWarning1 != null)
             {
                 BarcodeScannerLog barcodeScannerLog = new BarcodeScannerLog();
                 barcodeScannerLog.Category = TerminalLogCategory.Critical;
                 barcodeScannerLog.Message  = "Initialization error";
                 onDeviceWarning1((DeviceLog)barcodeScannerLog);
             }
             return(DeviceConnectionStatus.InitializationError);
         }
         finally
         {
             this._serialDevice.OnReceivedData = new Func <byte[], bool>(this.OnDataReceived);
         }
     }
 }