private void buttonDataRecTask_Click(object sender, EventArgs e)
        {
            byte ch;
            byte op;
            uint prescaler;
            uint targetPoints;

            // Parse input fields
            try
            {
                ch           = InputValidatorHelperClass.GetChModeFromComboBox(comboBoxDataRecTaskCh);
                op           = InputValidatorHelperClass.GetOperationModeFromComboBox(comboBoxDataRecTaskOpMode);
                prescaler    = Convert.ToUInt32(textBoxPrescaler.Text);
                targetPoints = Convert.ToUInt32(textBoxTargetPoints.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Wrong Values for Data Recorder!");
                return;
            }

            // Values are valid, add command to the list
            com.AppendDataRecorderTask(ch, op, prescaler, targetPoints, DateTime.Now);

            // Append to display
            textBoxInstructionPool.Text += "DataRecTask(" + comboBoxDataRecTaskCh.Text + ", " + comboBoxDataRecTaskOpMode.Text + " ," + prescaler +
                                           ", " + targetPoints + ") \r\n";
        }
Example #2
0
        private void buttonRecordTask_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    // (uint8_t chMode, uint8_t operationMode, uint32_t prescaler, uint32_t targetPoints)
            //    int chMode = Convert.ToInt32(textBoxChMode.Text);
            //    int opMode = Convert.ToInt32(textBoxOpMode.Text);
            //    int prescaler = Convert.ToInt32(textBoxPrescaler.Text);
            //    int targetPoints = Convert.ToInt32(textBoxTargetPoints.Text);
            //    // Check here for invalid values

            //    // Send command to erase measurement header
            //    List<byte> sb = new List<byte>();

            //    sb.Add(startSeq);
            //    sb.Add(deviceAddr);
            //    // Append message length, and include checksum
            //    sb.Add(0);
            //    sb.Add(13);
            //    sb.Add(commandStartRecorder); //1
            //    // Convert values to separate bytes
            //    byte bChMode = CustomConvertorClass.ConvertIntTo1Byte(chMode); // 2
            //    byte bOpMode = CustomConvertorClass.ConvertIntTo1Byte(opMode); // 3
            //    byte[] bPrescaler = CustomConvertorClass.ConvertIntTo4Bytes(prescaler); //  7
            //    byte[] bTargetPoints = CustomConvertorClass.ConvertIntTo4Bytes(targetPoints); // 11

            //    sb.Add(bChMode);
            //    sb.Add(bOpMode);
            //    sb.AddRange(bPrescaler);
            //    sb.AddRange(bTargetPoints);

            //    // Now calculate and append checksum
            //    UInt16 csum = ChecksumClass.CalculateChecksum(sb.ToArray());
            //    byte[] bcsum = CustomConvertorClass.ConvertIntTo2BytesBE(csum);
            //    sb.AddRange(bcsum); // 2B

            //    serialPort1.Write(sb.ToArray(), 0, sb.Count);
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}

            // First parse values from dropdown list



            try
            {
                int chMode       = InputValidatorHelperClass.GetChModeFromComboBox(comboBoxChannelSel);
                int opMode       = InputValidatorHelperClass.GetOperationModeFromComboBox(comboBoxOperationSel);
                int prescaler    = Convert.ToInt32(textBoxPrescaler.Text);
                int targetPoints = Convert.ToInt32(textBoxTargetPoints.Text);

                CommandFormerClass cm = new CommandFormerClass(startSeq, deviceAddr);
                cm.AppendDataRecorderTask((byte)chMode, (byte)opMode, (uint)prescaler, (uint)targetPoints, DateTime.Now);

                var data = cm.GetFinalCommandList();
                serial.Write(data, 0, data.Length);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }