private int send_Ack(Telegram.Callback callback) { try { Telegram telegram = new Telegram(0) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, lastReplyPrecondition = _lastReplyPec, protocol = Protocol.DCP, DCPCmdSet = 0, DCPMsgType = 0x40, replySize = 0x19 }; telegram.clearEventHandler(); telegram.CallbackEvent += callback; if (telegram.replySize == -1) { throw new Exception("Not supported command."); } telegram.userData = 1; telegram.portHandler = _mainWin._ioph; telegram.mainWin = _mainWin; _mainWin.showLocalLog("> ACK\n"); if (_mainWin._ioph.telegramFromMainWin(telegram) == 0) { return 0; } return -1; } catch (Exception exception) { AppWin_SPITool_PRO._log.Error(exception.Message); return -1; } }
private TelegramContainer createSeries(Task task, int numOfCommands, LastReplyPrecondition[] teleStopPrec, byte[][] teleData, Telegram.Callback callback) { 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, protocol = Protocol.DCP, DCPCmdSet = 4, lastReplyPrecondition = teleStopPrec[i], userData = (int) task, portHandler = this._ioph, mainWin = this }; tele.clearEventHandler(); tele.CallbackEvent += callback; tele.data.copy(teleData[i]); if (i == (numOfCommands - 1)) { tele.UserDataExt.addUserData("RetVal", 0); } container.addTelegramContainerItem(new TelegramContainerItem(tele)); } return container; }
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; }
private void sendLabelDataChanges(int nodeNumber) { Telegram telegram = new Telegram(5); TelegramContainer container = new TelegramContainer(); telegram.uniqId = GlobalServices.uniqTelegramId(); telegram.parentUniqId = -1; telegram.type = TelegramType.Command; telegram.protocol = Protocol.DCP2; telegram.DCPCmdSet = 0x24; telegram.lastReplyPrecondition = LastReplyPrecondition.Indication; telegram.portHandler = this._ioph; telegram.mainWin = this; telegram.clearEventHandler(); telegram.CallbackEvent += new Telegram.Callback(this.processReplyData); telegram.data.copy(new byte[1]); byte[] buf = this._shelfLabelDescriptorSet[nodeNumber].getUpdatePayload(); telegram.data.append(buf, buf.Length); telegram.UserDataExt.addUserData("NodeNumber", nodeNumber); container.addTelegram(telegram); if (!this._adtRec.isSimuation && (this._ioph.telegramSeriesFromMainWin(container, SeriesExecutionState.Run, true) == -1)) { MessageBox.Show("Device is BUSY!"); } }
private void btnChipStateReadInfo_Click(object sender, EventArgs e) { this._series.clear(); Telegram tele = new Telegram(5) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, protocol = Protocol.DCP, DCPCmdSet = 4, lastReplyPrecondition = LastReplyPrecondition.Indication, userData = 12, portHandler = this._ioph, mainWin = this }; tele.clearEventHandler(); tele.CallbackEvent += new Telegram.Callback(this.processReadChipStatusReplyTelegram); byte[] buf = new byte[] { 0x27, 0, 1, 0x61 }; buf[1] = this._Si4012I2CBusAddress; tele.data.copy(buf); this._series.addTelegramContainerItem(new TelegramContainerItem(tele)); tele = new Telegram(5) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, protocol = Protocol.DCP, DCPCmdSet = 4, lastReplyPrecondition = LastReplyPrecondition.Indication, userData = 11, portHandler = this._ioph, mainWin = this }; tele.clearEventHandler(); tele.CallbackEvent += new Telegram.Callback(this.processReadChipStatusReplyTelegram); tele.UserDataExt.addUserData("RetVal", 0); tele.data.copy(new byte[] { 40, this._Si4012I2CBusAddress, 6 }); this._series.addTelegramContainerItem(new TelegramContainerItem(tele)); if (this._teleProcessor.initSeries(this._series)) { this._teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } }
private TelegramContainer createSeries(Task task, int numOfCommands, byte[][] dcpPrefixCommandSet, byte[][] rfCommandSet, Telegram.Callback callback, bool[] isGeneralCmdIndicatorSet) { try { 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, protocol = Protocol.DCP2 }; if (isGeneralCmdIndicatorSet[i]) { tele.DCPCmdSet = 0x18; } else { tele.DCPCmdSet = 0x1c; } tele.lastReplyPrecondition = LastReplyPrecondition.Indication; tele.UserDataExt.addUserData("Task", task); tele.portHandler = this._ioph; tele.mainWin = this; tele.clearEventHandler(); tele.CallbackEvent += callback; if ((dcpPrefixCommandSet != null) && (dcpPrefixCommandSet.Length >= i)) { tele.data.copy(dcpPrefixCommandSet[i]); } if ((rfCommandSet != null) && (rfCommandSet.Length >= i)) { tele.data.append(rfCommandSet[i], rfCommandSet[i].Length); } container.addTelegramContainerItem(new TelegramContainerItem(tele)); } return container; } catch (Exception exception) { _log.Error("Could not create command series! " + exception.Message); return null; } }
private void tsrMainToolStrip_IdentifyRequested(object sender, EventArgs e) { Telegram telegram = new Telegram(1) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command }; if (this._ioph is IOPH_DCP) { telegram.protocol = Protocol.DCP; telegram.DCPCmdSet = 4; } else { telegram.protocol = Protocol.DCP2; telegram.DCPCmdSet = 0x18; } telegram.portHandler = this._ioph; telegram.mainWin = this; telegram.clearEventHandler(); telegram.CallbackEvent += new Telegram.Callback(this.identifyEventHandler); telegram.lastReplyPrecondition = LastReplyPrecondition.ACK; this._series.clear(); if (this._teleProcessor == null) { this._series.addTelegram(telegram); this._series[0].telegram.data.copy(new byte[] { 0x17, 1 }); this._series[0].telegram.UserDataExt.addUserData("CmdName", "IdentifyDevice"); this._series[0].telegram.UserDataExt.addUserData("Task", Task.DeviceIdentificationStart); this._series[0].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(this._series[0].telegram.data.Buf, this._series[0].telegram.data.NumItems)); this.statusBarPanel4.Reset(); this.statusBarPanel4.EndPoint = this._series.Count; this.sbDeviceStatePane.Text = this.getStatusString((Task) this._series[0].telegram.UserDataExt.StoredUserData["Task"]); if (this._adtRec.isSimuation) { this.logSimulationModeCommandSeries(this._series); } else if (this._ioph.telegramSeriesFromMainWin(this._series, SeriesExecutionState.Run, true) == -1) { MessageBox.Show("Device is BUSY!"); } } else { switch (this._commonTimerRole) { case TmrRole.None: telegram.data.copy(new byte[] { 0x17, 3 }); telegram.SenderInfo = new object[] { "IdentifyDevice" }; this._series.addTelegram(telegram); if (!this._teleProcessor.initSeries(this._series)) { MessageBox.Show("Device is BUSY!"); } else { this._teleProcessor.execTelegramSeries(); } this.tmrCommon.Interval = 0x3e8; this.tmrCommon.Enabled = true; this._commonTimerRole = TmrRole.LBIdentification; return; case TmrRole.LBIdentification: { byte[] buf = new byte[2]; buf[0] = 0x17; telegram.data.copy(buf); this.tmrCommon.Enabled = false; this._series.addTelegram(telegram); if (!this._teleProcessor.initSeries(this._series)) { MessageBox.Show("Device is BUSY!"); break; } this._teleProcessor.execTelegramSeries(); break; } default: this._commonTimerRole = TmrRole.None; return; } this._commonTimerRole = TmrRole.None; } }
private TelegramContainer createSpiCommanSeries(int numOfCommands, byte[][] teleData, Telegram.Callback callback, bool resetChip, bool shutdownChip) { TelegramContainer container = new TelegramContainer(); container.clear(); if (shutdownChip) { foreach (TelegramContainerItem item in createShutdownCommandSeries()) { container.addTelegramContainerItem(item); } return container; } if (resetChip) { foreach (TelegramContainerItem item2 in createResetCommandSeries()) { container.addTelegramContainerItem(item2); } } for (int i = 0; i < numOfCommands; i++) { Telegram tele = new Telegram(5) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, protocol = Protocol.DCP2, DCPCmdSet = 0x1c, portHandler = _ioph, mainWin = this }; tele.clearEventHandler(); tele.CallbackEvent += callback; byte[] buf = new byte[3]; buf[0] = 0x10; tele.data.copy(buf); tele.data.append(teleData[i], teleData[i].Length); tele.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(teleData[i], teleData[i].Length)); container.addTelegramContainerItem(new TelegramContainerItem(tele)); } return container; }
private TelegramContainer createShutdownCommandSeries() { TelegramContainer container = new TelegramContainer(); container.clear(); for (int i = 0; (i < RESET_COMMAND_SET.Length) || (i < 2); i++) { Telegram tele = new Telegram(5) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, protocol = Protocol.DCP2, DCPCmdSet = 0x1c, portHandler = _ioph, mainWin = this }; tele.clearEventHandler(); tele.data.copy(RESET_COMMAND_SET[i]); container.addTelegramContainerItem(new TelegramContainerItem(tele)); } return container; }
private int send_Ack(Telegram.Callback callback) { try { Telegram telegram = new Telegram(0) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, lastReplyPrecondition = this._lastReplyPec, protocol = Protocol.DCP, DCPCmdSet = 0, DCPMsgType = 0x40, replySize = 0x19 }; telegram.clearEventHandler(); telegram.CallbackEvent += callback; if (telegram.replySize == -1) { throw new Exception("Error sending ACK message"); } telegram.portHandler = this._ioph; telegram.mainWin = this._mainWin; this.communicationLog("> ACK"); if (this._ioph.telegramFromMainWin(telegram) == 0) { return 0; } return -1; } catch (Exception exception) { _log.Error(exception.Message); return -1; } }