Exemple #1
0
 public IOPH_EZLinkDongle(ADTRecord adtRec, IAppMainWindow mainWin)
 {
     this._adtRec = adtRec;
     this._mainWin = mainWin;
     this._teleFromWin = new Telegram(0x3e8);
     this._teleToWin = new Telegram(0x3e8);
     this._replyData = new DataBuffer(0x3e8);
     this._isSeries = false;
     this._seriesExecStat = SeriesExecutionState.Stop;
     this._taskEvent = new AutoResetEvent(false);
     this._taskState = TaskState.TaskReady_OK;
     if (adtRec.isUsbEZLinkDevice())
     {
         this._ddi = DDI_EZLinkDongle.instance();
     }
     else if (adtRec.isTESTDevice())
     {
         this._ddi = DDI_TEST.instance();
     }
     else
     {
         GlobalServices.ErrMsg("FATAL ERROR: IOPH_EZLinkDongle", "I/O port type not supported, exit WDS!");
         Application.Exit();
     }
     this._iot = new Thread(new ThreadStart(this.doDeviceIO));
     this._iot.IsBackground = true;
     this._iot.Name = "IOPH_EZLink thread";
     this._isTelegramRequest = false;
     this._isRxTimerRequest = false;
     this._isReadRxPacketEnabled = false;
     this._iot.Start();
 }
Exemple #2
0
 public int flushRead(DeviceHandle handle, DataBuffer data)
 {
     if (handle.isInvalid())
     {
         GlobalServices.ErrMsg("DDI_TEST.flushRead()", "called with INVALID handle");
         return -1;
     }
     data.copy(handle.TestDevHnd.readBuff);
     handle.TestDevHnd.readBuff.NumItems = 0;
     handle.TestDevHnd.readBuffIdx = 0;
     return data.NumItems;
 }
Exemple #3
0
 public DCPProtocol(IDCPDeviceInterface a_devInterface, int a_DCPMaxDataLen, int a_DCPMsgRepeatNr, int a_DCPRecTimeout, int a_ThreadSleepTime, byte a_DCPSOFByte)
 {
     _DCPMaxDataLen = 0x7c;
     _DCPMsgRepeatNr = 3;
     _DCPSOFByte = 0x55;
     _ThreadSleepTime = 10;
     _DCPRecTimeout = 500;
     _DCPMsgRepeatNr = a_DCPMsgRepeatNr;
     _DCPMaxDataLen = a_DCPMaxDataLen;
     _DCPSOFByte = a_DCPSOFByte;
     _DCPRecTimeout = a_DCPRecTimeout;
     _ThreadSleepTime = a_ThreadSleepTime;
     _devInterface = a_devInterface;
     _buffer = new DataBuffer(10);
 }
Exemple #4
0
 public int flushRead(DeviceHandle handle, DataBuffer data)
 {
     int bytesInRxQueue = 0;
     if (handle.isInvalid())
     {
         GlobalServices.ErrMsg("DDI_USB.flushRead()", "called with INVALID handle");
         return -1;
     }
     if (FTDIWrapper.GetRxQueueLen(handle.USBhnd.hnd, ref bytesInRxQueue) != 0)
     {
         GlobalServices.ErrMsg("DDI_USB.flushRead()", "FTDIWrapper.GetRxQueueLen() returned:" + FTDIWrapper.GetErrorString());
         return -1;
     }
     return this.read(handle, data, bytesInRxQueue);
 }
Exemple #5
0
 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();
 }
Exemple #6
0
 public bool isDeviceAlive(DeviceHandle handle)
 {
     DataBuffer data = new DataBuffer("\r".Length + "\n\rOK\n\r>".Length);
     if (handle.isInvalid())
     {
         GlobalServices.ErrMsg("DDI_TEST.isDeviceAlive()", "called with INVALID handle");
         return false;
     }
     data.copy("\r");
     if (this.write(handle, data) < 0)
     {
         return false;
     }
     if (this.read(handle, data, data.Capacity) < 0)
     {
         return false;
     }
     return data.endsWith("\n\rOK\n\r>");
 }
Exemple #7
0
 public IOPH_LoadBoard(ADTRecord adtRec, IAppMainWindow mainWin)
 {
     this._adtRec = adtRec;
     this._mainWin = mainWin;
     this._teleFromWin = new Telegram(GlobalServices.maxCommandDataLen);
     this._teleToWin = new Telegram(GlobalServices.maxReplyDataLen);
     this._replyData = new DataBuffer(GlobalServices.maxReplyDataLen, Data_Type.ASCII);
     this._isSeries = false;
     this._seriesExecStat = SeriesExecutionState.Stop;
     this._taskEvent = new AutoResetEvent(false);
     this._taskState = TaskState.TaskReady_OK;
     if (adtRec.isUsbFtdiDevice())
     {
         this._ddi = DDI_USB.instance();
         this._isTestDevice = false;
     }
     else if (adtRec.isRS232Device())
     {
         this._ddi = DDI_RS232.instance();
         this._isTestDevice = false;
     }
     else if (adtRec.isTESTDevice())
     {
         this._ddi = DDI_TEST.instance();
         this._isTestDevice = true;
     }
     else if (adtRec.isHIDDevice())
     {
         this._ddi = DDI_HID.instance();
         this._isTestDevice = false;
     }
     else
     {
         GlobalServices.ErrMsg("IOPH_LoadBoard.IOPH_LoadBoard()", "FATAL ERROR: Unknown I/O port type, exit WDS!");
         GlobalServices.msgBox("FATAL ERROR: Unknown I/O port type, exit WDS!", "IOPH_LoadBoard.IOPH_LoadBoard()");
         Application.Exit();
     }
     this.ReadReplytimerDelegate = new TimerCallback(this.rxReadReplyTimerTickHandler);
     this._iot = new Thread(new ThreadStart(this.doDeviceIO));
     this._iot.IsBackground = true;
     this._iot.Name = "IOPH_LoadBoard thread";
     this._iot.Start();
 }
Exemple #8
0
        public DCPRetCodes AnswerToDCPMessage(DataBuffer a_data, MessageTypes a_msgType, CommandSet a_cmdSet, DCPFrame a_txMsg, DCPFrame a_rxMsg)
        {
            DataBuffer buffer = new DataBuffer(a_data.NumItems + 4);
            byte num = (byte) a_msgType;
            buffer = a_data;
            switch (num)
            {
                case 0x40:
                case 0x80:
                    a_txMsg.CmdSet = (byte) a_cmdSet;
                    a_txMsg.SeqNum = a_rxMsg.SeqNum;
                    break;
            }
            int num2 = 0;
            while (num2 < _DCPMsgRepeatNr)
            {
                DCPRetCodes codes;
                if (_dcpVersion == DCPVersion.DCP)
                {
                    codes = a_txMsg.ConstructDCPmsg(buffer, a_cmdSet, a_msgType);
                }
                else
                {
                    codes = a_txMsg.ConstructDCP2msg(buffer, a_cmdSet, a_msgType);
                }
                codes = doExchangeDCP_TX(a_txMsg, a_rxMsg);
                switch (codes)
                {
                    case DCPRetCodes.DCP_RESP_SENT:
                        return codes;

                    case DCPRetCodes.DCP_FATAL:
                        return codes;
                }
                return DCPRetCodes.DCP_FATAL;
            }
            return DCPRetCodes.DCP_FATAL;
        }
Exemple #9
0
 private bool SendRequest(string request, int sliptime)
 {
     DataBuffer data = new DataBuffer(1);
     byte[] buf = new byte[2];
     Thread.Sleep(sliptime);
     for (int i = 0; i < request.Length; i++)
     {
         buf[0] = (byte) request[i];
         data.copy(buf, 1);
         Thread.Sleep(sliptime);
         if (_ddi.write(_adtRecord.PortAddress.handle, data) != 0)
             return false;
     }
     return true;
 }
Exemple #10
0
 public int WriteDevice(DataBuffer buf)
 {
     return _ddi.write(_adtRec.PortAddress.handle, buf);
 }
Exemple #11
0
        private void execReceiveCommandFromDevice()
        {
            int initialTimeout = int.Parse(ConfigurationManager.AppSettings["DCP2IndicationTimeout"]);
            Interlocked.Increment(ref _adtRec.IsDeviceBusy);
            lock (_adtRec.DevSyncObj)
            {
                DCPRetCodes codes = _dcpProtocolEngine.doRxDCP(initialTimeout, _DCPRXMsg);
                if ((codes != DCPRetCodes.DCP_ERR_TIMEOUT) || (codes != DCPRetCodes.DCP_TERMINATED))
                {
                    TelegramType deviceFailure;
                    switch (codes)
                    {
                        case DCPRetCodes.DCP_OK:
                        {
                            deviceFailure = TelegramType.PacketRecERROR;
                            if (_DCPRXMsg.MsgType == 0)
                            {
                                deviceFailure = TelegramType.PacketRecOK;
                            }
                            _dcpProtocolEngine.AnswerToDCPMessage(new DataBuffer(), MessageTypes.ACK, (CommandSet)_teleFromWin.DCPCmdSet, _DCPTXBuf, _DCPRXMsg);
                            sendTelegramToMainWin(deviceFailure, null, _DCPRXMsg);
                            DataBuffer buffer = new DataBuffer(4);
                            buffer.copy(new byte[2]);
                            _dcpProtocolEngine.exchangeDCPMessage(buffer, MessageTypes.SynchReqOrIndication, (CommandSet)_teleFromWin.DCPCmdSet, _DCPTXMsg, _DCPAnswerMsg);
                            goto Label_014F;
                        }
                        case DCPRetCodes.DCP_FATAL:
                            deviceFailure = TelegramType.DeviceFailure;
                            sendTelegramToMainWin(deviceFailure, null);
                            goto Label_014F;

                        case DCPRetCodes.DCP_ERR_TIMEOUT:
                            goto Label_014F;
                    }
                    deviceFailure = TelegramType.DeviceFailure;
                    sendTelegramToMainWin(deviceFailure, null);
                }
            Label_014F:;
            }
            Interlocked.Decrement(ref _adtRec.IsDeviceBusy);
        }
Exemple #12
0
 public int flushRead(DeviceHandle handle, DataBuffer data)
 {
     int num;
     if (handle.isInvalid())
     {
         _log.Warn("Called with INVALID handle");
         return -1;
     }
     data.NumItems = 0;
     while ((num = readAppend(handle, data, 1)) == 1)
     {
     }
     if (num == -1)
     {
         _log.Warn("readAppend() returned with -1");
         return -1;
     }
     return data.NumItems;
 }
Exemple #13
0
 public int ReadAppendDevice(DataBuffer buf, int bytesToRead)
 {
     return _ddi.readAppend(_adtRec.PortAddress.handle, buf, bytesToRead);
 }
Exemple #14
0
        public DCPRetCodes exchangeDCPMessage(DataBuffer a_data, MessageTypes a_msgType, CommandSet a_cmdSet, DCPFrame a_txMsg, DCPFrame a_rxMsg)
        {
            MessageTypes synchReqOrIndication;
            DataBuffer buffer = new DataBuffer(a_data.NumItems + 4);
            MessageTypes types = synchReqOrIndication = a_msgType;
            buffer = a_data;
            TaskState writingCommand = TaskState.WritingCommand;
            switch (synchReqOrIndication)
            {
                case MessageTypes.ACK:
                case MessageTypes.Nack:
                    return DCPRetCodes.DCP_FATAL;
            }
            for (int i = 0; i < _DCPMsgRepeatNr; i++)
            {
                DCPRetCodes codes;
                switch (_dcpVersion)
                {
                    case DCPVersion.DCP2:
                        codes = a_txMsg.ConstructDCP2msg(buffer, a_cmdSet, synchReqOrIndication);
                        break;

                    default:
                        codes = a_txMsg.ConstructDCPmsg(buffer, a_cmdSet, synchReqOrIndication);
                        break;
                }
                codes = doExchangeDCP_TX(a_txMsg, a_rxMsg);
                switch (codes)
                {
                    case DCPRetCodes.DCP_RESP_SENT:
                        return codes;

                    case DCPRetCodes.DCP_FATAL:
                        return codes;

                    case DCPRetCodes.DCP_ERR_TIMEOUT:
                    case DCPRetCodes.DCP_ERR_EDC:
                        break;

                    default:
                        if (codes != DCPRetCodes.DCP_OK)
                            return DCPRetCodes.DCP_FATAL;

                        if (a_rxMsg.SeqNum == a_txMsg.SeqNum)
                        {
                            if ((a_rxMsg.MsgType != 0) && (a_rxMsg.MsgType != 0xc0))
                            {
                                if (a_rxMsg.MsgType != 0x80)
                                {
                                    if (a_rxMsg.MsgType != 0x40)
                                        return DCPRetCodes.DCP_FATAL;
                                    if (writingCommand != TaskState.SynchReq)
                                    {
                                        if (a_rxMsg.Len > 2)
                                            return DCPRetCodes.DCP_OK_ACK;
                                        return DCPRetCodes.DCP_OK;
                                    }
                                    synchReqOrIndication = types;
                                    buffer = a_data;
                                    writingCommand = TaskState.WritingCommand;
                                }
                                else
                                {
                                    if (a_rxMsg.CmdSet != 0)
                                        return DCPRetCodes.DCP_OK_NACK;
                                    if (a_rxMsg.Data[0] != 0)
                                        return DCPRetCodes.DCP_OK_NACK;
                                }
                            }
                        }
                        else
                        {
                            writingCommand = TaskState.SynchReq;
                            synchReqOrIndication = MessageTypes.SynchReqOrIndication;
                            buffer.NumItems = 0;
                        }
                        break;
                }
            }
            return DCPRetCodes.DCP_FATAL;
        }
Exemple #15
0
        private DCPRetCodes doExchangeDCP_TX(DCPFrame a_dcpTxMsg, DCPFrame a_dcpRxMsg)
        {
            int dueTime = _DCPRecTimeout;
            DataBuffer dataToSend = new DataBuffer(a_dcpTxMsg.Data.Length + 4);
            DCPRetCodes codes = a_dcpTxMsg.CopyDCPmsgToDataBuffer(dataToSend);
            int num2 = 0;
            if (_devInterface != null)
                num2 = _devInterface.WriteDevice(dataToSend);

            if (num2 != -1)
            {
                if ((a_dcpTxMsg.MsgType == 0x40) || (a_dcpTxMsg.MsgType == 0x80))
                    return DCPRetCodes.DCP_RESP_SENT;

                _isSOFTimeOut = false;
                _rxTimer = new System.Threading.Timer(new TimerCallback(rxSOFTimerTickHandler), null, dueTime, -1);
                while (!_isSOFTimeOut)
                    if (checkIfSOFArrived() == DCPRetCodes.DCP_OK)
                    {
                        if (_rxTimer != null)
                        {
                            _rxTimer.Dispose();
                            _rxTimer = null;
                        }
                        return doRxDCP(dueTime, a_dcpRxMsg);
                    }

                if (_rxTimer != null)
                {
                    _rxTimer.Dispose();
                    _rxTimer = null;
                }
            }
            return DCPRetCodes.DCP_FATAL;
        }
Exemple #16
0
 public DCPRetCodes CopyDCPmsgToDataBuffer(DataBuffer DataToSend)
 {
     if (DataToSend != null)
     {
         int num = 0;
         DataToSend.NumItems = 3;
         DataToSend[num++] = this._DCPSOFByte;
         DataToSend[num++] = this.Len;
         DataToSend[num++] = this.Ctrl;
         DataToSend.appendFromStartIdx(this.Data, 0, this.Len - 2);
         num += this.Len - 2;
         DataToSend.NumItems++;
         DataToSend[num] = this.EDC;
         DataToSend.DType = Data_Type.Binary;
         return DCPRetCodes.DCP_OK;
     }
     return DCPRetCodes.DCP_FATAL;
 }
Exemple #17
0
 private bool ExchCmdWithDev(DeviceHandle a_Handle, DataBuffer a_Data)
 {
     int writeRetryCnt = int.Parse(ConfigurationManager.AppSettings["WriteRetryCnt"]);
     DataBuffer data = new DataBuffer(512)
     {
         DType = Data_Type.ASCII
     };
     while (writeRetryCnt > 0)
     {
         data.copy(a_Data);
         int readRetryCnt = int.Parse(ConfigurationManager.AppSettings["ReadRetryCnt"]);
         if (write(a_Handle, data) < 0)
         {
             _log.Warn("Device was probably disconnected.  write() returned with -1");
             return false;
         }
         Thread.Sleep(100);
         data.NumItems = 0;
         while (readRetryCnt > 0)
         {
             if (readAppend(a_Handle, data, data.Capacity - data.NumItems) < 0)
             {
                 _log.Warn("Device was probably disconnected.  readAppend() returned with -1");
                 Thread.Sleep(50);
                 readRetryCnt--;
             }
             else
             {
                 if (data.endsWith("OK\n\r>"))
                 {
                     a_Data.copy(data);
                     return true;
                 }
                 Thread.Sleep(100);
                 readRetryCnt--;
             }
         }
         writeRetryCnt--;
     }
     a_Data.NumItems = 0;
     return false;
 }
Exemple #18
0
 public int readAppend(DeviceHandle handle, DataBuffer data, int bytesToRead)
 {
     int num2;
     byte[] buffer = new byte[bytesToRead];
     int num = 0;
     int num5 = bytesToRead;
     try
     {
         if (handle == null || handle.isInvalid() || !handle.RS232hnd.hnd.IsOpen)
         {
             string portName = "unknown port";
             if (handle != null && handle.RS232hnd != null && handle.RS232hnd.hnd != null)
                 portName = handle.RS232hnd.hnd.PortName;
             _log.Error("readAppend() - " + portName + " - Port is not accessible");
             return -1;
         }
         if (data.Capacity < (data.NumItems + num5))
         {
             if (_log.IsErrorEnabled)
                 _log.Error("readAppend() - DataBuffer is too small: data.Capacity:'" + data.Capacity.ToString() + "' < data.NumItems:'" + data.NumItems.ToString() + "' + bytesToRead:'" + num5.ToString() + "'");
             return -1;
         }
     }
     catch (Exception exception)
     {
         _log.Error("readAppend() 1 - " + exception.Message);
         return -1;
     }
     int num4 = num2 = data.NumItems;
     data.NumItems += num5;
     do
     {
         try
         {
             int num7 = handle.RS232hnd.hnd.BytesToRead;
             num = handle.RS232hnd.hnd.Read(buffer, 0, (num5 < num7) ? num5 : num7);
         }
         catch (TimeoutException)
         {
         }
         catch (Exception exception2)
         {
             _log.Error("readAppend() 2 - " + exception2.Message);
             return -1;
         }
         int num3 = 0;
         num5 = 0;
         while (num3 < num)
         {
             byte num6 = buffer[num3++];
             if (data.DType == Data_Type.ASCII)
             {
                 if (num6 != 0)
                     data[num2++] = num6;
                 else
                 {
                     num5++;
                     _log.Warn("delivered a NULL byte");
                 }
             }
             else
                 data[num2++] = num6;
         }
     } while (num5 > 0);
     data.NumItems = num2;
     return (num2 - num4);
 }
Exemple #19
0
 public void StopIdentifyDevice(DeviceHandle handle, DeviceDescriptor a_dev)
 {
     DataBuffer data = new DataBuffer(128);
     int pollDeviceTypeProcDelay = int.Parse(ConfigurationManager.AppSettings["PollDeviceTypeProcDelay"]);
     if ((a_dev.DeviceType != null) && (a_dev.DeviceType.TypeID == DeviceTypeID.LoadBoard))
     {
         data.copy("d0\r");
         write(handle, data);
         Thread.Sleep(pollDeviceTypeProcDelay);
     }
 }
Exemple #20
0
 public int read(DeviceHandle handle, DataBuffer data, int bytesToRead)
 {
     if (handle.isInvalid())
     {
         _log.Error("read() - Called with INVALID handle");
         return -1;
     }
     data.NumItems = 0;
     return readAppend(handle, data, bytesToRead);
 }
Exemple #21
0
 public void IdentifyDevice(DeviceHandle handle, DeviceDescriptor a_dev)
 {
     if (a_dev.DeviceType != null && a_dev.DeviceType.TypeID == DeviceTypeID.LoadBoard)
     {
         DataBuffer data = new DataBuffer(128);
         data.copy("d3\r");
         write(handle, data);
         Thread.Sleep(int.Parse(ConfigurationManager.AppSettings["PollDeviceTypeProcDelay"]));
     }
 }
Exemple #22
0
        private void queryEBID(DeviceHandle handle, DeviceDescriptor a_dev)
        {
            DataBuffer data = new DataBuffer(512)
            {
                DType = Data_Type.ASCII
            };
            string bufToStr = "";
            if (handle.isInvalid() || a_dev.DeviceType == null)
                _log.Error("queryEBID() - Called with INVALID argument");
            else
            {
                flushRead(handle, data);
                if (a_dev.FirmwareType != null &&
                    (a_dev.FirmwareType.Name == "LoadBoard" || a_dev.FirmwareType.Name == "LoadBoard_Lite")
                    )
                {
                    switch (a_dev.DeviceType.TypeID)
                    {
                        case DeviceTypeID.LoadBoard:
                        case DeviceTypeID.SDBC:
                            data.copy("L6\r");
                            write(handle, data);
                            return;

                        case DeviceTypeID.EZLink:
                        case DeviceTypeID.SRW002:
                        case DeviceTypeID.Unknown:
                            return;

                        case DeviceTypeID.SRW004:
                            data.copy("ged\r");
                            if (ExchCmdWithDev(handle, data) && data.BufToStr.Contains("0x40"))
                            {
                                data.copy("gwd\r");
                                if (ExchCmdWithDev(handle, data))
                                {
                                    bufToStr = data.BufToStr;
                                    try
                                    {
                                        string[] strArray = bufToStr.Split(new char[] { ' ' });
                                        int index = strArray[0].IndexOf("x");
                                        strArray[0] = strArray[0].Remove(0, index + 1);
                                        for (int i = 1; i < strArray.Length; i++)
                                            strArray[i] = strArray[i].Replace("0x", "");

                                        byte[] bytes = new byte[strArray.Length];
                                        for (int j = 0; j < (strArray.Length - 1); j++)
                                            bytes[j] = Convert.ToByte(strArray[j], 16);

                                        string str3 = Encoding.Default.GetString(bytes);
                                        if (str3.Length > 6)
                                        {
                                            switch(str3.Substring(0, 6))
                                            {
                                                case "SI1000":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1000";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                                case "SI1002":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1002";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                                case "SI1004":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1004";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                                case "SI1010":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1010";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                                case "SI1012":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1012";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                                case "SI1014":
                                                    a_dev.PnPEBID = new CDTRecord();
                                                    a_dev.PnPEBID.ChipType = "Si1014";
                                                    a_dev.PnPEBID.ChipClass = "Transceiver";
                                                    a_dev.PnPEBID.ChipRevision = "B1";
                                                    break;
                                            }
                                        }
                                    }
                                    catch (FormatException exception)
                                    {
                                        _log.Error("queryEBID()" + exception.Message);
                                    }
                                }
                            }
                            return;
                    }
                }
            }
        }
Exemple #23
0
        private FDResult WriteFirmwareToDevice(ArrayList firmware, UpdateFirmwareCallback callback)
        {
            FDResult oK = FDResult.OK;
            try
            {
                if (_adtRecord.PortAddress.comAddr.COMPortId <= 0)
                {
                    callback(0, true, "The com port: " + _adtRecord.PortAddress.comAddr.COMPortId.ToString() + " is not valid.", MessageBoxButtons.OK);
                    return FDResult.FatalError;
                }
                _ddi.enablePollerRun(false);
                Thread.Sleep(300);
                bool flag = false;

                do
                {
                    flag = false;
                    try
                    {
                        int num;
                        _log.Info("==== WriteFirmwareToDevice ==== ");
                        if (_adtRecord.DeviceInfo.DeviceType.TypeID != DeviceTypeID.SRW002)
                        {
                            num = _ddi.close(_adtRecord.PortAddress.handle);
                            _adtRecord.PortAddress.comAddr.baudRate = 19200;
                            _adtRecord.PortAddress.handle = _ddi.open(_adtRecord, 'E');
                        }
                        if (!SendRequest("bl\r"))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while writing command to change to boot loader mode of the device.");
                        }
                        Thread.Sleep(100);
                        num = _ddi.close(_adtRecord.PortAddress.handle);
                        _adtRecord.PortAddress.handle = null;
                        if (num != 0)
                        {
                            oK = FDResult.Error;
                            throw new Exception("Error while closing serial port.");
                        }
                        _adtRecord.PortAddress.comAddr.baudRate = 115200;
                        _adtRecord.PortAddress.handle = _ddi.open(_adtRecord, 'E');
                        if (_adtRecord.PortAddress.handle == null)
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("The serial port could not be opened in high speed mode.");
                        }
                        Thread.Sleep(100);
                        _log.Info("in bl mode: J cmd");
                        if (!SendRequest("J\r"))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while writing command to change the communication speed on the device.");
                        }
                        if (WaitForResponse("BLD", "V1.10W"))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while waiting for response to Get Bootloader revision.");
                        }
                        string response = respBuff.objectInfo(false);
                        _log.Info("in bl mode: response of 'J':" + response);
                        if (response.Contains("SRW"))
                        {
                            string[] strArray = response.Split(new char[] { ',' });
                            string text1 = strArray[0];
                            if (strArray[3].Substring(0, 3) != "BLD")
                            {
                                oK = FDResult.FatalError;
                                throw new Exception("HW is not in Bootloader mode");
                            }
                            if (strArray[2] != "01.2r")
                            {
                                oK = FDResult.FatalError;
                                throw new Exception("Bootloader revision mismatch.");
                            }
                        }
                        response = "";
                        _log.Info("in bl mode: Na5f1H cmd");
                        if (!SendRequest("Na5f1H"))
                        {
                            oK = FDResult.Error;
                            throw new Exception("Error while writing command to Set Key Sequence on the device.");
                        }
                        if (WaitForResponse("E09", null))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while waiting for response to Set Key Sequence on the device.");
                        }
                        _log.Info("in bl mode: K cmd");
                        if (!SendRequest("K"))
                        {
                            oK = FDResult.Error;
                            throw new Exception("Error while writing command to Set Key Sequence on the device.");
                        }
                        if (WaitForResponse("EA\r\nOK\r\n>", null, 50))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while waiting for response to Set Key Sequence on the device.");
                        }
                        _log.Info("in bl mode: download loop");
                        for (int i = 0; i < firmware.Count; i++)
                        {
                            string fw_cmd = (string)firmware[i];
                            DataBuffer data = new DataBuffer(fw_cmd.Length);
                            data.copy(fw_cmd);
                            Thread.Sleep(1);
                            if (_ddi.write(_adtRecord.PortAddress.handle, data) != 0)
                            {
                                oK = FDResult.FatalError;
                                throw new Exception("Error while writing firmware command.");
                            }
                            callback((int)Math.Round((double)((((double)(i + 1)) / ((double)firmware.Count)) * 100.0), 0), false, "", MessageBoxButtons.OK);
                        }
                        _log.Info("in bl mode: end of download loop");
                        if (WaitForResponse("E09", null))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while waiting for response to Hex download.");
                        }
                        _log.Info("in bl mode: L mcd");
                        if (!SendRequest("L"))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while checking image integrity.");
                        }
                        if (WaitForResponse("00000000", null))
                        {
                            oK = FDResult.FatalError;
                            throw new Exception("Error while waiting for response to check image integrity.");
                        }
                        _log.Info("in bl mode: M cmd");
                        if (!SendRequest("M"))
                        {
                            oK = FDResult.Error;
                            throw new Exception("Error while starting application.");
                        }
                        _log.Info("==== WriteFirmwareToDevice has finished ====");
                        Thread.Sleep(1000);
                    }
                    catch (Exception exception)
                    {
                        _log.Info("in bl mode: error occured:" + exception.Message);
                        flag = false;
                        switch (callback(0, true, "There was an error while writing the firmware to the device.\r\n" + exception.Message, MessageBoxButtons.RetryCancel))
                        {
                            case DialogResult.Cancel:
                                flag = false;
                                break;
                            case DialogResult.Retry:
                                flag = true;
                                break;
                            default:
                                flag = false;
                                break;
                        }
                    }
                } while (flag);
            }
            catch (Exception exception2)
            {
                callback(0, true, "There was a fatal error while writing the firmware to the device.\r\n" + exception2.Message, MessageBoxButtons.OK);
            }
            finally
            {
                _ddi.close(_adtRecord.PortAddress.handle);
                _adtRecord.PortAddress.comAddr.baudRate = 19200;
                _adtRecord.PortAddress.handle = _ddi.open(_adtRecord, 'D');
                _ddi.enablePollerRun(true);
            }
            return oK;
        }
Exemple #24
0
        private bool isDeviceAlive(IOPortAddress iopaddr, out bool bootLoaderMode, out DeviceTypeID deviceType)
        {
            string command_CR = "\r";
            DataBuffer data = new DataBuffer(100);
            bootLoaderMode = false;
            deviceType = DeviceTypeID.Unknown;

            if (iopaddr.handle == null)
                return false;
            if (iopaddr.handle.isInvalid())
            {
                _log.Warn("Called with INVALID handle");
                return false;
            }

            int writeRetryCnt = int.Parse(ConfigurationManager.AppSettings["WriteRetryCnt"]);
            int readRetryCnt = int.Parse(ConfigurationManager.AppSettings["ReadRetryCnt"]);

            while (writeRetryCnt > 0)
            {
                data.copy(command_CR);
                if (write(iopaddr.handle, data) < 0)
                {
                    Thread.Sleep(10);
                    writeRetryCnt--;
                }
                else
                {
                    _log.Debug("[CR] was sent");
                    data.NumItems = 0;
                    int readCount = readRetryCnt;
                    while (readCount > 0)
                    {
                        if (readAppend(iopaddr.handle, data, data.Capacity - data.NumItems) < 0)
                            readCount--;
                        else
                        {
                            if (data.endsWith("OK\n\r>"))
                            {
                                _log.Debug("Device looks to be alive");
                                return true;
                            }
                            Thread.Sleep(20);
                            readCount--;
                        }
                    }
                    Thread.Sleep(20);
                    writeRetryCnt--;
                }
            }
            _log.Debug("Device to be checked with RTS control enabled");
            close(iopaddr.handle);

            iopaddr.handle = open(iopaddr, 19200, 'E');
            _log.Debug("Port opened by isDeviceAlive()@19200:" + iopaddr.comAddr.COMPortId + " DTR Enabled");
            writeRetryCnt = int.Parse(ConfigurationManager.AppSettings["WriteRetryCnt"]);
            readRetryCnt = int.Parse(ConfigurationManager.AppSettings["ReadRetryCnt"]);
            while (writeRetryCnt > 0)
            {
                data.copy(command_CR);
                if (write(iopaddr.handle, data) < 0)
                {
                    Thread.Sleep(10);
                    writeRetryCnt--;
                }
                else
                {
                    _log.Debug("isDeviceAlive():: '\r' sent");
                    data.NumItems = 0;
                    int num4 = readRetryCnt;
                    while (num4 > 0)
                    {
                        if (readAppend(iopaddr.handle, data, data.Capacity - data.NumItems) < 0)
                        {
                            Thread.Sleep(10);
                            num4--;
                        }
                        else
                        {
                            _log.Debug("isDeviceAlive():: response to '\r':" + data.BufToStr);
                            if (data.BufToStr.Contains("OK\n\r>"))
                                return true;
                            Thread.Sleep(20);
                            num4--;
                        }
                    }
                    Thread.Sleep(20);
                    writeRetryCnt--;
                }
            }
            close(iopaddr.handle);
            _log.Debug("Port closed by isDeviceAlive()@19200:" + iopaddr.comAddr.COMPortId);

            iopaddr.handle = open(iopaddr, 115200, 'D');
            _log.Debug("Port opened by isDeviceAlive()@115200:" + iopaddr.comAddr.COMPortId);
            for (int i = 0; i < 4; i++)
            {
                data.copy("J");
                if (write(iopaddr.handle, data) < 0)
                    Thread.Sleep(10);
                Thread.Sleep(50);
                _log.Debug("isDeviceAlive():: 'J' sent");
                data.NumItems = 0;
                int readCnt = readRetryCnt;
                while (readCnt > 0)
                {
                    if (readAppend(iopaddr.handle, data, data.Capacity - data.NumItems) < 0)
                    {
                        Thread.Sleep(10);
                        readCnt--;
                    }
                    else
                    {
                        _log.Debug("isDeviceAlive():: response to 'J':" + data.BufToStr);
                        if (data.endsWith("OK\r\n>\r\n"))
                        {
                            deviceType = DeviceTypeID.SDBC_8;
                            bootLoaderMode = true;
                            return true;
                        }
                        Thread.Sleep(20);
                        readCnt--;
                    }
                }
            }

            writeRetryCnt = int.Parse(ConfigurationManager.AppSettings["WriteRetryCnt"]);
            readRetryCnt = int.Parse(ConfigurationManager.AppSettings["ReadRetryCnt"]);
            while (writeRetryCnt > 0)
            {
                data.copy("OK\n\r>");
                if (write(iopaddr.handle, data) < 0)
                {
                    Thread.Sleep(10);
                    writeRetryCnt--;
                }
                else
                {
                    _log.Debug("[CRLF] sent");
                    data.NumItems = 0;
                    int num7 = readRetryCnt;
                    while (num7 > 0)
                    {
                        if (readAppend(iopaddr.handle, data, data.Capacity - data.NumItems) < 0)
                        {
                            Thread.Sleep(10);
                            num7--;
                        }
                        else
                        {
                            _log.Debug("Response to [CRLF]:" + data.BufToStr);
                            if (data.endsWith("OK\n\r>"))
                                return true;
                            Thread.Sleep(20);
                            num7--;
                        }
                    }
                    Thread.Sleep(20);
                    writeRetryCnt--;
                }
            }
            return false;
        }
Exemple #25
0
        public DCPRetCodes doRxDCP(int initialTimeout, DCPFrame dcpRxMsg)
        {
            int num2 = 1;
            _messageByteIndex = 0;
            int num3 = 0;
            DataBuffer buf = new DataBuffer(_DCPMaxDataLen)
            {
                NumItems = 0
            };
            _isPacketTimeOut = false;
            tmrPacketTimer = new System.Timers.Timer();
            tmrPacketTimer.Interval = initialTimeout;
            tmrPacketTimer.Elapsed += new ElapsedEventHandler(tmrPacketTimer_Elapsed);
            tmrPacketTimer.Start();
            while (!_isPacketTimeOut && (num2 > 0))
            {
                int num;
                int num5;
                int num6;
                if (_terminateRequested)
                    return DCPRetCodes.DCP_TERMINATED;

                switch (_messageByteIndex)
                {
                    case 0:
                    {
                        num = 0;
                        if (_devInterface != null)
                            num = _devInterface.ReadAppendDevice(buf, 3);
                        if (num < 0)
                        {
                            buf.NumItems = 0;
                            return DCPRetCodes.DCP_FATAL;
                        }
                        if (num == 0)
                            Thread.Sleep(_ThreadSleepTime);
                        else
                        {
                            dcpRxMsg.Len = buf[_messageByteIndex];
                            _messageByteIndex++;
                            if (dcpRxMsg.Len < 2)
                            {
                                dcpRxMsg.Len = 0;
                                return DCPRetCodes.DCP_ERR_EDC;
                            }
                            num = (_devInterface == null)
                                ? 0
                                : _devInterface.ReadAppendDevice(buf, (dcpRxMsg.Len - buf.NumItems) + 1);
                            if (num < 0)
                            {
                                buf.NumItems = 0;
                                return DCPRetCodes.DCP_FATAL;
                            }
                        }
                        continue;
                    }
                    case 1:
                    {
                        if (buf.NumItems < 2)
                            break;
                        dcpRxMsg.Ctrl = buf[_messageByteIndex++];
                        num2 = dcpRxMsg.Len - 1;
                        continue;
                    }
                    case 2:
                        if (buf.NumItems <= 2)
                            continue;
                        num5 = buf.NumItems - 2;
                        num6 = 0;
                        goto Label_025E;

                    default:
                        goto Label_0269;
                }
                num = (_devInterface == null)
                    ? 0
                    : _devInterface.ReadAppendDevice(buf, (dcpRxMsg.Len - buf.NumItems) + 1);
                if (num < 0)
                {
                    buf.NumItems = 0;
                    return DCPRetCodes.DCP_FATAL;
                }
                if (num > 0)
                {
                    dcpRxMsg.Ctrl = buf[_messageByteIndex++];
                    num2 = dcpRxMsg.Len - 1;
                }
                continue;

            Label_0225:
                dcpRxMsg.Data[_messageByteIndex - 2] = buf[_messageByteIndex++];
                num2--;
                num3++;
                num6++;
            Label_025E:
                if (num6 < num5)
                    goto Label_0225;
                continue;

            Label_0269:
                if (_messageByteIndex > 2)
                {
                    num = 0;
                    if (_devInterface != null)
                        num = _devInterface.ReadAppendDevice(buf, (dcpRxMsg.Len - buf.NumItems) + 1);

                    if (num < 0)
                    {
                        buf.NumItems = 0;
                        return DCPRetCodes.DCP_FATAL;
                    }
                    for (int i = 0; i < num; i++)
                    {
                        dcpRxMsg.Data[_messageByteIndex - 2] = buf[_messageByteIndex++];
                        num2--;
                        num3++;
                    }
                }
            }
            if (_isPacketTimeOut)
            {
                _isPacketTimeOut = false;
                return DCPRetCodes.DCP_ERR_TIMEOUT;
            }
            tmrPacketTimer.Stop();
            if (_messageByteIndex > 2)
            {
                _messageByteIndex -= 3;
            }
            else
            {
                return DCPRetCodes.DCP_ERR_EDC;
            }
            dcpRxMsg.EDC = dcpRxMsg.Data[_messageByteIndex];
            dcpRxMsg.Data[_messageByteIndex] = 0;
            byte num4 = (byte) (dcpRxMsg.Len ^ dcpRxMsg.Ctrl);
            _messageByteIndex = 0;
            while (_messageByteIndex < (dcpRxMsg.Len - 2))
            {
                num4 ^= dcpRxMsg.Data[_messageByteIndex];
                _messageByteIndex++;
            }

            if (dcpRxMsg.EDC != num4)
                return DCPRetCodes.DCP_ERR_EDC;

            return DCPRetCodes.DCP_OK;
        }
Exemple #26
0
        private DeviceDescriptor queryDeviceInfo(DeviceHandle handle, DeviceDescriptor devInfo)
        {
            DataBuffer data = new DataBuffer(128);
            int writeRetryCnt = int.Parse(ConfigurationManager.AppSettings["WriteRetryCnt"]);
            int pollDeviceTypeProcDelay = int.Parse(ConfigurationManager.AppSettings["PollDeviceTypeProcDelay"]);
            int readRetryCnt = int.Parse(ConfigurationManager.AppSettings["ReadRetryCnt"]);
            if (handle.isInvalid())
            {
                _log.Error("QueryDeviceInfo() - Called with INVALID argument");
                return devInfo;
            }
            data.copy("\r");
            write(handle, data);
            Thread.Sleep(pollDeviceTypeProcDelay);
            flushRead(handle, data);
            while (writeRetryCnt > 0)
            {
                if (devInfo.BootloaderMode)
                {
                    data.copy("J");
                    _log.Debug("queryDeviceInfo():: 'J'");
                }
                else
                {
                    data.copy("I\r");
                    _log.Debug("queryDeviceInfo():: 'I\r'");
                }
                if (write(handle, data) < 0)
                {
                    _log.Warn("Device was probably disconnected. write() returned with -1");
                    return devInfo;
                }

                Thread.Sleep(pollDeviceTypeProcDelay);
                data.NumItems = 0;
                for (int i = readRetryCnt; i > 0; i--)
                {
                    if (readAppend(handle, data, data.Capacity - data.NumItems) < 0)
                    {
                        _log.Warn("Device was probably disconnected.  readAppend() returned with -1");
                        return devInfo;
                    }
                    if (data.endsWith("OK\n\r>"))
                        break;
                    Thread.Sleep(20);
                }

                string response = data.BufToStr;
                _log.Info("queryDeviceInfo():: response:" + response);
                try
                {
                    if (response.Length < 10)
                        return devInfo;

                    string strTmp = response.Substring(0, 10);
                    if (response.Contains("SRW"))
                    {
                        #region SRW...

                        string[] strArray = response.Remove(0, response.IndexOf("SRW")).Split(new char[] { ',' });
                        string subType = strArray[3].Substring(0, 3).Trim();
                        switch (strArray[0].Trim())
                        {
                            case "SRW001":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SDBC_8);
                                switch (subType)
                                {
                                    case "NW2":
                                        devInfo.FirmwareType = new FirmwareType("ENW_Master");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;

                                    case "PED":
                                        devInfo.FirmwareType = new FirmwareType("PER_Demo");
                                        break;
                                }
                                devInfo.DevicePhoto = SDBC.SDBC_8;
                                devInfo.MarketingName = SDBC.MarketingName;
                                devInfo.UnAssignedDeviceText = SDBC.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = SDBC.SDBC_switch;
                                devInfo.WarningText = SDBC.WarningText;
                                devInfo.PartNumber = SDBC.PartNumber;
                                break;

                            case "SRW002":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SRW002);
                                if (subType != null && subType == "LBF")
                                    devInfo.FirmwareType = new FirmwareType("LBF");
                                devInfo.DevicePhoto = SRW002.SRW002_400;
                                devInfo.MarketingName = SRW002.MarketingName;
                                devInfo.UnAssignedDeviceText = SRW002.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = SRW002.SRW002_400;
                                devInfo.WarningText = SRW002.WarningText;
                                devInfo.PartNumber = SRW002.PartNumber;
                                break;

                            case "SRW003":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.EZLink);
                                switch (subType)
                                {
                                    case "NW1":
                                        devInfo.FirmwareType = new FirmwareType("NWD_Slave");
                                        break;

                                    case "NW2":
                                        devInfo.FirmwareType = new FirmwareType("ENW_Slave");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;

                                    case "ED":
                                        devInfo.FirmwareType = new FirmwareType("EZLink");
                                        break;
                                }
                                devInfo.DevicePhoto = EzLink.EZLink_D_EP;
                                devInfo.MarketingName = EzLink.MarketingName;
                                devInfo.UnAssignedDeviceText = EzLink.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = EzLink.EZLink_switch;
                                devInfo.WarningText = EzLink.WarningText;
                                devInfo.PartNumber = EzLink.PartNumber;
                                break;

                            case "SRW004":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SRW004);
                                switch (subType)
                                {
                                    case "LBL":
                                        devInfo.FirmwareType = new FirmwareType("LoadBoard_Lite");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;
                                }
                                devInfo.DevicePhoto = SRW004.Si1000DK;
                                devInfo.MarketingName = SRW004.MarketingName;
                                devInfo.UnAssignedDeviceText = SRW004.UnAssignedDeviceText;
                                devInfo.WarningText = SRW004.WarningText;
                                devInfo.PartNumber = SRW004.PartNumber;
                                break;

                            case "SRW005":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.EZLink);
                                switch (subType)
                                {
                                    case "NW1":
                                        devInfo.FirmwareType = new FirmwareType("NWD_Slave");
                                        break;

                                    case "NW2":
                                        devInfo.FirmwareType = new FirmwareType("ENW_Slave");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;

                                    case "ED":
                                        devInfo.FirmwareType = new FirmwareType("EZLink");
                                        break;
                                }
                                devInfo.DevicePhoto = EzLink.EZLink_D_EP;
                                devInfo.MarketingName = EzLink.MarketingName;
                                devInfo.UnAssignedDeviceText = EzLink.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = EzLink.EZLink_switch;
                                devInfo.WarningText = EzLink.WarningText;
                                devInfo.PartNumber = EzLink.PartNumber;
                                break;

                            case "SRW007":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SRW007);
                                switch (subType)
                                {
                                    case "RKD":
                                        devInfo.FirmwareType = new FirmwareType("RKE_Master");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;
                                }
                                devInfo.DevicePhoto = SRW007.SRW007_100x84;
                                devInfo.MarketingName = SRW007.MarketingName;
                                devInfo.UnAssignedDeviceText = SRW007.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = SRW007.SRW007_switch;
                                devInfo.WarningText = SRW007.WarningText;
                                devInfo.PartNumber = SRW007.PartNumber;
                                break;

                            case "SRW008":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SRW008);
                                switch (subType)
                                {
                                    case "RKD":
                                        devInfo.FirmwareType = new FirmwareType("RKE_Master");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;
                                }
                                devInfo.DevicePhoto = SRW008.SRW008_100x84;
                                devInfo.MarketingName = SRW008.MarketingName;
                                devInfo.UnAssignedDeviceText = SRW008.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = SRW008.SRW008_switch;
                                devInfo.WarningText = SRW008.WarningText;
                                devInfo.PartNumber = SRW008.PartNumber;
                                break;

                            case "SRW009":
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.SRW009);
                                switch (subType)
                                {
                                    case "RKD":
                                        devInfo.FirmwareType = new FirmwareType("RKE_Master");
                                        break;

                                    case "BLD":
                                        devInfo.FirmwareType = new FirmwareType("Bootloader");
                                        break;
                                }
                                devInfo.DevicePhoto = SRW009.SRW009_100x84;
                                devInfo.MarketingName = SRW009.MarketingName;
                                devInfo.UnAssignedDeviceText = SRW009.UnAssignedDeviceText;
                                devInfo.SwitchPhoto = SRW009.SRW009_switch;
                                devInfo.WarningText = SRW009.WarningText;
                                devInfo.PartNumber = SRW009.PartNumber;
                                break;

                            default:
                                break;
                        }
                        devInfo.DeviceVersion = new DeviceVersion(strArray[1]);
                        devInfo.FirmwareVersion = new FirmwareVersion(strArray[2]);
                        return devInfo;

                        #endregion
                    }

                    if (strTmp.Contains("SDBC-8"))
                    {
                        #region SDBC-8

                        int idx = strTmp.IndexOf("SDBC-8");
                        //	SDBC-8......VVVVV......FFFFF..PED
                        //	SDBC-8......VVVVV......FFFFF..NWD
                        //            dev.version  fw.version

                        devInfo.DeviceType = new DeviceType(DeviceTypeID.SDBC_8);
                        strTmp = response.Substring(idx + 30, 3);
                        if (strTmp == "NWD")
                        {
                            devInfo.DeviceVersion = new DeviceVersion(response.Substring(idx + 12, 5));
                            devInfo.FirmwareType = new FirmwareType("NWD_Master");
                            devInfo.FirmwareVersion = new FirmwareVersion(response.Substring(idx + 23, 5));
                            devInfo.DevicePhoto = SDBC.SDBC_8;
                            devInfo.SwitchPhoto = SDBC.SDBC_switch;
                            devInfo.WarningText = SDBC.WarningText;
                            return devInfo;
                        }
                        if (strTmp == "PED")
                        {
                            devInfo.DeviceVersion = new DeviceVersion(response.Substring(idx + 12, 5));
                            devInfo.FirmwareType = new FirmwareType("PER_Demo");
                            devInfo.FirmwareVersion = new FirmwareVersion(response.Substring(idx + 23, 5));
                            devInfo.DevicePhoto = SDBC.SDBC_8;
                            devInfo.SwitchPhoto = SDBC.SDBC_switch;
                            devInfo.WarningText = SDBC.WarningText;
                            return devInfo;
                        }

                        #endregion
                    }
                    else if (strTmp.Contains("D-EP"))
                    {
                        #region EZLink
                        int idx = strTmp.IndexOf("D-EP");
                        devInfo.DeviceType = new DeviceType(DeviceTypeID.EZLink);
                        if (response.Substring(idx + 27, 3) == "NWD")
                        {
                            strTmp = response.Substring(idx + 9, 5);
                            devInfo.DeviceVersion = new DeviceVersion(strTmp);
                            devInfo.FirmwareType = new FirmwareType("NWD_Slave");
                            strTmp = response.Substring(idx + 20, 5);
                            devInfo.FirmwareVersion = new FirmwareVersion(strTmp);
                            return devInfo;
                        }
                        #endregion
                    }
                    else
                    {
                        if (response.Contains("V1.10W"))
                        {
                            devInfo.DeviceType = new DeviceType(DeviceTypeID.SDBC_8);
                            devInfo.DeviceVersion = new DeviceVersion("01.1r");
                            devInfo.FirmwareType = new FirmwareType("Bootloader");
                            devInfo.FirmwareVersion = new FirmwareVersion("V1.10W");
                            devInfo.DevicePhoto = SDBC.SDBC_8;
                            devInfo.SwitchPhoto = SDBC.SDBC_switch;
                            devInfo.WarningText = SDBC.WarningText;
                            return devInfo;
                        }
                        if (response.Length >= 26)
                        {
                            #region LoadBoard
                            if (response.Substring(4, 26) == "Wireless Development Suite")
                            {
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.LoadBoard);
                                devInfo.DeviceVersion = new DeviceVersion("02.20");
                                devInfo.FirmwareType = new FirmwareType("LoadBoard");
                                devInfo.FirmwareVersion = new FirmwareVersion(response.Substring(0x23, 4));
                                devInfo.DevicePhoto = LoadBoard.HWBoard_LoadBoard;
                                return devInfo;
                            }
                            if (response.Substring(4, 16) == "LoadBoard Loader")
                            {
                                devInfo.DeviceType = new DeviceType(DeviceTypeID.LoadBoard);
                                devInfo.DeviceVersion = new DeviceVersion("02.20");
                                devInfo.FirmwareType = new FirmwareType("BootLoader");
                                devInfo.FirmwareVersion = new FirmwareVersion(response.Substring(0x17, 4));
                                return devInfo;
                            }
                            #endregion
                        }
                    }
                }
                catch (Exception exception)
                {
                    _log.Error("QueryDeviceInfo() - " + exception.Message);
                    return devInfo;
                }
                writeRetryCnt--;
            }
            return devInfo;
        }
Exemple #27
0
 public DCPRetCodes ConstructDCPmsg(DataBuffer a_DataToSend, CommandSet a_cmdset, MessageTypes a_msgtype)
 {
     if (this.Data == null)
     {
         return DCPRetCodes.DCP_FATAL;
     }
     if (!this._seqList.ContainsKey((byte) a_cmdset))
     {
         this._seqList.Add((byte) a_cmdset, 3);
     }
     this.Len = (byte) (((byte) a_DataToSend.NumItems) + 2);
     this.CmdSet = (byte) a_cmdset;
     this.MsgType = (byte) a_msgtype;
     MessageTypes types = a_msgtype;
     if (types <= MessageTypes.ACK)
     {
         switch (types)
         {
             case MessageTypes.Data:
                 this.SeqNum = (byte) (this.SeqNum + 1);
                 break;
         }
     }
     else if ((types != MessageTypes.Nack) && (types == MessageTypes.SynchReqOrIndication))
     {
         this.SeqNum = 0;
     }
     this.Ctrl = (byte) ((this.CmdSet + this.MsgType) + this.SeqNum);
     this.EDC = (byte) (this.Len ^ this.Ctrl);
     for (int i = 0; i < a_DataToSend.NumItems; i++)
     {
         this.Data[i] = a_DataToSend[i];
         this.EDC = (byte) (this.EDC ^ a_DataToSend[i]);
     }
     return DCPRetCodes.DCP_OK;
 }
Exemple #28
0
 private void UpdateControls(DataBuffer slavedata)
 {
     Point location = new Point(0, 0);
     int temp = 0;
     if (slavedata[0] == 0x83)
     {
         if (slavedata[1] == 0)
         {
             this.pnlNode1.Visible = false;
         }
         else
         {
             this.pnlNode1.Visible = true;
             this.lbl_NoNodes.Visible = false;
             if (slavedata[2] != 0)
             {
                 temp = slavedata[2];
                 this.txbN1Temp.Text = this.CalcTemp(temp);
                 this.pnlN1TempBar.Height = (int) (temp * 0.39);
                 location = this.pnlN1TempBar.Location;
                 location.Y = (this.pnlN1TempBase.Location.Y + this.pnlN1TempBase.Height) - this.pnlN1TempBar.Height;
                 this.pnlN1TempBar.Location = location;
                 this.CalcColor(temp);
                 this.pnlN1TempBar.BackColor = Color.FromArgb(this._tColor.red, this._tColor.green, this._tColor.blue);
             }
             if (slavedata[3] != 0xff)
             {
                 this.pnlN1PBEvent.BackColor = this._LedColor_H;
             }
             else
             {
                 this.pnlN1PBEvent.BackColor = this._LedColor_L;
             }
             byte num1 = slavedata[4];
         }
         if (slavedata[5] == 0)
         {
             this.pnlNode2.Visible = false;
         }
         else
         {
             this.pnlNode2.Visible = true;
             this.lbl_NoNodes.Visible = false;
             if (slavedata[6] != 0)
             {
                 temp = slavedata[6];
                 this.txbN2Temp.Text = this.CalcTemp(temp);
                 this.pnlN2TempBar.Height = (int) (temp * 0.39);
                 location = this.pnlN2TempBar.Location;
                 location.Y = (this.pnlN2TempBase.Location.Y + this.pnlN2TempBase.Height) - this.pnlN2TempBar.Height;
                 this.pnlN2TempBar.Location = location;
                 this.CalcColor(temp);
                 this.pnlN2TempBar.BackColor = Color.FromArgb(this._tColor.red, this._tColor.green, this._tColor.blue);
             }
             if (slavedata[7] != 0xff)
             {
                 this.pnlN2PBEvent.BackColor = this._LedColor_H;
             }
             else
             {
                 this.pnlN2PBEvent.BackColor = this._LedColor_L;
             }
             byte num2 = slavedata[8];
         }
         if (slavedata[9] == 0)
         {
             this.pnlNode3.Visible = false;
         }
         else
         {
             this.pnlNode3.Visible = true;
             this.lbl_NoNodes.Visible = false;
             if (slavedata[10] != 0)
             {
                 temp = slavedata[10];
                 this.txbN3Temp.Text = this.CalcTemp(temp);
                 this.pnlN3TempBar.Height = (int) (temp * 0.39);
                 location = this.pnlN3TempBar.Location;
                 location.Y = (this.pnlN3TempBase.Location.Y + this.pnlN3TempBase.Height) - this.pnlN3TempBar.Height;
                 this.pnlN3TempBar.Location = location;
                 this.CalcColor(temp);
                 this.pnlN3TempBar.BackColor = Color.FromArgb(this._tColor.red, this._tColor.green, this._tColor.blue);
             }
             if (slavedata[11] != 0xff)
             {
                 this.pnlN3PBEvent.BackColor = this._LedColor_H;
             }
             else
             {
                 this.pnlN3PBEvent.BackColor = this._LedColor_L;
             }
             byte num3 = slavedata[12];
         }
         if (slavedata[13] == 0)
         {
             this.pnlNode4.Visible = false;
         }
         else
         {
             this.pnlNode4.Visible = true;
             this.lbl_NoNodes.Visible = false;
             if (slavedata[14] != 0)
             {
                 temp = slavedata[14];
                 this.txbN4Temp.Text = this.CalcTemp(temp);
                 this.pnlN4TempBar.Height = (int) (temp * 0.39);
                 location = this.pnlN4TempBar.Location;
                 location.Y = (this.pnlN4TempBase.Location.Y + this.pnlN4TempBase.Height) - this.pnlN4TempBar.Height;
                 this.pnlN4TempBar.Location = location;
                 this.CalcColor(temp);
                 this.pnlN4TempBar.BackColor = Color.FromArgb(this._tColor.red, this._tColor.green, this._tColor.blue);
             }
             if (slavedata[15] != 0xff)
             {
                 this.pnlN4PBEvent.BackColor = this._LedColor_H;
             }
             else
             {
                 this.pnlN4PBEvent.BackColor = this._LedColor_L;
             }
             byte num4 = slavedata[0x10];
         }
         if ((!this.pnlNode1.Visible && !this.pnlNode2.Visible) && (!this.pnlNode3.Visible && !this.pnlNode4.Visible))
         {
             this.lbl_NoNodes.Visible = true;
         }
     }
 }
Exemple #29
0
 public int write(DeviceHandle handle, DataBuffer data)
 {
     if (handle == null || handle.isInvalid())
     {
         _log.Warn("Called with INVALID handle");
         return -1;
     }
     try
     {
         handle.RS232hnd.hnd.Write(data.Buf, 0, data.NumItems);
     }
     catch (Exception exception)
     {
         _log.Error("write() - " + exception.Message);
         return -1;
     }
     return 0;
 }
Exemple #30
0
 public NodeDescriptor(int index, DataBuffer a_buf)
 {
     _address = (byte) (a_buf[index + 1] & 7);
     _temperature = (a_buf[index + 11] * 0x100) + a_buf[index + 12];
     _analog = (a_buf[index + 9] * 0x100) + a_buf[index + 10];
     _humidity = a_buf[10];
     _battery = a_buf[index + 13];
     _button = a_buf[index + 14];
 }