/// <summary>
        /// Send commands based on textfields to selected cells in dataGridView
        /// </summary>
        public async void SendCommandsToSelectedCells()
        {
            // Get selected devices
            var list = ExtractSelectedCheckboxesFromDataGridView(_dgv);

            if (list.Count == 0)
            {
                MessageBox.Show("Select one or more devices first!");
                return;
            }
            // Return cell painting to default

            foreach (var item in list)
            {
                ConfigClass.UpdateWorkingDeviceAddress(item);
                // Send Commands
                // Paint the cell

                FormCustomConsole.WriteLineWithConsole("Sending to ID:" + item);
                // Wait
                await Task.Delay(1000);

                FormCustomConsole.WriteLineWithConsole("ID:" + item + " finished");
            }
        }
        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 GetVoltage(int devId, int delayMs)
        {
            ConfigClass.UpdateWorkingDeviceAddress(devId);
            form.Text = "Charger Controller   DEV_ADDR=" + ConfigClass.deviceAddr.ToString() + "     GainCH0=" + ConfigClass.deviceGainCH0 + "  GainCH1=" + ConfigClass.deviceGainCH1;

            // Send command to get last ADC sample
            FormCustomConsole.WriteLineWithConsole("\r\n ------------------------");
            // form test sequence
            var com = new CommandFormerClass(ConfigClass.startSeq, ConfigClass.deviceAddr);

            com.GetLastADCSample(1);
            var data = com.GetFinalCommandList();

            try
            {
                Thread.Sleep(delayMs);
                if (forceStop)
                {
                    FormCustomConsole.WriteLineWithConsole("Multi sending aborted\r\n");
                    busy = false;
                    return;
                }
                FormCustomConsole.WriteLineWithConsole("\r\nSending commands to ID:" + devId + "\r\n");
                if (!SerialDriver.Send(data, SuccessCallback, FailCallback))
                {
                    Console.WriteLine("Serial Driver busy!!");
                    busy = false;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Problem occured while trying to send data to serial port!");
                FormCustomConsole.WriteLine("------- Commands not sent --------\r\n");
            }
        }
Exemple #4
0
        private void buttonDataDownloadAddrSelect_Click(object sender, EventArgs e)
        {
            // Addresses are ranging from 1 to 116
            int addr;

            try
            {
                addr = Convert.ToInt32(textBoxDataDownloadAddrSelect.Text);
                if (addr < 1 || addr > 116)
                {
                    throw new Exception();
                }
                ConfigClass.UpdateWorkingDeviceAddress(addr);
                buttonDebugResetInstructions_Click(this, EventArgs.Empty);
                // Reset DataGrid
                dataGridViewDataDownloadMesHeaders.DataSource = null;
                dataGridViewDataDownloadMesHeaders.Rows.Clear();
                dataGridViewDataDownloadMesHeaders.Refresh();
                this.Text = "Charger Controller   DEV_ADDR=" + ConfigClass.deviceAddr.ToString() + "     GainCH0=" + ConfigClass.deviceGainCH0 + "  GainCH1=" + ConfigClass.deviceGainCH1;
            }
            catch (Exception)
            {
                MessageBox.Show("Please enter number ranging from 1 to 116");
            }
        }
Exemple #5
0
        /// <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!*****");
        }
        public async void ReadMeasurementsFromSelectedCells()
        {
            // Get selected devices
            var list = ExtractSelectedCheckboxesFromDataGridView(_dgv);

            if (list.Count == 0)
            {
                MessageBox.Show("Select one or more devices first!");
                return;
            }
            foreach (var item in list)
            {
                ConfigClass.UpdateWorkingDeviceAddress(item);

                Console.WriteLine("Sending to ID:" + item);
                // Wait
                await Task.Delay(1000);

                Console.WriteLine("ID:" + item + " finished");
            }
        }