public bool initSeries(TelegramContainer tc) { if (this._ioph.isBusy()) { return false; } this._telegramSeries = tc; this._isFirstTelegram = true; return true; }
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 tsrMainToolStrip_IdentifyRequested(object sender, EventArgs e) { TelegramContainer container = new TelegramContainer(); if (_ioph is IOPH_DATA) { container = createSeries(Task.IdentifyStop, 1, new LastReplyPrecondition[] { LastReplyPrecondition.Indication }, new byte[][] { new byte[] { 0x17, 1 } }, new Telegram.Callback(processSimpleCommunicationReplyTelegram), true); _commonTimerRole = TmrRole.None; container[0].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(container[0].telegram.data.Buf, container[0].telegram.data.NumItems)); tmrCommon.Enabled = false; } else { switch (_commonTimerRole) { case TmrRole.None: container = createSeries(Task.IdentifyStart, 1, new LastReplyPrecondition[] { LastReplyPrecondition.ACK }, new byte[][] { new byte[] { 0x17, 3 } }, null, true); _commonTimerRole = TmrRole.LBIdentification; tmrCommon.Enabled = true; goto Label_0195; case TmrRole.LBIdentification: { byte[][] teleData = new byte[1][]; byte[] buffer3 = new byte[2]; buffer3[0] = 0x17; teleData[0] = buffer3; container = createSeries(Task.IdentifyStop, 1, new LastReplyPrecondition[] { LastReplyPrecondition.ACK }, teleData, null, true); _commonTimerRole = TmrRole.None; tmrCommon.Enabled = false; goto Label_0195; } } _commonTimerRole = TmrRole.None; tmrCommon.Enabled = false; return; } Label_0195: if (_teleProcessor == null) { if (_ioph.telegramSeriesFromMainWin(container, SeriesExecutionState.Run, true) == -1) { MessageBox.Show("Device is BUSY!"); return; } } else { if (_teleProcessor.initSeries(container)) { _teleProcessor.execTelegramSeries(); return; } MessageBox.Show("Device is BUSY!"); } }
public bool initSeries(TelegramContainer tc) { if (this._mainWin._deviceBusy) { return false; } this._telegramSeries = tc; return true; }
private void btnRead_Click(object sender, EventArgs e) { try { if (_myDev.RxPufferSize < 1) { MessageBox.Show("This device can not Receive data!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { byte[] buffer = new byte[_myDev.RxPufferSize + 4]; buffer[0] = 0x10; buffer[1] = 0; buffer[2] = 0; buffer[3] = (byte) _myDev.RxPufferAddress; TelegramContainer container = new TelegramContainer(); container = createSeries(Task.FIFORead, 1, new LastReplyPrecondition[] { LastReplyPrecondition.Indication }, new byte[][] { buffer }, new Telegram.Callback(processFIFOReadIO), false); container[0].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(container[0].telegram.data.Buf, container[0].telegram.data.NumItems)); if (_teleProcessor == null) { if (_ioph.telegramSeriesFromMainWin(container, SeriesExecutionState.Run, true) == -1) { MessageBox.Show("Device is BUSY!"); } } else if (_teleProcessor.initSeries(container)) { _teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } } } catch (Exception exception) { MessageBox.Show("Error at Reading FIFO!\n" + exception.Message); } }
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!"); } }
public int telegramSeriesFromMainWin(TelegramContainer container, SeriesExecutionState initialState, bool sendReplyTelegrams) { if (isBusy()) { GlobalServices.ErrMsg("telegramSeriesFromMainWin()", "Telegram series received in busy port handler state"); return -1; } _seriesFromWin = container; _seriesExecStat = initialState; _replyTelegramsRequested = sendReplyTelegrams; _isRequestAvailible = true; return 0; }
private void ffcFifo_StartTransmit(List<byte> contents, string mode, int packetSize, bool autoTransmit) { ushort num = Convert.ToUInt16(packetSize); byte num2 = 0; switch (mode) { case "Ready": num2 = 0x30; break; case "Sleep": case "Standby": num2 = 0x10; break; case "TuneTX": num2 = 80; break; case "TuneRX": num2 = 0x60; break; case "TX": num2 = 0x70; break; case "RX": num2 = 0x80; break; case "SPIActive": num2 = 0x20; break; } byte[][] teleData = new byte[1][]; byte[] buffer = new byte[8]; buffer[0] = 0x10; buffer[3] = 0x31; buffer[5] = num2; buffer[6] = BitConverter.GetBytes(num)[1]; buffer[7] = BitConverter.GetBytes(num)[0]; teleData[0] = buffer; this._series = this.createSeries(Task.Fifo, 1, new LastReplyPrecondition[] { LastReplyPrecondition.Indication }, teleData, new Telegram.Callback(this.processFifoReply), new bool[1]); if (this._series != null) { this._series[0].telegram.SenderInfo = new object[] { "StartTX" }; this._series[0].telegram.UserDataExt.addUserData("CmdName", "StartTX"); this._series[0].telegram.UserDataExt.addUserData("Task", Task.Fifo); this._series[0].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(this._series[0].telegram.data.Buf, this._series[0].telegram.data.NumItems)); } if (this._teleProcessor == null) { 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 if (this._teleProcessor.initSeries(this._series)) { this._teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } }
public AppWin_SPITool_PRO2() { byte[][] bufferArray = new byte[4][]; byte[] buffer = new byte[3]; buffer[0] = 8; buffer[1] = 0x7f; bufferArray[0] = buffer; bufferArray[1] = new byte[] { 0x21, 100, 0xa2 }; byte[] buffer2 = new byte[3]; buffer2[0] = 0x20; buffer2[1] = 0x7f; bufferArray[2] = buffer2; byte[] buffer3 = new byte[3]; buffer3[0] = 8; buffer3[1] = 0x1f; bufferArray[3] = buffer3; this.PA_MODE_CMD = bufferArray; this._chipType = ""; this._chipRev = ""; this._myDev = new DeviceRegisterSet(); this._tele = new Telegram(100); this._series = new TelegramContainer(); this._appId = GlobalServices.uniqApplicationId(WDSApplicationType.SPITool_PRO2); this._formwidth = 0x3e9; this.vsb = new VScrollBar(); this._currentVoltage = 2.4; this._interpreter = "base-tcl8.5-thread-win32-ix86.exe"; this._execState = ExecutionStatus.Stopped; this.InitializeComponent(); this.spcMainContainer.IsSplitterFixed = true; if ((SystemInformation.PrimaryMonitorSize.Height - 120) < 720) { base.Height = SystemInformation.PrimaryMonitorSize.Height - 140; Point point = new Point(); this.vsb.Height = (base.ClientSize.Height - this.tsrMainToolStrip.Height) - this.spiStatusBar.Height; this.vsb.SmallChange = this.spcMainContainer.Height / 20; this.vsb.LargeChange = this.spcMainContainer.Height / 10; this.vsb.Minimum = 0; this.vsb.Maximum = (((this.spcMainContainer.Height - base.ClientSize.Height) + this.vsb.LargeChange) + this.spiStatusBar.Height) + this.tsrMainToolStrip.Height; this.vsb.ValueChanged += new EventHandler(this.vsb_ValueChanged); base.MouseWheel += new MouseEventHandler(this.mouseWheelRotated); base.Controls.Add(this.vsb); this._formwidth += this.vsb.Width; base.Width = this._formwidth; point.Y = this.tsrMainToolStrip.Height; point.X = (base.Width - this.vsb.Width) - 10; this.vsb.Location = point; this.vsb.Show(); this.vsb.BringToFront(); } if (!GlobalServices.isfeatureAllowed(GlobalServices.Features.NextGenerationPRO_EngExtra)) { this.tbcCommandTypeSelector.TabPages.Remove(this.tbpRegisterEditor); this.tbcCommandTypeSelector.TabPages.Remove(this.tbpTclScriptCall); this.tbcCommandTypeSelector.TabPages.Remove(this.tbpRamLoad); } this.statusBarPanel4.ShowText = false; this.statusBarPanel4.StartPoint = 0L; this.statusBarPanel4.StepSize = 1L; }
private void ffcFifo_LoadTxFifo(List<byte> contents) { byte[] collection = new byte[4]; collection[0] = 0x10; collection[3] = 0x66; contents.InsertRange(0, collection); this._series = this.createSeries(Task.Fifo, 4, new LastReplyPrecondition[] { LastReplyPrecondition.Indication, LastReplyPrecondition.Indication, LastReplyPrecondition.Indication, LastReplyPrecondition.Indication }, new byte[][] { contents.ToArray(), new byte[] { 0x10, 0, 0, 0x11, 0x10, 1, 0, 0 }, new byte[] { 0x10, 0, 0, 0x11, 0x10, 1, 4, 1 }, new byte[] { 0x10, 0, 0, 0x11, 0x11, 1, 0, 0 } }, new Telegram.Callback(this.processFifoReply), new bool[4]); if (this._series != null) { for (int i = 0; i < this._series.Count; i++) { if (i == 0) { this._series[i].telegram.SenderInfo = new object[] { "LoadTX" }; this._series[i].telegram.UserDataExt.addUserData("CmdName", "LoadTX"); } this._series[i].telegram.UserDataExt.addUserData("Task", Task.Fifo); this._series[i].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(this._series[i].telegram.data.Buf, this._series[i].telegram.data.NumItems)); } } if (this._teleProcessor == null) { 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 if (this._teleProcessor.initSeries(this._series)) { this._teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } }
private void ffcFifo_ReadFifo(string mode, int packetSize) { this._bytesToRead = packetSize; byte[] buffer = new byte[packetSize + 4]; buffer[0] = 0x10; buffer[3] = 0x77; this._series = this.createSeries(Task.Fifo, 2, new LastReplyPrecondition[] { LastReplyPrecondition.Indication, LastReplyPrecondition.Indication }, new byte[][] { buffer, new byte[] { 0x10, 0, 0, 0x44, 0xff } }, new Telegram.Callback(this.processReadFifo), new bool[2]); if (this._series != null) { for (int i = 0; i < this._series.Count; i++) { if (i == 0) { this._series[i].telegram.SenderInfo = new object[] { "ReadRX" }; this._series[i].telegram.UserDataExt.addUserData("RxFifo", null); this._series[i].telegram.UserDataExt.addUserData("CmdName", "ReadRX"); } this._series[i].telegram.UserDataExt.addUserData("Task", Task.Fifo); this._series[i].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(this._series[i].telegram.data.Buf, this._series[i].telegram.data.NumItems)); } } if (this._teleProcessor == null) { 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 if (this._teleProcessor.initSeries(this._series)) { this._teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } }
private void ffcFifo_InitTxFifo(object sender, EventArgs e) { this._series = this.createSeries(Task.Fifo, 1, new LastReplyPrecondition[] { LastReplyPrecondition.Indication }, new byte[][] { new byte[] { 0x10, 0, 0, 0x15, 1 } }, new Telegram.Callback(this.processFifoReply), new bool[1]); if (this._series != null) { this._series[0].telegram.SenderInfo = new object[] { "InitTX" }; this._series[0].telegram.UserDataExt.addUserData("CmdName", "InitTX"); this._series[0].telegram.UserDataExt.addUserData("Task", Task.Fifo); this._series[0].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(this._series[0].telegram.data.Buf, this._series[0].telegram.data.NumItems)); } if (this._teleProcessor == null) { 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 if (this._teleProcessor.initSeries(this._series)) { this._teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } }
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 void matlabCalc_FormClosing(object sender, EventArgs e) { TelegramContainerItem[] itemArray; string str3; TelegramContainer teleContainer = new TelegramContainer(); string logMessage = string.Empty; string str2 = string.Empty; if (sender == null) { goto Label_095F; } base.Enabled = true; switch (this._matlabCalcForm.MatlabResult) { case Result.Success: if (this._matlabCalcForm.RegularOutput == null) { goto Label_095F; } if ((!this.chbEnableIqCalibration.Checked || (this._matlabCalcForm.IqOutput == null)) || ((this._matlabCalcForm.IqOutput.propertyValues == null) || (this._matlabCalcForm.IqOutput.propertyValues.Count <= 0))) { goto Label_0399; } if (this._matlabCalcForm.getInputRef().RF_Frequency <= 0x1f4add40) { this._calibrateCommandString.Append((string) this._appResources.GetObject("App_Si4060CP_IQ_LowBand_For_Si4463")); break; } this._calibrateCommandString.Append((string) this._appResources.GetObject("App_Si4060CP_IQ_HighBand_For_Si4463")); break; case Result.Cancelled: return; default: MessageBox.Show("Matlab calculation failed!\n" + this._matlabCalcForm.LogFileContent + "\n" + this._matlabCalcForm.MatlabResult.ToString()); return; } uint num5 = Convert.ToUInt32((decimal) (this.nudXtalFrequency.Value * 1000000M)); byte num = BitConverter.GetBytes(num5)[3]; byte num2 = BitConverter.GetBytes(num5)[2]; byte num3 = BitConverter.GetBytes(num5)[1]; byte num4 = BitConverter.GetBytes(num5)[0]; this._calibrateCommandString = this._calibrateCommandString.Replace("<POWER_UP>", "'POWER_UP' 01 00 " + num.ToString("X2") + " " + num2.ToString("X2") + " " + num3.ToString("X2") + " " + num4.ToString("X2")); this._calibrateCommandString = this._calibrateCommandString.Replace("<CAP_BANK>", "'SET_PROPERTY' 'GLOBAL_XO_TUNE' " + ((byte) this.nudXtalCapBank.Value).ToString("X2")); foreach (Pro2Calc.PropertyValuePair pair in this._matlabCalcForm.IqOutput.propertyValues) { this._calibrateCommandString = this._calibrateCommandString.Replace("<INSERT_HERE>", "'SET_PROPERTY' '" + pair.name + "' " + pair.value.ToString("X2") + "\r\n<INSERT_HERE>"); } this._calibrateCommandString = this._calibrateCommandString.Replace("<INSERT_HERE>", "\r\n"); if (((itemArray = SPI_tool_PRO2.createTelegramsFromBatchString(this._calibrateCommandString.ToString(), this._ioph, this, false, this._registerDescriptor, this._chipApiDescriptor, out str3)) == null) || (itemArray.Length < 4)) { MessageBox.Show("Invalid Command, cannot execute!"); _log.Error("Problem in calibration commands generation. No commands, or to few commands were generated!"); return; } for (int i = 0; i < itemArray.Length; i++) { itemArray[i].telegram.SenderInfo = null; itemArray[i].telegram.clearEventHandler(); itemArray[i].telegram.CallbackEvent += new Telegram.Callback(this.updateExecutionEventHandler); itemArray[i].telegram.UserDataExt.addUserData("Task", Task.Update); teleContainer.addTelegramContainerItem(itemArray[i]); } Label_0399: foreach (Pro2Calc.PropertyValuePair pair2 in this._matlabCalcForm.RegularOutput.propertyValues) { if (this.cbbModulationType.SelectedItem.ToString().StartsWith("4") && (pair2.name == "MODEM_FSK4_MAP")) { pair2.value = (byte) this.cbb4GfskMap.SelectedIndex; } ChipProperty property = this._chipApiDescriptor.getPropertyByName(pair2.name); byte[] item = new byte[] { 0x10, 0, 0, 0x11, 0, 1, 0, 0 }; item[4] = BitConverter.GetBytes(property.PropID)[1]; item[6] = BitConverter.GetBytes(property.PropID)[0]; item[7] = pair2.value; this._updateCommandByte.Add(item); this._updateCommandReplyType.Add(LastReplyPrecondition.Indication); this._updateCommandString.AppendLine("'SET_PROPERTY' '" + pair2.name + "' " + pair2.value.ToString("X2")); } this._headerContent.AppendLine(""); this._headerContent.AppendLine("/* Input file content:"); this._headerContent.AppendLine(this._matlabCalcForm.InputFile + "*/"); this._headerContent.AppendLine(""); this._headerContent.AppendLine("#define CENTER_FREQ " + this._matlabCalcForm.getInputRef().RF_Frequency.ToString()); this._headerContent.AppendLine("#define XTAL_FREQ " + this._matlabCalcForm.getInputRef().CrystalFrequency.ToString()); this._headerContent.AppendLine("#define CHANNEL_SPACING " + ((int) (this.nudChannelSpacing.Value * 1000M)).ToString()); this._headerContent.AppendLine("#define CHANNEL_NUMBER " + this.nudChannelNumber.Value.ToString()); this._headerContent.AppendLine("#define XTAL_CAP_BANK 0x" + ((int) this.nudXtalCapBank.Value).ToString("X2")); this._headerContent.AppendLine("#define MODULATION_TYPE \"" + this.cbbModulationType.SelectedItem.ToString() + "\""); this._headerContent.AppendLine("#define MODULATION_TYPE_VALUE " + (this.rdbRX.Checked ? ((this.cbbModulationType.SelectedIndex + 1)).ToString() : this.cbbModulationType.SelectedIndex.ToString())); this._headerContent.AppendLine("#define MANCHESTER_CODE \"" + this.cbbManchesterMode.SelectedItem.ToString() + "\""); this._headerContent.AppendLine("#define MANCHESTER_CODE_VALUE " + this.cbbManchesterMode.SelectedIndex.ToString()); this._headerContent.AppendLine("#define DEVIATION " + this._matlabCalcForm.getInputRef().FrequencyDeviation.ToString()); this._headerContent.AppendLine("#define DATA_RATE " + this._matlabCalcForm.getInputRef().SymbolRate.ToString()); this._headerContent.AppendLine("#define ANTENNA_DIVERSITY \"" + this.cbbAntennaDiversity.SelectedItem.ToString() + "\""); this._headerContent.AppendLine("#define ANTENNA_DIVERSITY_VALUE " + this.cbbAntennaDiversity.SelectedIndex.ToString()); this._headerContent.AppendLine(""); int index = this._matlabCalcForm.LogFileContent.IndexOf("# WB"); if (index != -1) { logMessage = this._matlabCalcForm.LogFileContent.Substring(index); int length = logMessage.IndexOf("\n"); logMessage = logMessage.Substring(0, length); this._headerContent.AppendLine(""); this._headerContent.AppendLine("// " + logMessage + "\n"); this.showLocalLog(logMessage); } int num9 = (2 * this._matlabCalcForm.getInputRef().FrequencyDeviation) / this._matlabCalcForm.getInputRef().SymbolRate; this._headerContent.AppendLine("// Modulation index: " + num9.ToString() + "\n"); this.showLocalLog("# Modulation index: " + num9.ToString()); if (this._matlabCalcForm.LogFileContent.Contains("# Warning:")) { str2 = this._matlabCalcForm.LogFileContent.Substring(this._matlabCalcForm.LogFileContent.IndexOf("# Warning:")).Trim(); this.showLocalLog(str2); str2 = str2.Replace("\n", "\n// "); this._headerContent.AppendLine(""); this._headerContent.AppendLine("// " + str2 + "\n"); } this._headerContent = new StringBuilder(this._headerContent.ToString() + this._matlabCalcForm.HeaderFileContent); Label_095F: this.addPACommand(); this.addTRXCommand(); switch (this._calcPurpose) { case CalculationPurpose.Update: { TelegramContainer tc = this.createSeries(Task.Update, this._updateCommandByte.Count, this._updateCommandReplyType.ToArray(), this._updateCommandByte.ToArray(), null, new bool[this._updateCommandByte.Count]); tc.insertTelegramContainer(teleContainer, 0); if (this._teleProcessor != null) { if (this._teleProcessor.initSeries(tc)) { this.sbProgressBar.Reset(); this.sbProgressBar.EndPoint = tc.Count; this._teleProcessor.execTelegramSeries(); return; } MessageBox.Show("Device is BUSY!"); return; } for (int j = 0; j < tc.Count; j++) { tc[j].telegram.clearEventHandler(); tc[j].telegram.CallbackEvent += new Telegram.Callback(this.updateExecutionEventHandler); tc[j].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(tc[j].telegram.data.Buf, tc[j].telegram.data.NumItems)); } this.sbProgressBar.Reset(); this.sbProgressBar.EndPoint = tc.Count; this.sbDeviceStatePane.Text = this.getStatusString((Task) tc[0].telegram.UserDataExt.StoredUserData["Task"]); if (this._adtRec.isSimuation) { this.logSimulationModeCommandSeries(tc); return; } if (this._ioph.telegramSeriesFromMainWin(tc, SeriesExecutionState.Run, true) != -1) { break; } MessageBox.Show("Device is BUSY!"); return; } case CalculationPurpose.CodeGenerate: this.rtbCHeaderPreview.Clear(); if (this.rdbAddTextName.Checked && (this.txbDeviceName.Text != "")) { this._headerContent.Replace("#define ", "#define " + this.txbDeviceName.Text + "_"); } this.rtbCHeaderPreview.AppendText(this._headerContent.ToString()); return; case CalculationPurpose.SaveBatch: { Stream stream; string currentDirectory = Directory.GetCurrentDirectory(); SaveFileDialog dialog = new SaveFileDialog { Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*", FilterIndex = 0, FileName = Path.Combine(Application.LocalUserAppDataPath, "Batch_" + this._chipType + ".txt") }; DialogResult result = dialog.ShowDialog(); Directory.SetCurrentDirectory(currentDirectory); if ((result == DialogResult.OK) && ((stream = dialog.OpenFile()) != null)) { TextWriter writer = new StreamWriter(stream); writer.WriteLine("#BatchName " + this._chipType); if (this._matlabCalcForm != null) { writer.WriteLine("#" + this._matlabCalcForm.InputFile.Replace("\r\n", "\r\n#")); writer.WriteLine("# " + logMessage); writer.WriteLine("# " + str2); writer.WriteLine(""); } if (this.chbEnableIqCalibration.Checked) { writer.Write(this._calibrateCommandString); writer.WriteLine(""); } writer.Write(this._updateCommandString.ToString()); writer.Close(); stream.Close(); } break; } default: return; } }
private void tsrMainToolStrip_AmmeteringRequested(object sender, EventArgs e) { byte num = 0; if (this._chipType.Contains("Si10")) { num = 1; } this._series = this.createSeries(Task.ReadPowerSupply, 1, new LastReplyPrecondition[] { LastReplyPrecondition.Indication }, new byte[][] { new byte[] { 0x1f, num, 1 } }, new Telegram.Callback(this.currentReadEventHandler), new bool[] { true }); this._series[0].telegram.SenderInfo = new object[] { "MeasureCurrent" }; if (this._teleProcessor == null) { this._series[0].telegram.UserDataExt.addUserData("CmdName", "MeasureCurrent"); this._series[0].telegram.UserDataExt.addUserData("Task", Task.ReadPowerSupply); 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 if (this._teleProcessor.initSeries(this._series)) { this._teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } }
private void tsrMainToolStrip_IdentifyRequested(object sender, EventArgs e) { TelegramContainer telegramSeries = new TelegramContainer(); if (this._teleProcessor == null) { telegramSeries = this.createSeries(Task.IdentifyStart, 1, new LastReplyPrecondition[] { LastReplyPrecondition.ACK }, new byte[][] { new byte[] { 0x17, 1 } }, null, new bool[] { true }); this._commonTimerRole = TmrRole.LBIdentification; telegramSeries[0].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(telegramSeries[0].telegram.data.Buf, telegramSeries[0].telegram.data.NumItems)); this.sbProgressBar.Reset(); this.sbProgressBar.EndPoint = telegramSeries.Count; this.sbDeviceStatePane.Text = this.getStatusString((Task) telegramSeries[0].telegram.UserDataExt.StoredUserData["Task"]); if (this._adtRec.isSimuation) { this.logSimulationModeCommandSeries(telegramSeries); } else if (this._ioph.telegramSeriesFromMainWin(telegramSeries, SeriesExecutionState.Run, true) == -1) { MessageBox.Show("Device is BUSY!"); } } else { switch (this._commonTimerRole) { case TmrRole.None: telegramSeries = this.createSeries(Task.IdentifyStart, 1, new LastReplyPrecondition[] { LastReplyPrecondition.ACK }, new byte[][] { new byte[] { 0x17, 3 } }, null, new bool[] { true }); this._commonTimerRole = TmrRole.LBIdentification; this.tmrCommon.Enabled = true; break; case TmrRole.LBIdentification: { byte[][] teleData = new byte[1][]; byte[] buffer3 = new byte[2]; buffer3[0] = 0x17; teleData[0] = buffer3; telegramSeries = this.createSeries(Task.IdentifyStop, 1, new LastReplyPrecondition[] { LastReplyPrecondition.ACK }, teleData, null, new bool[] { true }); this._commonTimerRole = TmrRole.None; this.tmrCommon.Enabled = false; break; } default: this._commonTimerRole = TmrRole.None; this.tmrCommon.Enabled = false; return; } if (this._teleProcessor.initSeries(telegramSeries)) { this._teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } } }
private void tsrMainToolStrip_SetVoltageRequested(object sender, VoltageEventArgs e) { try { byte num = BitConverter.GetBytes(Convert.ToInt32((double) (255.0 - (309.0 / e.Voltage))))[0]; this._series = this.createSeries(Task.SetVoltage, 1, new LastReplyPrecondition[] { LastReplyPrecondition.ACK }, new byte[][] { new byte[] { 0x15, num } }, new Telegram.Callback(this.voltageExecutionEventHandler), new bool[] { true }); this._series[0].telegram.SenderInfo = new object[] { "SetVoltage" }; if (this._teleProcessor == null) { this._series[0].telegram.UserDataExt.addUserData("CmdName", "SetVoltage"); this._series[0].telegram.UserDataExt.addUserData("Task", Task.SetVoltage); 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 if (this._teleProcessor.initSeries(this._series)) { this._teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } } catch { } }
public int telegramFromMainWin(Telegram telegram) { TelegramContainer container = new TelegramContainer(); container.addTelegram(telegram); return telegramSeriesFromMainWin(container, SeriesExecutionState.Run, true); }
public int telegramSeriesFromMainWin(TelegramContainer container, SeriesExecutionState initialState, bool sendAcknowledgeTelegrams) { if (isBusy()) { GlobalServices.ErrMsg("telegramSeriesFromMainWin()", "Telegram series received in busy port handler state"); return -1; } _isSeries = true; _seriesFromWin = container; _seriesExecStat = initialState; _sendAcknowledge = sendAcknowledgeTelegrams; _isTelegramRequest = true; return 0; }
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, 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 logSimulationModeCommandSeries(TelegramContainer telegramSeries) { if (!this._adtRec.isSimuation) { _log.Error("logSimulationModeCommandSeries() called for a non simulation device!"); } else { this.sbProgressBar.Reset(); this.sbProgressBar.EndPoint = telegramSeries.Count; if ((telegramSeries.Count > 0) && telegramSeries[0].telegram.UserDataExt.hasStoredValue("Task")) { this.sbDeviceStatePane.Text = this.getStatusString((Task) telegramSeries[0].telegram.UserDataExt.StoredUserData["Task"]); } for (int i = 0; i < telegramSeries.Count; i++) { if (telegramSeries[i].telegram.UserDataExt.hasStoredValue("SentData")) { this.showLocalLog((string) telegramSeries[i].telegram.UserDataExt["SentData"]); } else { this.showLocalLog("> " + WDSConverters.ToHexString(telegramSeries[i].telegram.data.Buf, telegramSeries[i].telegram.data.NumItems)); } this.sbProgressBar.Step(); } if (telegramSeries.Count > 0) { this.showLocalLog(""); } this.sbDeviceStatePane.Text = this.getStatusString(Task.Idle); this.sbProgressBar.Reset(); } }
public int telegramSeriesFromMainWin(TelegramContainer container, SeriesExecutionState initialState, bool sendAcknowledgeTelegrams) { if (this.isBusy()) { this._isLastErrorBusy = true; return -1; } this._isLastErrorBusy = false; this._isSeries = true; this._seriesFromWin = container; this._seriesExecStat = initialState; this._sendAcknowledge = sendAcknowledgeTelegrams; this._isTelegramRequest = true; this._taskEvent.Set(); return 0; }
private void btnWrite_Click(object sender, EventArgs e) { try { if (_myDev.TxPufferSize < 1) { MessageBox.Show("This device can not Transmit data!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { byte[] sourceArray = new byte[0x100]; int length = 0; for (int i = 0; (i < 0xff) && (i < _myDev.TxPufferSize); i++) { if (!byte.TryParse(dgvTX.Rows[i].Cells[1].Value.ToString(), NumberStyles.HexNumber, (IFormatProvider) null, out sourceArray[i])) { break; } length++; } if (length < 1) { MessageBox.Show("No Data to send, please enter some data!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { byte[] destinationArray = new byte[length + 4]; destinationArray[0] = 0x10; destinationArray[1] = 0; destinationArray[2] = 0; destinationArray[3] = (byte) (BitConverter.GetBytes(_myDev.TxPufferAddress)[0] | 0x80); Array.ConstrainedCopy(sourceArray, 0, destinationArray, 4, length); TelegramContainer container = new TelegramContainer(); container = createSeries(Task.FIFOWrite, 1, new LastReplyPrecondition[] { LastReplyPrecondition.Indication }, new byte[][] { destinationArray }, new Telegram.Callback(processSimpleCommunicationReplyTelegram), false); container[0].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(container[0].telegram.data.Buf, container[0].telegram.data.NumItems)); if (_teleProcessor == null) { if (_ioph.telegramSeriesFromMainWin(container, SeriesExecutionState.Run, true) == -1) { MessageBox.Show("Device is BUSY!"); } } else if (_teleProcessor.initSeries(container)) { _teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } } } } catch (Exception exception) { MessageBox.Show("Error at Writing FIFO!\n" + exception.Message); } }
private void doPer(object sender, EventArgs e) { TelegramContainer tc = new TelegramContainer(); switch (this._perState) { case PerTestState.Stopped: break; case PerTestState.Start: { byte[][] bufferArray2 = new byte[2][]; bufferArray2[0] = new byte[] { 0x18, 4, 1 }; byte[] buffer = new byte[3]; buffer[0] = 0x18; buffer[1] = 4; bufferArray2[1] = buffer; byte[][] teleData = bufferArray2; tc = this.createSeries(Task.PER, 2, new LastReplyPrecondition[] { LastReplyPrecondition.ACK, LastReplyPrecondition.ACK }, teleData, null, new bool[2]); if (this._teleProcessor != null) { if (this._teleProcessor.initSeries(tc)) { this._perState = PerTestState.Wait; this.tmrPerTimer.Interval = this.ercPerTest.getTimeout(); this.tmrPerTimer.Enabled = true; this._triggeringFinished = false; this._teleProcessor.execTelegramSeries(); return; } MessageBox.Show("Device is BUSY!"); this._perState = PerTestState.Stopped; this.ercPerTest.setStartStopBtnText("Start"); return; } for (int i = 0; i < tc.Count; i++) { tc[i].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(tc[i].telegram.data.Buf, tc[i].telegram.data.NumItems)); } this._perState = PerTestState.Wait; this._triggeringFinished = false; this.tmrPerTimer.Interval = this.ercPerTest.getTimeout(); this.tmrPerTimer.Enabled = true; this.sbProgressBar.Reset(); this.sbProgressBar.EndPoint = tc.Count; this.sbDeviceStatePane.Text = this.getStatusString((Task) tc[0].telegram.UserDataExt.StoredUserData["Task"]); if (this._adtRec.isSimuation) { this.logSimulationModeCommandSeries(tc); return; } if (this._ioph.telegramSeriesFromMainWin(tc, SeriesExecutionState.Run, true) != -1) { break; } MessageBox.Show("Device is BUSY!"); this._perState = PerTestState.Stopped; this.ercPerTest.setStartStopBtnText("Start"); return; } case PerTestState.Wait: { if (!this._triggeringFinished) { _log.Error("Initiating double timeout waiting, due to the slow communication."); return; } this.tmrPerTimer.Enabled = false; byte[][] bufferArray3 = new byte[2][]; byte[] buffer2 = new byte[7]; buffer2[0] = 0x10; buffer2[3] = 0x20; bufferArray3[0] = buffer2; bufferArray3[1] = new byte[] { 0x10, 0, 0, 0x44, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; tc = this.createSeries(Task.ReadInterruptStatus, 2, new LastReplyPrecondition[] { LastReplyPrecondition.Indication, LastReplyPrecondition.Indication }, bufferArray3, new Telegram.Callback(this.processInterruptStatusForPerRepTele), new bool[2]); tc[1].telegram.UserDataExt.addUserData("PerRxPacketInfo", null); if (this._teleProcessor != null) { if (this._teleProcessor.initSeries(tc)) { this._teleProcessor.execTelegramSeries(); this._perState = PerTestState.Read; return; } MessageBox.Show("Device is BUSY!"); this._perState = PerTestState.Stopped; this.ercPerTest.setStartStopBtnText("Start"); return; } for (int j = 0; j < tc.Count; j++) { tc[j].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(tc[j].telegram.data.Buf, tc[j].telegram.data.NumItems)); } this.sbProgressBar.Reset(); this.sbProgressBar.EndPoint = tc.Count; this.sbDeviceStatePane.Text = this.getStatusString((Task) tc[0].telegram.UserDataExt.StoredUserData["Task"]); if (this._adtRec.isSimuation) { this.logSimulationModeCommandSeries(tc); return; } if (this._ioph.telegramSeriesFromMainWin(tc, SeriesExecutionState.Run, true) == -1) { MessageBox.Show("Device is BUSY!"); this._perState = PerTestState.Stopped; this.ercPerTest.setStartStopBtnText("Start"); return; } this._perState = PerTestState.Read; return; } case PerTestState.Read: { if (sender == null) { break; } byte num3 = (byte) sender; if ((num3 & 0x10) != 0x10) { this.ercPerTest.packetReceived(false); break; } this.ercPerTest.packetReceived(true); return; } default: return; } }
private void tsrMainToolStrip_AmmeteringRequested(object sender, EventArgs e) { byte num = 0; if (_chipType.Contains("Si10")) { num = 1; } TelegramContainer container = new TelegramContainer(); if (_ioph is IOPH_DCP) { container = createSeries(Task.ReadCurrent, 1, new LastReplyPrecondition[] { LastReplyPrecondition.Indication }, new byte[][] { new byte[] { 0x1f } }, new Telegram.Callback(processReadCurrentReplyTelegram), true); } else { container = createSeries(Task.ReadCurrent, 1, new LastReplyPrecondition[] { LastReplyPrecondition.Indication }, new byte[][] { new byte[] { 0x1f, num, 1 } }, new Telegram.Callback(processReadCurrentReplyTelegram), true); } container[0].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(container[0].telegram.data.Buf, container[0].telegram.data.NumItems)); statusBarPanel4.EndPoint = container.Count; if (_teleProcessor == null) { if (_ioph.telegramSeriesFromMainWin(container, SeriesExecutionState.Run, true) == -1) { MessageBox.Show("Device is BUSY!"); } } else if (_teleProcessor.initSeries(container)) { _teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } }
private void loadBatchCommands(string batchCommands) { string str; TelegramContainer telegramSeries = new TelegramContainer(); TelegramContainerItem[] itemArray = SPI_tool_PRO2.createTelegramsFromBatchString(batchCommands, this._ioph, this, false, this._registerDescriptor, this._chipApiDescriptor, out str); if (itemArray == null) { MessageBox.Show("Invalid Command, cannot execute!"); } else { for (int i = 0; i < itemArray.Length; i++) { itemArray[i].telegram.clearEventHandler(); itemArray[i].telegram.UserDataExt.addUserData("Task", Task.PER); telegramSeries.addTelegramContainerItem(itemArray[i]); } if (this._teleProcessor == null) { for (int j = 0; j < telegramSeries.Count; j++) { telegramSeries[j].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(telegramSeries[j].telegram.data.Buf, telegramSeries[j].telegram.data.NumItems)); } this.sbProgressBar.Reset(); this.sbProgressBar.EndPoint = telegramSeries.Count; this.sbDeviceStatePane.Text = this.getStatusString((Task) telegramSeries[0].telegram.UserDataExt.StoredUserData["Task"]); if (this._adtRec.isSimuation) { this.logSimulationModeCommandSeries(telegramSeries); } else if (this._ioph.telegramSeriesFromMainWin(telegramSeries, SeriesExecutionState.Run, true) == -1) { MessageBox.Show("Device is BUSY!"); } } else if (this._teleProcessor.initSeries(telegramSeries)) { this._teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } } }
public bool initSeries(TelegramContainer tc) { if (_mainWin._ioph.isBusy()) { return false; } _telegramSeries = tc; _mainWin.statusBarPanel4.Reset(); _mainWin.statusBarPanel4.EndPoint = _telegramSeries.Count; return true; }
public int telegramSeriesFromMainWin(TelegramContainer container, SeriesExecutionState initialState, bool sendAcknowledgeTelegrams) { if (this.isBusy()) { GlobalServices.ErrMsg("telegramSeriesFromMainWin()", "Telegram series received in busy port handler state"); return -1; } this._isSeries = true; this._seriesFromWin = container; this._seriesExecStat = initialState; this._sendAcknowledge = sendAcknowledgeTelegrams; this._taskEvent.Set(); return 0; }