Example #1
0
File: IOPH_DCP.cs Project: x893/WDS
 public IOPH_DCP(ADTRecord adtRec, IAppMainWindow mainWin)
 {
     _adtRec = adtRec;
     _mainWin = mainWin;
     _teleFromWin = new Telegram(GlobalServices.maxCommandDataLen);
     _teleToWin = new Telegram(GlobalServices.maxReplyDataLen);
     _replyData = new DataBuffer(GlobalServices.maxReplyDataLen);
     _isSeries = false;
     _seriesExecStat = SeriesExecutionState.Stop;
     _taskState = TaskState.TaskReady_OK;
     int num = int.Parse(ConfigurationManager.AppSettings["DCPMaxDataLen"]);
     int num2 = int.Parse(ConfigurationManager.AppSettings["DCPMsgRepeatNr"]);
     int num3 = int.Parse(ConfigurationManager.AppSettings["DCPRecTimeout"]);
     byte num4 = byte.Parse(ConfigurationManager.AppSettings["DCPSOFByte"]);
     _dcpProtocolEngine = new DCPProtocol(this, num, num2, num3, 10, num4);
     _DCPRXMsg = new DCPFrame(num, num4);
     _DCPAnswerMsg = new DCPFrame(num, num4);
     _DCPTXMsg = new DCPFrame(num, num4);
     _DCPTXBuf = new DCPFrame(num, num4);
     if (adtRec.isUsbFtdiDevice())
     {
         _ddi = DDI_USB.instance();
     }
     else if (adtRec.isRS232Device())
     {
         _ddi = DDI_RS232.instance();
     }
     else if (adtRec.isTESTDevice())
     {
         _ddi = DDI_TEST.instance();
     }
     else if (adtRec.isHIDDevice())
     {
         _ddi = DDI_HID.instance();
     }
     else
     {
         GlobalServices.ErrMsg("IOPH_DCP.IOPH_DCP()", "FATAL ERROR: Unknown I/O port type, exit WDS!");
         Application.Exit();
     }
     _iot = new Thread(new ThreadStart(doDeviceIO));
     _iot.IsBackground = true;
     _iot.Name = "IOPH_DCP thread";
     _isTelegramRequest = false;
     _iot.Start();
 }
Example #2
0
File: DCP.cs Project: x893/WDS
 public DCPRetCodes close()
 {
     try
     {
         if (this._port != null)
         {
             if (this._dcpProtocolEngine != null)
             {
                 this._dcpProtocolEngine.controlReceivePacket(false, this._ThreadSleepTime);
                 this._dcpProtocolEngine.terminate();
                 this._dcpProtocolEngine = null;
             }
             this._terminateRequested = true;
             while (this._ioThread.IsAlive)
             {
             }
             if (this.connectionLostEvent != null)
             {
                 this.connectionLostEvent(DCPRetCodes.DCP_CONNECTION_LOST);
             }
             this.closePort();
             this._txFifo.Clear();
             this._respFifo.Clear();
             this._rxFifo.Clear();
             DCP_DLL.Utils.log(this, "close ", "finished");
             return DCPRetCodes.DCP_OK;
         }
         DCP_DLL.Utils.log(this, "close ", "nothing to close");
         return DCPRetCodes.DCP_ERR_COM;
     }
     catch (Exception exception)
     {
         DCP_DLL.Utils.log(this, "close ", exception.Message);
         return DCPRetCodes.DCP_FATAL;
     }
 }
Example #3
0
 public int initialize()
 {
     Interlocked.Increment(ref _adtRec.NumUsers);
     int num = int.Parse(ConfigurationManager.AppSettings["DCPMaxDataLen"]);
     int num2 = int.Parse(ConfigurationManager.AppSettings["DCP2MsgRepeatNr"]);
     int num3 = int.Parse(ConfigurationManager.AppSettings["DCPRecTimeout"]);
     byte num4 = byte.Parse(ConfigurationManager.AppSettings["DCPSOFByte"]);
     _dcpProtocolEngine = new DCPProtocol(this, num, num2, num3, 10, num4, DCPVersion.DCP2);
     _DCPRXMsg = new DCPFrame(num, num4);
     _DCPAnswerMsg = new DCPFrame(num, num4);
     _DCPTXMsg = new DCPFrame(num, num4);
     _DCPTXBuf = new DCPFrame(num, num4);
     if (_adtRec.isUsbFtdiDevice())
     {
         _ddi = DDI_USB.instance();
     }
     else if (_adtRec.isRS232Device())
     {
         _ddi = DDI_RS232.instance();
     }
     else if (_adtRec.isHIDDevice())
     {
         _ddi = DDI_HID.instance();
     }
     else if (_adtRec.isTOOLSTICKDevice())
     {
         _ddi = DDI_TOOLSTICK.instance();
     }
     else if (_adtRec.isTESTDevice())
     {
         _ddi = DDI_TEST.instance();
     }
     else
     {
         _log.Error("IOPH_DATA.initialize() - Unknown I/O port type!");
         return -1;
     }
     _iot = new Thread(new ThreadStart(doDeviceIO));
     _iot.IsBackground = true;
     _iot.Name = "IOPH_DATA thread";
     _isRequestAvailible = false;
     _iot.Start();
     return 0;
 }
Example #4
0
File: IOPH_DCP.cs Project: x893/WDS
 public void ReconnectDevice(ADTRecord adt)
 {
     int num = 10;
     while (--num > 0)
     {
         _adtRec.PortAddress.handle = _ddi.open(_adtRec, 'D');
         if (_adtRec.PortAddress.handle != null)
         {
             break;
         }
         Thread.Sleep(100);
         _log.Warn("IOPH_DCP: ReconnectDevice retry");
     }
     int num2 = int.Parse(ConfigurationManager.AppSettings["DCPMaxDataLen"]);
     int num3 = int.Parse(ConfigurationManager.AppSettings["DCPMsgRepeatNr"]);
     int num4 = int.Parse(ConfigurationManager.AppSettings["DCPRecTimeout"]);
     byte num5 = byte.Parse(ConfigurationManager.AppSettings["DCPSOFByte"]);
     _dcpProtocolEngine = new DCPProtocol(this, num2, num3, num4, 10, num5);
     if (num == 0)
     {
         _log.Error("IOPH_DCP: ReconnectDevice Failed: " + adt.PortAddress.DeviceID);
     }
     _ddi.enablePollerRun(true);
 }
Example #5
0
File: DCP.cs Project: x893/WDS
 public DCPRetCodes open(string a_port, string a_initString)
 {
     try
     {
         StopBits one;
         if ((this._port != null) && this._port.IsOpen)
         {
             return DCPRetCodes.DCP_ERR_COM;
         }
         string[] strArray = a_initString.Split(new char[] { ',' });
         int baudRate = int.Parse(strArray[0]);
         int dataBits = int.Parse(strArray[1]);
         Parity space = Parity.Space;
         string str = strArray[2].ToUpper();
         if (str != null)
         {
             if (!(str == "N"))
             {
                 if (str == "E")
                 {
                     goto Label_0085;
                 }
                 if (str == "O")
                 {
                     goto Label_0089;
                 }
             }
             else
             {
                 space = Parity.None;
             }
         }
         goto Label_008B;
     Label_0085:
         space = Parity.Even;
         goto Label_008B;
     Label_0089:
         space = Parity.Odd;
     Label_008B:
         one = StopBits.None;
         string str2 = strArray[3];
         if (str2 != null)
         {
             if (!(str2 == "1"))
             {
                 if (str2 == "5")
                 {
                     goto Label_00C7;
                 }
                 if (str2 == "2")
                 {
                     goto Label_00CC;
                 }
             }
             else
             {
                 one = StopBits.One;
             }
         }
         goto Label_00CF;
     Label_00C7:
         one = StopBits.OnePointFive;
         goto Label_00CF;
     Label_00CC:
         one = StopBits.Two;
     Label_00CF:
         this._port = new SerialPort(a_port, baudRate, space, dataBits, one);
         this._port.Open();
         this._port.ReadTimeout = 1;
         this._dcpProtocolEngine = new DCPProtocol(this, this._DCPMaxDataLen, this._DCPMsgRepeatNr, this._DCPRecTimeout, this._ThreadSleepTime, this._DCPSOFByte);
         this._DCPRXMsg = new DCPFrame(this._DCPMaxDataLen, this._DCPSOFByte);
         this._DCPTXBuf = new DCPFrame(this._DCPMaxDataLen, this._DCPSOFByte);
         this._DCPTXMsg = new DCPFrame(this._DCPMaxDataLen, this._DCPSOFByte);
         this._DCPAnswerMsg = new DCPFrame(this._DCPMaxDataLen, this._DCPSOFByte);
         this._dcpProtocolEngine.controlReceivePacket(true, this._ThreadSleepTime);
         this._terminateRequested = false;
         this._ioThread = new Thread(new ThreadStart(this.DeviceIOThread));
         this._ioThread.Name = "DCP_DLL IO thread";
         this._ioThread.IsBackground = true;
         this._ioThread.Start();
         DCP_DLL.Utils.log(this, "opened ", a_port.ToString() + " " + a_initString);
         return DCPRetCodes.DCP_OK;
     }
     catch (Exception exception)
     {
         this.closePort();
         DCP_DLL.Utils.log(this, "open ", exception.Message);
         return DCPRetCodes.DCP_FATAL;
     }
 }