public FormMain() { InitializeComponent(); // Configure serial driver //serial.ReadTimeout = 500; // 500ms //serial.WriteTimeout = 500; // 500ms SetThreadCultureInfo(); // Select CultureInfo for this thread StartupConfigClass.Init(); ConfigClass.UpdateWorkingDeviceAddress(0x31); // Select addr 0x31 as default this.Text = "Charger Controller DEV_ADDR=" + ConfigClass.deviceAddr.ToString() + " GainCH0=" + ConfigClass.deviceGainCH0 + " GainCH1=" + ConfigClass.deviceGainCH1; #region Data Download // Initialize all controlls from DataDownload tab comboBoxDataDownloadSerial.Items.AddRange(SerialPort.GetPortNames()); #endregion com = new CommandFormerClass(ConfigClass.startSeq, ConfigClass.deviceAddr); //DataGridHelperClass.PopulateCapDataGridNew(ConfigClass.DEV_POOL_NEW_1, dataGridViewCap1); DataGridHelperClass.PopulateCapDataGrid(ConfigClass.DevPoolCap1, dataGridViewCap1); DataGridHelperClass.PopulateCapDataGrid(ConfigClass.DevPoolCap2, dataGridViewCap2); TabDebugSetDefaultValues(); }
private void buttonDataDownloadMultiDownload35A_Click(object sender, EventArgs e) { // Get unique row numbers from datagrid List <int> uniqueRows = DataGridHelperClass.ExtractSelectedRowNumbers(dataGridViewDataDownloadMesHeaders); // Now check if there are 2 rows selected if (uniqueRows.Count != 2) { MessageBox.Show("Select exactly 2 rows!!!"); return; } // Now form all data that needs to be sent // Update label labelMultiDownload.Text = "Pending!"; labelMultiDownload.ForeColor = System.Drawing.Color.Black; // First select selected header MeasurementHeaderClass header; // Make key value pairs of addresses and data length that needs to be read var kvList = new List <Tuple <int, int> >(); foreach (var index in uniqueRows) { header = headers[index]; kvList.Add(new Tuple <int, int>(header.headerAddress, header.numOfPoints * 2 + ConfigClass.HEADER_LENGTH)); } if (!MultiDownloader.Download(kvList, MultiSuccess35A, MultiFail)) { MessageBox.Show("Request not sent!"); } }
/// <summary> /// Fetch all selected addresses and send command sequence to all of them with given delay in seconds /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void buttonCap1SendTestSeq_Click(object sender, EventArgs e) { int delay; // First parse float value try { delay = int.Parse(textBoxCap1DebugDelay.Text); delay *= 1000; // Delay is in ms and user input is in seconds } catch (Exception) { MessageBox.Show("Insert valid float value!"); return; } DataGridHelperClass.ClearStatusColorsFromDataGrid(dataGridViewCap1); list = DataGridHelperClass.GetSelectedIndexes(dataGridViewCap1); foreach (var index in list) { ConfigClass.UpdateWorkingDeviceAddress(index); this.Text = "Charger Controller DEV_ADDR=" + ConfigClass.deviceAddr.ToString() + " GainCH0=" + ConfigClass.deviceGainCH0 + " GainCH1=" + ConfigClass.deviceGainCH1; FormCustomConsole.WriteLineWithConsole("\r\n ------------------------"); // form test sequence com = new CommandFormerClass(ConfigClass.startSeq, ConfigClass.deviceAddr); AppendTestSequence(); var data = com.GetFinalCommandList(); labelDebugBytesUsed.Text = "Bytes Used : " + data.Length; try { FormCustomConsole.WriteLineWithConsole("\r\nSending commands to ID:" + index + "\r\n"); SerialDriver.Send(data, Cap1ExecuteSuccessCallback, Cap1ExecuteFailCallback); } catch (Exception) { MessageBox.Show("Problem occured while trying to send data to serial port!"); FormCustomConsole.WriteLine("------- Commands not sent --------\r\n"); return; } // Reset everything com = new CommandFormerClass(ConfigClass.startSeq, ConfigClass.deviceAddr); textBoxDebugInstructionPool.Text = ""; // Wait delay async await Task.Delay(delay); } Thread t = new Thread(() => { MessageBox.Show("******All commands sent!*****", DateTime.Now.ToString()); }); t.IsBackground = true; t.Start(); FormCustomConsole.WriteLineWithConsole("\r\n ******All commands sent!*****"); }
private void buttonCap1GetVoltage_Click(object sender, EventArgs e) { var list = DataGridHelperClass.GetSelectedIndexes(dataGridViewCap1); if (list.Count == 0) { return; // Ignore if none device is selected } FormMultiVoltageViewer f = new FormMultiVoltageViewer(list, this); f.Show(); }
public void ChangeColorOnDatagrid(int index, Color col) { DataGridViewCell cell; if (index < ConfigClass.cap2AddrOffset) { cell = DataGridHelperClass.FindCellWithID(dataGridViewCap1, index); } else { cell = DataGridHelperClass.FindCellWithID(dataGridViewCap2, index); } if (cell != null) { cell.Style.BackColor = col; } else { throw new Exception("Cell not found in FormMain.ChangeColorOnDataGrid()"); } }
public static bool SendMulti(DataGridView _dg, FormMain f, Action <CommandFormerClass> _testSeq) { if (busy == true) { FormCustomConsole.WriteLineWithConsole("Multi sender busy \r\n"); return(false); } busy = true; dg = _dg; form = f; testSeq = _testSeq; DataGridHelperClass.ClearStatusColorsFromDataGrid(dg); forceStop = false; cap1IndexList = DataGridHelperClass.GetSelectedIndexes(dg); cap1IndexListCount = 0; // Send first to start a sequence, take care that first time sender is main (GUI) thread other times is thread from serial driver module if (cap1IndexListCount < cap1IndexList.Count) // Prevent stupid things { Cap1SendToNextDev(cap1IndexList[cap1IndexListCount++], 10); } return(true); }
private void buttonCap1CheckSelected_Click(object sender, EventArgs e) { DataGridHelperClass.ActivateSelectedCheckboxes(dataGridViewCap1); }
private void buttonCap1DeselectAll_Click(object sender, EventArgs e) { DataGridHelperClass.DeselectAll(dataGridViewCap1); }