Example #1
0
 public IOPH_DATA(ADTRecord adtRec, IAppMainWindow mainWin)
 {
     _adtRec = adtRec;
     _mainWin = mainWin;
     _teleToWin = new Telegram(GlobalServices.maxReplyDataLen);
     _teleFromWin = new Telegram(GlobalServices.maxReplyDataLen);
 }
Example #2
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();
 }
Example #3
0
 public int telegramFromPortHandler(Telegram recTelegram)
 {
     TelegramTools.copyTelegram(recTelegram, ref this._savedTelegram);
     this._isDeviceBusy = false;
     if ((this._savedTelegram.type != TelegramType.PortHandlerTerminated) &&
         this._savedTelegram.FireCallback())
     {
         return 0;
     }
     return this.DefaultTelegramFromPortHandler(this._savedTelegram);
 }
Example #4
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 #5
0
 public static void copyTelegram(Telegram srcTele, ref Telegram dstTele)
 {
     if (srcTele != null)
     {
         dstTele = new Telegram(100);
         if (dstTele.copy(srcTele) == -1)
         {
             int numItems = srcTele.data.NumItems;
             dstTele = new Telegram((numItems < 0x3e8) ? (numItems * 5) : (numItems * 2));
             if (dstTele.copy(srcTele) == -1)
             {
                 GlobalServices.ErrMsg("TelegramTools.copyTelegram()", "FATAL ERROR: erroneous telegram copy implementation, exit WDS!");
                 Application.Exit();
             }
         }
     }
 }
Example #6
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();
 }
Example #7
0
 private void processRegisterIO(Telegram replyTele)
 {
     try
     {
         bool flag = false;
         if (replyTele.type == TelegramType.SeriesEndOK)
         {
             statusBarPanel4.Reset();
             showLocalLog("\n");
             if (tsrMainToolStrip.IsContCurrentReadOn)
             {
                 base.BeginInvoke(new EventHandler(tsrMainToolStrip_AmmeteringRequested), new object[2]);
             }
         }
         else
         {
             if ((((replyTele.type == TelegramType.PacketRecOK) && (replyTele.data.NumItems > 0)) && ((replyTele.data.Buf[0] == 0x11) && replyTele.UserDataExt.hasStoredValue("RegId"))) && (replyTele.data.NumItems >= 4))
             {
                 if (replyTele.data.Buf[1] != 0)
                 {
                     showLocalLog("< Reading returned with error code: " + replyTele.data.Buf[1].ToString());
                     return;
                 }
                 int registerIdx = (int) replyTele.UserDataExt["RegId"];
                 if (replyTele.UserDataExt.hasStoredValue("IsRead") && ((bool) replyTele.UserDataExt["IsRead"]))
                 {
                     _myDev.Registers[registerIdx].DeviceValue = _myDev.Registers[registerIdx].CurrentValue = replyTele.data.Buf[3];
                     repaintRegisterRowColors(registerIdx);
                     flag = true;
                 }
                 else
                 {
                     _myDev.Registers[registerIdx].DeviceValue = _myDev.Registers[registerIdx].CurrentValue;
                     repaintRegisterRowColors(registerIdx);
                     flag = true;
                 }
                 if (replyTele.UserDataExt.hasStoredValue("SentData"))
                 {
                     showLocalLog(((string) replyTele.UserDataExt["SentData"]) + "\n");
                     showLocalLog("< " + WDSConverters.ToHexString(replyTele.data.Buf, replyTele.data.NumItems) + "\n");
                     statusBarPanel4.Step();
                 }
             }
             if (!flag)
             {
                 showLocalLog("Unexpected packet received! The packet could not be procesed! " + replyTele.UserDataExt["RegId"].ToString());
                 _log.Error("Unexpected packet received! The packet could not be procesed!");
             }
         }
     }
     catch (Exception exception)
     {
         _log.Error("Register IO processing problem! " + exception.Message);
     }
 }
Example #8
0
 private void processReadCurrentReplyTelegram(Telegram replyTele)
 {
     if ((replyTele.type == TelegramType.DeviceFailure) && replyTele.UserDataExt.hasStoredValue("SentData"))
     {
         showLocalLog(((string) replyTele.UserDataExt["SentData"]) + "\n");
         showLocalLog("< " + ((TelegramType) replyTele.type).ToString() + "\n");
         statusBarPanel4.Step();
     }
     else if (replyTele.type == TelegramType.SeriesEndOK)
     {
         statusBarPanel4.Reset();
         showLocalLog("\n");
     }
     else
     {
         double num;
         byte[] buffer;
         if ((replyTele.data.NumItems > 0) && (replyTele.data[0] == 0x20))
         {
             if (replyTele.UserDataExt.hasStoredValue("SentData"))
             {
                 showLocalLog(((string) replyTele.UserDataExt["SentData"]) + "\n");
                 showLocalLog("< " + WDSConverters.ToHexString(replyTele.data.Buf, replyTele.data.NumItems) + "\n");
                 statusBarPanel4.Step();
             }
             buffer = new byte[4];
             Array.ConstrainedCopy(replyTele.data.Buf, 3, buffer, 0, 4);
             Array.Reverse(buffer, 0, 4);
             num = BitConverter.ToUInt32(buffer, 0);
             num /= 1000000.0;
         }
         else
         {
             buffer = new byte[replyTele.data.Capacity];
             replyTele.data.Buf.CopyTo(buffer, 0);
             Array.Reverse(buffer, 1, 2);
             num = BitConverter.ToUInt16(buffer, 1);
             num = (num * 31.25) / 20000000.0;
         }
         if (num >= 0.001)
         {
             num *= 1000.0;
             tsrMainToolStrip.setCurrentText(num.ToString("###.###") + " mA");
         }
         else
         {
             tsrMainToolStrip.setCurrentText(((num * 1000000.0)).ToString("###.###") + " \x00b5A");
         }
     }
 }
Example #9
0
        private void ProcessReceivedTelegram(Telegram command, Telegram reply)
        {
            try
            {
                switch (_task_id)
                {
                    case Task.None:
                    case Task.ACK:
                    case Task.NACK:
                    case Task.SetVoltage:
                    case Task.ReadCurrent:
                    case Task.Reset:
                    case Task.IdentifyStart:
                    case Task.IdentifyStop:
                    case Task.SingleRegisterIO:
                        return;

                    case Task.MultipleRegisterIO:
                        if (reply.type == TelegramType.DataAcknowledgeOK)
                        {
                            if (isWriteCommand(command))
                            {
                                break;
                            }
                            _myDev.Registers[reply.userData].CurrentValue = getDeviceData(command, reply);
                            _myDev.Registers[reply.userData].DeviceValue = getDeviceData(command, reply);
                            if (!_isSeries)
                            {
                                repaintRegisterRowColors(reply.userData);
                            }
                        }
                        goto Label_014F;

                    case Task.Batch1:
                        statusBarPanel4.Step();
                        if (chbLoopB1.Checked)
                        {
                            _telegramSeriesReplyConuter++;
                            if (_series.ItemNum <= _telegramSeriesReplyConuter)
                            {
                                _telegramSeriesReplyConuter = 0;
                                int num = Convert.ToInt32(txbLoopCount.Text) + 1;
                                txbLoopCount.Text = num.ToString();
                                myFormStatus.LoopNum = num.ToString();
                            }
                        }
                        return;

                    case Task.Batch2:
                        statusBarPanel4.Step();
                        if (chbLoopB2.Checked)
                        {
                            _telegramSeriesReplyConuter++;
                            if (_series.ItemNum <= _telegramSeriesReplyConuter)
                            {
                                _telegramSeriesReplyConuter = 0;
                                int num2 = Convert.ToInt32(txbLoopCount.Text) + 1;
                                txbLoopCount.Text = num2.ToString();
                                myFormStatus.LoopNum = num2.ToString();
                            }
                        }
                        return;

                    case Task.Batch3:
                        statusBarPanel4.Step();
                        if (chbLoopB3.Checked)
                        {
                            _telegramSeriesReplyConuter++;
                            if (_series.ItemNum <= _telegramSeriesReplyConuter)
                            {
                                _telegramSeriesReplyConuter = 0;
                                int num3 = Convert.ToInt32(txbLoopCount.Text) + 1;
                                txbLoopCount.Text = num3.ToString();
                                myFormStatus.LoopNum = num3.ToString();
                            }
                        }
                        return;

                    case Task.Batch4:
                        statusBarPanel4.Step();
                        if (chbLoopB4.Checked)
                        {
                            _telegramSeriesReplyConuter++;
                            if (_series.ItemNum <= _telegramSeriesReplyConuter)
                            {
                                _telegramSeriesReplyConuter = 0;
                                int num4 = Convert.ToInt32(txbLoopCount.Text) + 1;
                                txbLoopCount.Text = num4.ToString();
                                myFormStatus.LoopNum = num4.ToString();
                            }
                        }
                        return;

                    case Task.FIFOWrite:
                        statusBarPanel4.Step();
                        return;

                    case Task.FIFORead:
                    {
                        if (reply.userData == -1)
                        {
                            return;
                        }
                        string str = ((char) reply.data[reply.data.NumItems - 10]).ToString();
                        string str2 = ((char) reply.data[reply.data.NumItems - 9]).ToString();
                        string str3 = str + str2;
                        myFifoReadWrite.RxArray[reply.userData].H = str3;
                        dgvRX.Rows[reply.userData].Cells[1].Value = str3;
                        if (!(myFifoReadWrite.RxArray[reply.userData].Xpd != ""))
                        {
                            goto Label_03BA;
                        }
                        if (!(myFifoReadWrite.RxArray[reply.userData].H != myFifoReadWrite.RxArray[reply.userData].Xpd))
                        {
                            goto Label_0324;
                        }
                        dgvRX.Rows[reply.userData].Cells[3].Style.BackColor = Color.Red;
                        dgvRX.Rows[reply.userData].Cells[3].Style.SelectionBackColor = Color.Red;
                        dgvRX.Rows[reply.userData].Cells[3].Value = "1";
                        goto Label_0450;
                    }
                    default:
                        return;
                }
                if (_isSeries)
                {
                    _myDev.Registers[reply.userData].DeviceValue = getDeviceData(_series.findTelegram(reply.parentUniqId), reply);
                }
                else
                {
                    _myDev.Registers[reply.userData].DeviceValue = getDeviceData(command, reply);
                }
                calculateHexValueInGridLine(myDevIndexer.ListToView(reply.userData));
            Label_014F:
                if (_isSeries)
                {
                    statusBarPanel4.Step();
                }
                else
                {
                    _task_id = Task.None;
                }
                return;
            Label_0324:
                dgvRX.Rows[reply.userData].Cells[3].Style.BackColor = Color.LightGreen;
                dgvRX.Rows[reply.userData].Cells[3].Style.SelectionBackColor = Color.LightGreen;
                dgvRX.Rows[reply.userData].Cells[3].Value = "0";
                goto Label_0450;
            Label_03BA:
                dgvRX.Rows[reply.userData].Cells[3].Style.BackColor = Color.White;
                dgvRX.Rows[reply.userData].Cells[3].Style.SelectionBackColor = Color.FromName("HIGHLIGHT");
                dgvRX.Rows[reply.userData].Cells[3].Value = "";
            Label_0450:
                statusBarPanel4.Step();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Error at ProcessRecivedTelegram()!\n" + exception.Message);
            }
        }
Example #10
0
 private int send_Script(List<string> commandSet, int delay, string commandName)
 {
     try
     {
         this._series.clear();
         for (int i = 0; i < commandSet.Count; i++)
         {
             this._tele = new Telegram(commandSet[i].Length);
             this._tele.uniqId = GlobalServices.uniqTelegramId();
             this._tele.parentUniqId = -1;
             this._tele.type = TelegramType.Command;
             this._tele.protocol = Protocol.WriteRead;
             string reply = null;
             this._tele.replySize = GlobalServices.calculateExpextedReplyLen(commandSet[i], ref reply);
             if (this._tele.replySize == -1)
             {
                 throw new Exception("Not supported command.");
             }
             this._tele.data.copy(commandSet[i]);
             this._tele.userData = -1;
             this._tele.portHandler = this._ioph;
             this._tele.mainWin = this;
             this._series.addTelegram(this._tele);
         }
         if (delay > 0)
         {
             this._series.addDelay(delay);
         }
         if (this._series.ItemNum == 0)
         {
             return 0;
         }
         if (this._ioph.telegramSeriesFromMainWin(this._series, SeriesExecutionState.Run, true) == 0)
         {
             this._isDeviceBusy = true;
             this.lockDeviceButtons(ExceptedBtn.None);
             GlobalServices.LogMsg(this._appId, commandName + " Series started");
             return 0;
         }
         GlobalServices.ErrMsg(this._appId, commandName + "error at sending user scripts to the Device!");
         return -1;
     }
     catch (Exception exception)
     {
         GlobalServices.ErrMsg(this._appId, "Error at sending " + commandName + " Commands!\n" + exception.Message);
         GlobalServices.msgBox("Error at sending " + commandName + " Commands!\n" + exception.Message, "Error!");
         return -1;
     }
 }
Example #11
0
 private void processFIFOReadIO(Telegram replyTele)
 {
     try
     {
         if ((replyTele.type == TelegramType.DeviceFailure) && replyTele.UserDataExt.hasStoredValue("SentData"))
         {
             showLocalLog(((string) replyTele.UserDataExt["SentData"]) + "\n");
             showLocalLog("< " + ((TelegramType) replyTele.type).ToString() + "\n");
             statusBarPanel4.Step();
         }
         else if (replyTele.type == TelegramType.SeriesEndOK)
         {
             statusBarPanel4.Reset();
             showLocalLog("\n");
             if (tsrMainToolStrip.IsContCurrentReadOn)
             {
                 base.BeginInvoke(new EventHandler(tsrMainToolStrip_AmmeteringRequested), new object[2]);
             }
         }
         else
         {
             int num = 0;
             int num2 = 0;
             int num3 = 0;
             for (int i = 0; i < _myDev.RxPufferSize; i++)
             {
                 byte num5;
                 if ((i + 2) < replyTele.data.NumItems)
                 {
                     byte num4 = replyTele.data[i + 2];
                     num++;
                     dgvRX.Rows[i].Cells[1].Value = num4.ToString("X2");
                     if (byte.TryParse(dgvRX.Rows[i].Cells[2].Value.ToString(), NumberStyles.HexNumber, (IFormatProvider) null, out num5) && (num4 != num5))
                     {
                         num2++;
                         byte num7 = 0x80;
                         int num8 = 0;
                         while (num8 < 8)
                         {
                             if (((num4 ^ num5) & num7) != 0)
                             {
                                 num3++;
                             }
                             num8++;
                             num7 = (byte) (num7 >> 1);
                         }
                     }
                 }
                 else
                 {
                     dgvRX.Rows[i].Cells[1].Value = string.Empty;
                     if (byte.TryParse(dgvRX.Rows[i].Cells[2].Value.ToString(), NumberStyles.HexNumber, (IFormatProvider) null, out num5))
                     {
                         num2++;
                         num3 += 8;
                     }
                 }
             }
             txbPackets.Text = num.ToString();
             txbLost.Text = num2.ToString();
             txbPER.Text = Math.Round((double) (((double) num2) / ((double) num)), 4).ToString();
             txbDatabits.Text = (num * 8).ToString();
             txbBitErrors.Text = num3.ToString();
             txbBER.Text = Math.Round((double) (((double) num3) / ((double) (num * 8))), 4).ToString();
             if (replyTele.UserDataExt.hasStoredValue("SentData"))
             {
                 showLocalLog(((string) replyTele.UserDataExt["SentData"]) + "\n");
                 showLocalLog("< " + WDSConverters.ToHexString(replyTele.data.Buf, replyTele.data.NumItems) + "\n");
                 statusBarPanel4.Step();
             }
         }
     }
     catch (Exception exception)
     {
         _log.Error("FIFO read IO processing problem! " + exception.Message);
     }
 }
Example #12
0
 private int send_Nack()
 {
     try
     {
         Telegram telegram = new Telegram(0) {
             uniqId = GlobalServices.uniqTelegramId(),
             parentUniqId = -1,
             type = TelegramType.Command,
             lastReplyPrecondition = _lastReplyPec,
             protocol = Protocol.DCP,
             DCPCmdSet = 0,
             DCPMsgType = 0x80,
             replySize = 0x19
         };
         if (telegram.replySize == -1)
         {
             throw new Exception("Not supported command.");
         }
         telegram.userData = 2;
         telegram.portHandler = _mainWin._ioph;
         telegram.mainWin = _mainWin;
         _mainWin.showLocalLog("> NACK\n");
         if (_mainWin._ioph.telegramFromMainWin(telegram) == 0)
         {
             return 0;
         }
         return -1;
     }
     catch (Exception exception)
     {
         AppWin_SPITool_PRO._log.Error(exception.Message);
         return -1;
     }
 }
Example #13
0
        public int oldTelegramFromPortHandler(Telegram telegram)
        {
            if (telegram.type == TelegramType.Command)
            {
                _closeCtrl.portHandlerClosed(telegram.portHandler);
                return 0;
            }
            if (telegram.type == TelegramType.DeviceFailure)
            {
                GlobalServices.ErrMsg(_appId, "telegramFromPortHandler(): DeviceFailure received");
                _ioph.controlSeriesExecution(SeriesExecutionState.Stop);
                statusBarPanel4.Reset();
                sbDeviceStatePane.Text = "Status: DeviceFailure";
                return -1;
            }
            if (_isSeries)
            {
                string str = "";
                if (_series.findTelegram(telegram.parentUniqId) != null)
                {
                    str = _series.findTelegram(telegram.parentUniqId).data.objectInfo(false);
                }
                GlobalServices.LogMsg(_appId, str + telegram.data.objectInfo(false));
            }
            else
            {
                GlobalServices.LogMsg(_appId, "|--->\n\tWindow->Device:   " + _tele.data.objectInfo(false) + "\n\tWindow<-Device:   " + telegram.data.objectInfo(false));
            }
            switch (telegram.type)
            {
                case TelegramType.AcknowledgeOK:
                    showLocalLog(telegram.data.objectInfo(false) + "\n");
                    break;

                case TelegramType.AcknowledgeERROR:
                    showLocalLog(telegram.data.objectInfo(false) + "\n");
                    break;

                case TelegramType.DataAcknowledgeOK:
                    showLocalLog(telegram.data.objectInfo(false) + "\n");
                    break;

                case TelegramType.DataAcknowledgeERROR:
                    showLocalLog(telegram.data.objectInfo(false));
                    break;

                case TelegramType.SeriesEndOK:
                    GlobalServices.LogMsg(_appId, "<--- Series finished");
                    break;

                case TelegramType.SeriesEndERROR:
                    GlobalServices.LogMsg(_appId, "<--- Series finished with SeriesEndERROR");
                    break;

                case TelegramType.DeviceFailure:
                    showLocalLog("DeviceFailure telegram type received: " + ((TelegramType) telegram.type).ToString());
                    break;

                default:
                    showLocalLog("Unexpected telegram type received: " + ((TelegramType) telegram.type).ToString());
                    break;
            }
            if ((telegram.type != TelegramType.SeriesEndOK) && (telegram.type != TelegramType.SeriesEndERROR))
            {
                ProcessReceivedTelegram(_tele, telegram);
            }
            else
            {
                base._isDeviceBusy = false;
                statusBarPanel4.Reset();
                if (telegram.type != TelegramType.SeriesEndOK)
                {
                    statusBarPanel4.Reset();
                    ButtonLock(false);
                    sbDeviceStatePane.Text = "Status: SeriesEnd Error";
                }
                else
                {
                    ButtonLock(false);
                    switch (_task_id)
                    {
                        case Task.SetVoltage:
                            _task_id = Task.None;
                            if (!_isReadCurrentOnChange)
                            {
                                tsrMainToolStrip.setCurrentText("? \x00b5A");
                            }
                            break;

                        case Task.Reset:
                            if (!_isReadCurrentOnChange)
                            {
                                tsrMainToolStrip.setCurrentText("? \x00b5A");
                            }
                            break;

                        case Task.SingleRegisterIO:
                            if (!_isReadCurrentOnChange)
                            {
                                tsrMainToolStrip.setCurrentText("? \x00b5A");
                            }
                            break;

                        case Task.MultipleRegisterIO:
                            RegisterDGVACC = _myDev;
                            if (!_isReadCurrentOnChange)
                            {
                                tsrMainToolStrip.setCurrentText("? \x00b5A");
                            }
                            break;

                        case Task.Batch1:
                        case Task.Batch2:
                        case Task.Batch3:
                        case Task.Batch4:
                            tsrMainToolStrip.setCurrentText("? \x00b5A");
                            break;

                        case Task.FIFORead:
                        {
                            myFifoReadWrite.Packets++;
                            bool flag = false;
                            for (int i = 0; i < myFifoReadWrite.RxArray.Length; i++)
                            {
                                if (myFifoReadWrite.RxArray[i].H != "")
                                {
                                    myFifoReadWrite.Databits += 8;
                                    if (myFifoReadWrite.RxArray[i].Xpd != "")
                                    {
                                        if (!flag && (myFifoReadWrite.RxArray[i].H != myFifoReadWrite.RxArray[i].Xpd))
                                        {
                                            myFifoReadWrite.Lost++;
                                            flag = true;
                                        }
                                        int variable = Convert.ToInt32(myFifoReadWrite.RxArray[i].H, 0x10);
                                        int num3 = Convert.ToInt32(myFifoReadWrite.RxArray[i].Xpd, 0x10);
                                        for (int j = 0; j < 8; j++)
                                        {
                                            if (SPI_tools.isIndexedBitSet(variable, j) != SPI_tools.isIndexedBitSet(num3, j))
                                            {
                                                myFifoReadWrite.BitError++;
                                            }
                                        }
                                    }
                                }
                            }
                            myFifoReadWrite.Per = ((double) myFifoReadWrite.Lost) / ((double) myFifoReadWrite.Packets);
                            myFifoReadWrite.Per = Math.Round(myFifoReadWrite.Per, 4);
                            myFifoReadWrite.Ber = ((double) myFifoReadWrite.BitError) / ((double) myFifoReadWrite.Databits);
                            myFifoReadWrite.Ber = Math.Round(myFifoReadWrite.Ber, 4);
                            break;
                        }
                    }
                }
            }
            return 0;
        }
Example #14
0
 private void tsrMainToolStrip_ResetRequested(object sender, EventArgs e)
 {
     if ((DialogResult.Yes == MessageBox.Show("Chip configuration will be changed to the POR values!\nDo you want to proceed?", "Warning!", MessageBoxButtons.YesNo)) && !this._isDeviceBusy)
     {
         string command = "S2";
         command = (command + "FE") + "00" + "\r";
         this._task_id = Task.SWReset;
         try
         {
             this._series.clear();
             string reply = null;
             this._tele = new Telegram(command.Length);
             this._tele.uniqId = GlobalServices.uniqTelegramId();
             this._tele.parentUniqId = -1;
             this._tele.type = TelegramType.Command;
             this._tele.protocol = Protocol.WriteRead;
             this._tele.replySize = GlobalServices.calculateExpextedReplyLen(command, ref reply);
             if (this._tele.replySize == -1)
             {
                 throw new Exception("Not supported command.");
             }
             this._tele.data.copy(command);
             this._tele.userData = 2;
             this._tele.portHandler = this._ioph;
             this._tele.mainWin = this;
             this._series.addTelegram(this._tele);
             if (this._ioph.telegramSeriesFromMainWin(this._series, SeriesExecutionState.Run, true) == 0)
             {
                 this._isDeviceBusy = true;
                 this.lockDeviceButtons(ExceptedBtn.None);
                 GlobalServices.LogMsg(this._appId, "SWReset Series started");
             }
             else
             {
                 GlobalServices.ErrMsg("IO operation failed", "SW Reset");
             }
         }
         catch (Exception exception)
         {
             GlobalServices.ErrMsg(this._appId, "Error at sending Set Voltage Command!\n" + exception.Message);
             GlobalServices.msgBox("Error at sending Set Voltage Command!\n" + exception.Message, "Error!");
         }
     }
 }
Example #15
0
        public int telegramFromPortHandler(Telegram telegram)
        {
            switch (telegram.type)
            {
                case TelegramType.AcknowledgeOK:
                    switch (telegram.protocol)
                    {
                        case Protocol.Write:
                            this.lsbRegisterLog.Items.Insert(0, "Transmit OK");
                            goto Label_02C4;

                        case Protocol.WriteRegister:
                            this.lsbRegisterLog.Items.Insert(0, "Write Register OK: address=" + this._regAddr.ToString("X") + " value=" + this._regVal.ToString("X"));
                            goto Label_02C4;
                    }
                    GlobalServices.ErrMsg("AppWin_EZLinkTest.telegramFromPortHandler", "Unexpected protocol in handling AcknowledgeOK");
                    return -1;

                case TelegramType.AcknowledgeERROR:
                case TelegramType.DataAcknowledgeERROR:
                case TelegramType.DeviceFailure:
                    GlobalServices.ErrMsg("AppWin_EZLinkTest.telegramFromPortHandler", "ERROR status received:  type: " + ((TelegramType) telegram.type).ToString() + "   protocol: " + telegram.protocol.ToString() + "   error code: " + ((int) telegram.userData).ToString("X"));
                    this.chbAutoTxmt.Checked = false;
                    this.chbRxOnIdle.Checked = false;
                    return -1;

                case TelegramType.DataAcknowledgeOK:
                    string str;
                    switch (telegram.protocol)
                    {
                        case Protocol.ReadRegister:
                            uint num;
                            uint num2;
                            telegram.data.appWin_getReply_ReadRegister(out num, out num2);
                            this.lsbRegisterLog.Items.Insert(0, "Read Register OK: Address=" + num.ToString("X") + "   data=" + num2.ToString("X"));
                            goto Label_02C4;

                        case Protocol.ReadStatus:
                            telegram.data.appWin_getReply_ReadStatus(out str);
                            this.lsbRegisterLog.Items.Insert(0, "Read Status OK: " + str);
                            goto Label_02C4;

                        case Protocol.Read:
                            telegram.data.appWin_getReply_Receive(out str);
                            this.lsbMessageLog.Items.Insert(0, "Receive OK: " + str);
                            goto Label_02C4;
                    }
                    GlobalServices.ErrMsg("AppWin_EZLinkTest.telegramFromPortHandler", "Unexpected protocol in handling DataAcknowledgeOK");
                    return -1;

                case TelegramType.SeriesEndOK:
                    this.lsbRegisterLog.Items.Insert(0, "Series terminated with OK");
                    break;

                case TelegramType.SeriesEndERROR:
                    this.lsbRegisterLog.Items.Insert(0, "Series terminated with ERROR");
                    break;

                case TelegramType.PortHandlerTerminated:
                    this._closeCtrl.portHandlerClosed(telegram.portHandler);
                    return 0;

                default:
                    GlobalServices.ErrMsg("AppWin_EZLinkTest.telegramFromPortHandler", "Unexpected telegram type received:  type: " + ((TelegramType) telegram.type).ToString() + "   protocol: " + telegram.protocol.ToString());
                    return -1;
            }
            Label_02C4:
            return 0;
        }
Example #16
0
 private int send_StopReceiveCommand()
 {
     try
     {
         if (!this._isDeviceBusy)
         {
             byte num;
             if (this.fifo_chbDisSensRes.Checked)
             {
                 num = 1;
             }
             else
             {
                 num = 0;
             }
             string str = ((byte) (0x80 | num)).ToString("X");
             str = "S2CA" + str + "\r";
             string[] strArray = new string[] { "F0\r", str };
             this._series.clear();
             for (int i = 0; i < strArray.Length; i++)
             {
                 this._tele = new Telegram(strArray[i].Length);
                 this._tele.uniqId = GlobalServices.uniqTelegramId();
                 this._tele.parentUniqId = -1;
                 this._tele.type = TelegramType.Command;
                 this._tele.protocol = Protocol.WriteRead;
                 string reply = null;
                 this._tele.replySize = GlobalServices.calculateExpextedReplyLen(strArray[i], ref reply);
                 if (this._tele.replySize == -1)
                 {
                     throw new Exception("Not supported command.");
                 }
                 this._tele.data.copy(strArray[i]);
                 this._tele.userData = -1;
                 this._tele.portHandler = this._ioph;
                 this._tele.mainWin = this;
                 this._series.addTelegram(this._tele);
             }
             if (this._ioph.telegramSeriesFromMainWin(this._series, SeriesExecutionState.Run, true) == 0)
             {
                 this._isDeviceBusy = true;
                 GlobalServices.LogMsg(this._appId, "STOP RECEIVE Series started");
                 return 0;
             }
             return -1;
         }
         return -2;
     }
     catch (Exception exception)
     {
         GlobalServices.ErrMsg(this._appId, "Error at sending Stop Receive Commands!\n" + exception.Message);
         GlobalServices.msgBox("Error at sending Stop Receive Commands!\n" + exception.Message, "Error!");
         return -1;
     }
 }
Example #17
0
 private int send_UpdateCommand()
 {
     try
     {
         if (!this._isDeviceBusy)
         {
             bool flag = this.cfgSet_chbEnTxLatch.Checked || this.cfgSet_chbEnRxFIFO.Checked;
             this._series.clear();
             string[] strArray = new string[] { "S2" + this._cfgSettingCommand + "\r", flag ? "H3\r" : "Z3\r", "S2" + this._freqSettingCommand + "\r", "S2" + this._powerManCommand + "\r", "S2" + this._recSettingCommand + "\r", "S2" + this._transSettingCommand + "\r", "S2" + this._wakeUpTimerCommand + "\r", "S2" + this._lowDutyCycleCommand + "\r", "S2" + this._lowBattDetCommand + "\r", "S2" + this._afcCommand + "\r", "S2" + this._dataRateCommand + "\r", "S2" + this._dataFilterCommand + "\r", "S2" + this._fifoCommand + "\r" };
             for (int i = 0; i < strArray.Length; i++)
             {
                 this._tele = new Telegram(strArray[i].Length);
                 this._tele.uniqId = GlobalServices.uniqTelegramId();
                 this._tele.parentUniqId = -1;
                 this._tele.type = TelegramType.Command;
                 if (i == 1)
                 {
                     this._tele.protocol = Protocol.Write;
                     this._tele.replySize = 0;
                 }
                 else
                 {
                     this._tele.protocol = Protocol.WriteRead;
                     string reply = null;
                     this._tele.replySize = GlobalServices.calculateExpextedReplyLen(strArray[i], ref reply);
                     if (this._tele.replySize == -1)
                     {
                         throw new Exception("Not supported command.");
                     }
                 }
                 this._tele.data.copy(strArray[i]);
                 this._tele.userData = -1;
                 this._tele.portHandler = this._ioph;
                 this._tele.mainWin = this;
                 this._series.addTelegram(this._tele);
             }
             if (this._ioph.telegramSeriesFromMainWin(this._series, SeriesExecutionState.Run, true) == 0)
             {
                 this._isDeviceBusy = true;
                 GlobalServices.LogMsg(this._appId, "UPDATE Series started");
                 this.lockDeviceButtons(ExceptedBtn.None);
                 return 0;
             }
             return -1;
         }
         return -2;
     }
     catch (Exception exception)
     {
         GlobalServices.ErrMsg(this._appId, "Error at sending Update Commands!\n" + exception.Message);
         GlobalServices.msgBox("Error at sending Update Commands!\n" + exception.Message, "Error!");
         return -1;
     }
 }
Example #18
0
 private int send_StopContTransmitCommand()
 {
     try
     {
         string command = "T0\r";
         this._series.clear();
         string reply = null;
         this._tele = new Telegram(command.Length);
         this._tele.uniqId = GlobalServices.uniqTelegramId();
         this._tele.parentUniqId = -1;
         this._tele.type = TelegramType.Command;
         this._tele.protocol = Protocol.WriteRead;
         this._tele.portHandler = this._ioph;
         this._tele.userData = -1;
         this._tele.data.NumItems = command.Length;
         for (int i = 0; i < this._tele.data.NumItems; i++)
         {
             this._tele.data[i] = (byte) command[i];
         }
         this._tele.replySize = GlobalServices.calculateExpextedReplyLen(command, ref reply);
         this._tele.mainWin = this;
         this._series.addTelegram(this._tele);
         if (this._ioph.telegramSeriesFromMainWin(this._series, SeriesExecutionState.Run, true) == 0)
         {
             this._isDeviceBusy = true;
             this.lockDeviceButtons(ExceptedBtn.None);
             GlobalServices.LogMsg(this._appId, "STOP CONTINUOUS TRANSMIT Series started");
             return 0;
         }
         return -1;
     }
     catch (Exception exception)
     {
         GlobalServices.ErrMsg(this._appId, "Error at sending Stop Continuous Transmit Command!\n" + exception.Message);
         GlobalServices.msgBox("Error at sending Stop Continuous Transmit Command!\n" + exception.Message, "Error!");
         return -1;
     }
 }
Example #19
0
 private int send_SetVoltageCommand(double voltage)
 {
     try
     {
         if (!this._isDeviceBusy)
         {
             string str;
             this._series.clear();
             if (this._loadBoardRev == 1)
             {
                 str = "V" + Convert.ToInt32((double) (255.0 - (311.0 / voltage))).ToString("X") + "\r";
             }
             else
             {
                 if (this._loadBoardRev != 2)
                 {
                     throw new Exception("Not supported Loadboard type: " + this._loadBoardRev.ToString());
                 }
                 str = "V" + Convert.ToInt32((double) (255.0 - (309.0 / voltage))).ToString("X") + "\r";
             }
             string reply = null;
             this._tele = new Telegram(str.Length);
             this._tele.uniqId = GlobalServices.uniqTelegramId();
             this._tele.parentUniqId = -1;
             this._tele.type = TelegramType.Command;
             this._tele.protocol = Protocol.WriteRead;
             this._tele.replySize = GlobalServices.calculateExpextedReplyLen(str, ref reply);
             if (this._tele.replySize == -1)
             {
                 throw new Exception("Not supported command.");
             }
             this._tele.data.copy(str);
             this._tele.userData = 5;
             this._tele.portHandler = this._ioph;
             this._tele.mainWin = this;
             this._series.addTelegram(this._tele);
             if (this._ioph.telegramSeriesFromMainWin(this._series, SeriesExecutionState.Run, true) == 0)
             {
                 this._isDeviceBusy = true;
                 this._sentVoltage = voltage;
                 this.lockDeviceButtons(ExceptedBtn.None);
                 GlobalServices.LogMsg(this._appId, "SET VOLTAGE Series started");
                 return 0;
             }
             return -1;
         }
         return -2;
     }
     catch (Exception exception)
     {
         GlobalServices.ErrMsg(this._appId, "Error at sending Set Voltage Command!\n" + exception.Message);
         GlobalServices.msgBox("Error at sending Set Voltage Command!\n" + exception.Message, "Error!");
         return -1;
     }
 }
Example #20
0
        private int send_SetLoadboardLed(LBLEDMode mode)
        {
            try
            {
                if (!this._isDeviceBusy)
                {
                    string str2;
                    this._series.clear();
                    switch (mode)
                    {
                        case LBLEDMode.Mode0:
                            str2 = "D0\r";
                            break;

                        case LBLEDMode.Mode1:
                            str2 = "D1\r";
                            break;

                        case LBLEDMode.Mode2:
                            str2 = "D2\r";
                            break;

                        case LBLEDMode.Mode3:
                            str2 = "D3\r";
                            break;

                        default:
                            str2 = "D0\r";
                            break;
                    }
                    this._tele = new Telegram(str2.Length);
                    this._tele.uniqId = GlobalServices.uniqTelegramId();
                    this._tele.parentUniqId = -1;
                    this._tele.type = TelegramType.Command;
                    this._tele.protocol = Protocol.WriteRead;
                    string reply = null;
                    this._tele.replySize = GlobalServices.calculateExpextedReplyLen(str2, ref reply);
                    if (this._tele.replySize == -1)
                    {
                        throw new Exception("Not supported command.");
                    }
                    this._tele.data.copy(str2);
                    this._tele.userData = -1;
                    this._tele.portHandler = this._ioph;
                    this._tele.mainWin = this;
                    this._series.addTelegram(this._tele);
                    if (this._ioph.telegramSeriesFromMainWin(this._series, SeriesExecutionState.Run, true) == 0)
                    {
                        this._isDeviceBusy = true;
                        GlobalServices.LogMsg(this._appId, "Set Loadboard Led Series started");
                        return 0;
                    }
                    return -1;
                }
                return -2;
            }
            catch (Exception exception)
            {
                GlobalServices.ErrMsg(this._appId, "Error at sending Set Loadboard Led Command!\n" + exception.Message);
                GlobalServices.msgBox("Error at sending Set Loadboard Led Command!\n" + exception.Message, "Error!");
                return -1;
            }
        }
Example #21
0
 private void processSimpleCommunicationReplyTelegram(Telegram replyTele)
 {
     if (!(_ioph is IOPH_DCP))
     {
         if ((replyTele.type == TelegramType.DeviceFailure) && replyTele.UserDataExt.hasStoredValue("SentData"))
         {
             showLocalLog(((string) replyTele.UserDataExt["SentData"]) + "\n");
             showLocalLog("< " + ((TelegramType) replyTele.type).ToString() + "\n");
             statusBarPanel4.Step();
         }
         else if (replyTele.type == TelegramType.SeriesEndOK)
         {
             statusBarPanel4.Reset();
             showLocalLog("\n");
             if (tsrMainToolStrip.IsContCurrentReadOn)
             {
                 base.BeginInvoke(new EventHandler(tsrMainToolStrip_AmmeteringRequested), new object[2]);
             }
         }
         else if (replyTele.UserDataExt.hasStoredValue("SentData"))
         {
             showLocalLog(((string) replyTele.UserDataExt["SentData"]) + "\n");
             showLocalLog("< " + WDSConverters.ToHexString(replyTele.data.Buf, replyTele.data.NumItems) + "\n");
             statusBarPanel4.Step();
         }
     }
 }
Example #22
0
 private int send_ReadStatusCommand(bool continuousMode)
 {
     try
     {
         if (!this._isDeviceBusy)
         {
             string[] strArray;
             bool flag = this.afc_chbEnAFC.Checked;
             bool isNeed = this.__isUpdateNeeded;
             this._series.clear();
             if (flag)
             {
                 this.afc_chbEnAFC.Checked = false;
                 string command = this._afc.Command;
                 this.afc_chbEnAFC.Checked = true;
                 string str3 = this._afc.Command;
                 if (isNeed != this.__isUpdateNeeded)
                 {
                     this.setUpdateNeeded(isNeed);
                 }
                 strArray = new string[] { "S2" + command + "\r", "S2" + command + "\r", "H2\r", "L2\r", "L0\r", "RS2\r", "S2" + str3 + "\r", "H2\r" };
             }
             else
             {
                 strArray = new string[] { "H2\r", "L2\r", "L0\r", "RS2\r", "H2\r" };
             }
             int num = flag ? 5 : 3;
             for (int i = 0; i < strArray.Length; i++)
             {
                 this._tele = new Telegram(strArray[i].Length);
                 this._tele.uniqId = GlobalServices.uniqTelegramId();
                 this._tele.parentUniqId = -1;
                 this._tele.type = TelegramType.Command;
                 this._tele.protocol = Protocol.WriteRead;
                 string reply = null;
                 this._tele.replySize = GlobalServices.calculateExpextedReplyLen(strArray[i], ref reply);
                 if (this._tele.replySize == -1)
                 {
                     throw new Exception("Not supported command.");
                 }
                 this._tele.data.copy(strArray[i]);
                 if (i == num)
                 {
                     this._tele.userData = 0;
                 }
                 else
                 {
                     this._tele.userData = -1;
                 }
                 this._tele.portHandler = this._ioph;
                 this._tele.mainWin = this;
                 this._series.addTelegram(this._tele);
             }
             if (continuousMode)
             {
                 this._series.addDelay(0x3e8);
                 this._series.setInfiniteRepetition();
             }
             if (this._ioph.telegramSeriesFromMainWin(this._series, SeriesExecutionState.Run, true) == 0)
             {
                 this._isDeviceBusy = true;
                 GlobalServices.LogMsg(this._appId, "STATUS READ Series started");
                 return 0;
             }
             return -1;
         }
         return -2;
     }
     catch (Exception exception)
     {
         GlobalServices.ErrMsg(this._appId, "Error at sending Read Status Commands!\n" + exception.Message);
         GlobalServices.msgBox("Error at sending Read Status Commands!\n" + exception.Message, "Error!");
         return -1;
     }
 }
Example #23
0
            private void replyTeleArrived(Telegram replyTelegram)
            {
                switch (replyTelegram.type)
                {
                    case TelegramType.AckOrNackSentOK:
                        if (_lastReplyPec == ((LastReplyPrecondition) replyTelegram.lastReplyPrecondition))
                        {
                            if (replyTelegram.numOfLastReplyPackets != -1)
                            {
                                _replyPreconditionCnt--;
                                if (_replyPreconditionCnt == 0)
                                {
                                    execTelegramSeries();
                                }
                                return;
                            }
                            execTelegramSeries();
                        }
                        return;

                    case TelegramType.AcknowledgeOK:
                        _mainWin.showLocalLog("< ACK\n");
                        _gotACKforCommand = true;
                        if (replyTelegram.lastReplyPrecondition == LastReplyPrecondition.ACK)
                        {
                            _replyPreconditionCnt--;
                            if (_replyPreconditionCnt > 0)
                            {
                                return;
                            }
                            execTelegramSeries();
                        }
                        return;

                    case TelegramType.AcknowledgeERROR:
                        _mainWin.showLocalLog("< NACK\n");
                        execTelegramSeries();
                        return;

                    case TelegramType.DataAcknowledgeOK:
                        _mainWin.showLocalLog("< " + WDSConverters.ToHexString(replyTelegram.data.Buf, replyTelegram.data.NumItems) + "\n");
                        if (_savedEvent != null)
                        {
                            _savedEvent(replyTelegram);
                        }
                        if (replyTelegram.lastReplyPrecondition == LastReplyPrecondition.DataACK)
                        {
                            if (replyTelegram.numOfLastReplyPackets == -1)
                            {
                                execTelegramSeries();
                                return;
                            }
                            _replyPreconditionCnt--;
                            if (_replyPreconditionCnt != 0)
                            {
                                return;
                            }
                            execTelegramSeries();
                        }
                        return;

                    case TelegramType.PacketRecOK:
                        if ((((replyTelegram.protocol == Protocol.DCP) || (replyTelegram.protocol == Protocol.DCP2)) && ((replyTelegram.DCPCmdSet == 4) || (replyTelegram.DCPCmdSet == 0x1c))) && (replyTelegram.DCPMsgType == 0))
                        {
                            _mainWin.showLocalLog("< " + WDSConverters.ToHexString(replyTelegram.data.Buf, replyTelegram.data.NumItems) + "\n");
                            switch (replyTelegram.data[0])
                            {
                                case 0x11:
                                case 0x2c:
                                    if (!_gotACKforCommand)
                                    {
                                        _mainWin.showLocalLog(" Unexpected intication, did not got ACK!\n");
                                        return;
                                    }
                                    waitForDevice();
                                    send_Ack(new Telegram.Callback(replyTeleArrived));
                                    _lastReplyPec = LastReplyPrecondition.Indication;
                                    if (_savedEvent == null)
                                        return;
                                    _savedEvent(replyTelegram);
                                    break;
                            }
                        }
                        return;

                    case TelegramType.Terminated:
                        if (_savedEvent != null)
                        {
                            _savedEvent(replyTelegram);
                        }
                        execTelegramSeries();
                        return;
                }
                if (_savedEvent != null)
                {
                    _savedEvent(replyTelegram);
                }
            }
Example #24
0
 private int getDeviceData(Telegram command, Telegram reply)
 {
     try
     {
         if (isWriteCommand(command))
         {
             string str = ((char) command.data[4]).ToString();
             string str2 = ((char) command.data[5]).ToString();
             return Convert.ToInt32(str + str2, 0x10);
         }
         string str4 = ((char) reply.data[reply.data.NumItems - 10]).ToString();
         string str5 = ((char) reply.data[reply.data.NumItems - 9]).ToString();
         return Convert.ToInt32(str4 + str5, 0x10);
     }
     catch (Exception exception)
     {
         MessageBox.Show("Error at getDeviceData()!\n" + exception.Message);
         return -1;
     }
 }
Example #25
0
 public override int DefaultTelegramFromPortHandler(Telegram telegram)
 {
     if (telegram.type == TelegramType.Command)
     {
         _closeCtrl.portHandlerClosed(telegram.portHandler);
         return 0;
     }
     if (telegram.type == TelegramType.DeviceFailure)
     {
         GlobalServices.ErrMsg(_appId, "telegramFromPortHandler(): DeviceFailure received");
         _ioph.controlSeriesExecution(SeriesExecutionState.Stop);
         sbDeviceStatePane.Text = "Status: DeviceFailure";
         return -1;
     }
     oldTelegramFromPortHandler(telegram);
     return 0;
 }
Example #26
0
 private bool isWriteCommand(Telegram command)
 {
     try
     {
         char ch = (char) command.data[2];
         return ((Convert.ToInt32(ch.ToString(), 0x10) & 8) > 0);
     }
     catch (Exception exception)
     {
         MessageBox.Show("Error at isWriteCommand()!\n" + exception.Message);
         return false;
     }
 }
Example #27
0
 public int send_TransmitPacketCommand(string hexStrPacket, bool continuousMode)
 {
     try
     {
         string reply = null;
         this._series.clear();
         string command = "T14";
         if ((hexStrPacket.Length % 2) == 1)
         {
             hexStrPacket = "0" + hexStrPacket;
         }
         for (int i = 0; i < hexStrPacket.Length; i += 2)
         {
             object obj2 = command;
             command = string.Concat(new object[] { obj2, ",", hexStrPacket[i], hexStrPacket[i + 1] });
         }
         command = command + "\r";
         this._tele = new Telegram(command.Length);
         this._tele.uniqId = GlobalServices.uniqTelegramId();
         this._tele.parentUniqId = -1;
         this._tele.type = TelegramType.Command;
         this._tele.protocol = Protocol.WriteRead;
         this._tele.replySize = GlobalServices.calculateExpextedReplyLen(command, ref reply);
         if (this._tele.replySize == -1)
         {
             throw new Exception("Not supported command.");
         }
         this._tele.data.copy(command);
         this._tele.userData = 3;
         this._tele.portHandler = this._ioph;
         this._tele.mainWin = this;
         if (this.chbTransPackErrRateTestEnab.Checked)
         {
             this._tele.addHeader(0);
         }
         this._series.addTelegram(this._tele);
         if (continuousMode)
         {
             this._series.addDelay(this._transmitRepetitionTime);
             this._series.setInfiniteRepetition();
         }
         if (this._ioph.telegramSeriesFromMainWin(this._series, SeriesExecutionState.Run, true) == 0)
         {
             this._isDeviceBusy = true;
             GlobalServices.LogMsg(this._appId, "TRANSMIT PACKET Series started");
             return 0;
         }
         return -1;
     }
     catch (Exception exception)
     {
         GlobalServices.ErrMsg(this._appId, "Error at sending Transmit Packet Command!\n" + exception.Message);
         GlobalServices.msgBox("Error at sending Transmit Packet Command!\n" + exception.Message, "Error!");
         return -1;
     }
 }
Example #28
0
 private int send_ReceivePacketCommand(bool enableEOPChar_or_PacketLength, bool enableEOPChar_only, int EOP, int PL, bool continuousMode)
 {
     try
     {
         byte num;
         string str2;
         if (this.fifo_chbDisSensRes.Checked)
         {
             num = 1;
         }
         else
         {
             num = 0;
         }
         string str = "S2CA" + ((byte) (0x80 | num)).ToString("X") + "\r";
         if (enableEOPChar_or_PacketLength)
         {
             str2 = "F11," + EOP.ToString() + "," + PL.ToString() + "\r";
         }
         else if (enableEOPChar_only)
         {
             str2 = "F12," + EOP.ToString() + "," + PL.ToString() + "\r";
         }
         else
         {
             str2 = "F13," + EOP.ToString() + "," + PL.ToString() + "\r";
         }
         string str3 = "S2CA" + ((byte) (130 | num)).ToString("X") + "\r";
         string[] strArray = new string[] { str, "H2\r", "L2\r", "L0\r", "RS2\r", "H2\r", str2, str3, "" };
         this._series.clear();
         for (int i = 0; i < strArray.Length; i++)
         {
             this._tele = new Telegram(strArray[i].Length);
             this._tele.uniqId = GlobalServices.uniqTelegramId();
             this._tele.parentUniqId = -1;
             this._tele.type = TelegramType.Command;
             if (strArray[i] != "")
             {
                 this._tele.protocol = Protocol.WriteRead;
                 string reply = null;
                 this._tele.replySize = GlobalServices.calculateExpextedReplyLen(strArray[i], ref reply);
             }
             else
             {
                 this._tele.protocol = Protocol.ReadRxPacket;
                 this._tele.replySize = PL;
             }
             if (this._tele.replySize == -1)
             {
                 throw new Exception("Not supported command.");
             }
             this._tele.data.copy(strArray[i]);
             this._tele.userData = -1;
             this._tele.portHandler = this._ioph;
             this._tele.mainWin = this;
             this._series.addTelegram(this._tele);
         }
         if (continuousMode)
         {
             this._series.setInfiniteRepetition();
         }
         if (this._ioph.telegramSeriesFromMainWin(this._series, SeriesExecutionState.Run, true) == 0)
         {
             this._isDeviceBusy = true;
             GlobalServices.LogMsg(this._appId, "START RECEIVE Series started");
             return 0;
         }
         return -1;
     }
     catch (Exception exception)
     {
         GlobalServices.ErrMsg(this._appId, "Error at sending Start Receive Commands!\n" + exception.Message);
         GlobalServices.msgBox("Error at sending Start Receive Commands!\n" + exception.Message, "Error!");
         return -1;
     }
 }
Example #29
0
 private int ForceTelegramFromMainWin(Telegram tele, int waitMsec, int maxWaitMsec)
 {
     if (waitMsec <= 0)
     {
         return this._ioph.telegramFromMainWin(tele);
     }
     for (int i = 0; i < maxWaitMsec; i += waitMsec)
     {
         if (this._ioph.telegramFromMainWin(tele) == 0)
         {
             return 0;
         }
         if (this._ioph.IsLastErrorBusyState())
         {
             Thread.Sleep(waitMsec);
         }
         else
         {
             return -1;
         }
     }
     GlobalServices.ErrMsg(this._appId, "Unable to send forced telegram, IOPH is busy");
     return -1;
 }
Example #30
0
 private TelegramContainer createSeries(Task task, int numOfCommands, LastReplyPrecondition[] teleStopPrec, byte[][] teleData, Telegram.Callback callback, bool isGeneralCmd)
 {
     TelegramContainer container = new TelegramContainer();
     container.clear();
     for (int i = 0; i < numOfCommands; i++)
     {
         Telegram tele = new Telegram(5) {
             uniqId = GlobalServices.uniqTelegramId(),
             parentUniqId = -1,
             type = TelegramType.Command
         };
         if (_ioph is IOPH_DATA)
         {
             tele.protocol = Protocol.DCP2;
             if (isGeneralCmd)
             {
                 tele.DCPCmdSet = 0x18;
             }
             else
             {
                 tele.DCPCmdSet = 0x1c;
             }
         }
         else
         {
             tele.protocol = Protocol.DCP;
             tele.DCPCmdSet = 4;
         }
         tele.lastReplyPrecondition = teleStopPrec[i];
         tele.UserDataExt.addUserData("Task", task);
         tele.portHandler = _ioph;
         tele.mainWin = this;
         tele.clearEventHandler();
         tele.CallbackEvent += callback;
         tele.data.copy(teleData[i]);
         container.addTelegramContainerItem(new TelegramContainerItem(tele));
     }
     return container;
 }