//*********************** ЗАГРУЗКА НЕПОСРЕДСТВЕННО ОСЦИЛЛОГРАММ ******************************************// //********************************************************************************************************// private void LoadButtonClick(object sender, EventArgs e) { int t = 0; try { t = (int)(sender as Button).Tag; } catch { return; } AskScopeForm askForm = new AskScopeForm(Texts, oscilTitls[t], oscilsStatus[t]); if (askForm.ShowDialog() != System.Windows.Forms.DialogResult.Yes) { return; } if (askForm.ScopeDialogResult == ScopeDialogResults.Clear) { serialPort.SetDataRTU((ushort)(ScopeSysType.OscilStatusAddr + t), null, RequestPriority.Normal, 0); return; } LoadOscDataForm loadOscDataForm = new LoadOscDataForm(serialPort, oscilTitls[t], scopeConfig, t, Texts); loadOscDataForm.ShowDialog(); }
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { for (eventIndex = 0; eventIndex < eventCount; eventIndex++) { eventData.Add(new ushort[blockCount * 32]); serialPort.SetDataRTU(loadEventAddr, serialPort_DataReceived, RequestPriority.Normal, (ushort)(eventIndex + 1)); waitResponce.WaitOne(); if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } for (blockIndex = 0; blockIndex < blockCount; blockIndex++) { serialPort.GetDataRTU((ushort)(startDataAddr + 32 * blockIndex), 32, serialPort_LoadDataReceived); waitResponce.WaitOne(); if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } } Array.Copy(loadEventLine, 0, eventData[eventIndex], 0, blockCount * 32); backgroundWorker.ReportProgress(eventIndex + 1); } e.Result = true; }
private void writeBtn_Click(object sender, EventArgs e) { ushort w1 = 0; ushort w2 = 0; try { ulong u = ConvertFuncs.StrToULong(longTextBox.Text); FloatStruct fs = new FloatStruct(); fs.ULong = u; w1 = fs.Word1; w2 = fs.Word2; } catch { ErrorMessage(texts[9]); return; } ushort Addr = 0; if (!CheckAddr(out Addr)) { ErrorMessage(texts[6]); return; } serialPort.SetDataRTU(Addr, WriteDataRecieved, RequestPriority.Normal, w1, w2); }
private void WritePartConfigToSystem() { ushort[] partParam = new ushort[8]; int i; for (i = 0; i < 8; i++) { partParam[i] = newOscillConfig[i + writeConfigStep * 8]; } serialPort.SetDataRTU((ushort)(0x20 + ScopeSysType.ParamLoadDataAddr + writeConfigStep * 8), EndWriteConfig, RequestPriority.High, partParam); }
//Установить private void SetOutput(bool mode, string addrOutput) //mode: false - unset, true - set { var addr = ushort.Parse(addrOutput.Substring(2), NumberStyles.HexNumber); CalcDigitMasks(_testListOutput[addrOutput], addrOutput, mode, out var maskOr, out var maskAnd); var param = new { Mode = mode, Addr = addr, MaskOr = maskOr, MaskAnd = maskAnd }; _serialPort.SetDataRTU((ushort)(addr + 1), AnswerSet, param, maskOr, maskAnd); }
public static void SendSetTimeRequest(byte SlaveAddr, AsynchSerialPort SerialPort, TimeConfig CurrentConfig, int Hour, int Min, int Sec, int Day, int Month, int Year) { if (CurrentConfig.TimeFormat == TimeFormats.STMFormat) { ushort[] paramRTU = new ushort[4]; paramRTU[0] = (ushort)(((Month.ToBCD() & 0x1F) << 8) | (Day.ToBCD() & 0x3F)); paramRTU[1] = (ushort)Year.ToBCD(); paramRTU[2] = (ushort)(((Min.ToBCD() & 0xFF) << 8) | (Sec.ToBCD() & 0xFF)); paramRTU[3] = (ushort)(Hour.ToBCD() | 0x0100); SerialPort.SetDataRTU(SlaveAddr, CurrentConfig.STMProcAddr1_1, null, RequestPriority.Normal, paramRTU); } else if (CurrentConfig.TimeFormat == TimeFormats.ADSPFormat) { ushort[] paramRTU = new ushort[3]; paramRTU[0] = Sec.ToBCD(); paramRTU[1] = Min.ToBCD(); paramRTU[2] = Hour.ToBCD(); SerialPort.SetDataRTU(SlaveAddr, CurrentConfig.SetAddr, null, RequestPriority.Normal, paramRTU); paramRTU[0] = Day.ToBCD(); paramRTU[1] = Month.ToBCD(); paramRTU[2] = Year.ToBCD(); SerialPort.SetDataRTU(SlaveAddr, (ushort)(CurrentConfig.SetAddr + 4), null, RequestPriority.Normal, paramRTU); SerialPort.SetDataRTU(SlaveAddr, CurrentConfig.AddrSetTime, null, RequestPriority.Normal, 1); } if (CurrentConfig.TimeFormat == TimeFormats.RTCFormat) { ushort[] paramRTU = new ushort[4]; paramRTU[0] = (ushort)(((Month.ToBCD() & 0x1F) << 8) | (Day.ToBCD() & 0x3F)); paramRTU[1] = (ushort)Year.ToBCD(); paramRTU[2] = (ushort)(((Min.ToBCD() & 0x7F) << 8) | (Sec.ToBCD() & 0x7F)); paramRTU[3] = (ushort)(Hour.ToBCD() & 0x3F); SerialPort.SetDataRTU(SlaveAddr, CurrentConfig.SetAddr, null, RequestPriority.Normal, paramRTU); } }
//***************************ЗАПИСЬ ДАННЫХ****************************************************************// //********************************************************************************************************// private void writeBtn1_Click(object sender, EventArgs e) { // if (portBusy) return; double f; if (!double.TryParse(textBox1.Text, out f)) { MessageBox.Show("Неправильно задан параметр!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((f > 120) || (f < 80)) { MessageBox.Show("Неправильно задан параметр!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ushort[] w = new ushort[1] { (ushort)(f * 40.96) }; // portBusy = true; serialPort.SetDataRTU(0x015C, WriteDataRecieved, RequestPriority.Normal, w); }
//**************************************ОБМЕН СИГНАЛАМИ***********************************************************// //****************************************************************************************************************// private void timer1_Tick(object sender, EventArgs e) { if (!serialPort.IsOpen) { return; } if (!this.Visible) { return; } if (portBusy) { return; } portBusy = true; serialPort.SetDataRTU((ushort)(startAddr + 1), null, RequestPriority.Normal, maskOR, maskAND); serialPort.GetDataRTU((ushort)(startAddr + 3), 1, DataRecieved); }
void SendSecondRequest() { ushort[] writeArr = new ushort[6]; UInt32 m; writeArr[0] = 0x0001; writeArr[1] = ScopeSysType.ParamLoadDataAddr; m = CalcMemoryAddr(loadOscNum); writeArr[2] = (ushort)(m & 0x3FFF); m = m & 0x003FC000; m = m >> 6; m = m & 0xFFFF; m = m | 0x8001; writeArr[3] = (ushort)m; writeArr[4] = 32; writeArr[5] = 1; serialPort.SetDataRTU(ScopeSysType.ParamLoadConfigAddr, EndLoadStepTwo, requestPriority, writeArr); }
void LoadOscDataRequest() { if (stopRequests) { return; } if (!serialPort.IsOpen) { this.Close(); return; } switch (loadOscDataStep) { //Загрузка стартового адреса case 0: { serialPort.GetDataRTU((ushort)(ScopeSysType.LoadOscilStartAddr + loadOscNum), 1, EndLoadStepOne, RequestPriority.High); } break; //Загрузка данных case 1: { ushort[] writeArr = new ushort[6]; UInt32 m; writeArr[0] = 0x0001; writeArr[1] = ScopeSysType.ParamLoadDataAddr; m = CalcMemoryAddr(loadOscNum); writeArr[2] = (ushort)(m & 0x3FFF); m = m & 0x003FC000; m = m >> 6; m = m & 0xFFFF; m = m | 0x8001; writeArr[3] = (ushort)m; writeArr[4] = 32; writeArr[5] = 1; serialPort.SetDataRTU(ScopeSysType.ParamLoadConfigAddr, EndLoadStepTwo, RequestPriority.High, writeArr); } break; case 2: { serialPort.GetDataRTU(ScopeSysType.ParamLoadDataAddr, 32, EndLoadStepThree, RequestPriority.High); } break; } }
//***************************ЗАПИСЬ ДАННЫХ****************************************************************// //********************************************************************************************************// private void writeBtn_Click(object sender, EventArgs e) { if (portBusy) { return; } if (!CheckAddr()) { MessageBox.Show(appTexts.ParameterName(10), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!CheckValue()) { MessageBox.Show(appTexts.ParameterName(49), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } portBusy = true; serialPort.SetDataRTU(addr, WriteDataRecieved, RequestPriority.Normal, value); }
private void NewWriteRequest() { ushort[] writePartBuffer = new ushort[16]; Array.Copy(systemProfile, loadIndex * 16, writePartBuffer, 0, 16); serialPort.SetDataRTU((ushort)(startAddr + loadIndex * 16), WriteDataRecieved, RequestPriority.Normal, writePartBuffer); }