Ejemplo n.º 1
0
        private void buttonDebugDataRecTask_Click(object sender, EventArgs e)
        {
            byte ch;
            byte op;
            uint prescaler;
            uint targetPoints;

            // Parse input fields
            try
            {
                ch           = InputValidatorHelperClass.GetChModeFromComboBox(comboBoxDebugDataRecTaskCh);
                op           = InputValidatorHelperClass.GetOperationModeFromComboBox(comboBoxDebugDataRecTaskOpMode);
                prescaler    = Convert.ToUInt32(textBoxDebugPrescaler.Text);
                targetPoints = Convert.ToUInt32(textBoxDebugTargetPoints.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
            textBoxDebugInstructionPool.Text += "DataRecTask(" + comboBoxDebugDataRecTaskCh.Text + ", " + comboBoxDebugDataRecTaskOpMode.Text + " ," + prescaler +
                                                ", " + targetPoints + ") \r\n";
            FormCustomConsole.WriteLine("DataRecTask(" + comboBoxDebugDataRecTaskCh.Text + ", " + comboBoxDebugDataRecTaskOpMode.Text + " ," + prescaler +
                                        ", " + targetPoints + ")");
        }
Ejemplo n.º 2
0
        // NOT USED, TESTING CODE
        private static void DeviceAvailabilityInit2()
        {
            // Init configurations for both capacitors
            // Capacitor 1 init
            string fileName = "AvailabiltyConf1.xml";
            string fullPath = path + fileName;

            if (File.Exists(fullPath))
            {
                try
                {
                    using (var stream = new FileStream(fileName, FileMode.Open))
                    {
                        XmlSerializer xml = new XmlSerializer(typeof(DeviceAvailability));
                        // No need to asign result, static reference will be updated in constructor
                        ConfigClass.DEV_POOL_NEW_1 = (DeviceAvailability)xml.Deserialize(stream);
                    }
                }
                catch (Exception)
                {
                    //ConfigClass.DevPoolCap1 = new DevicePoolSerializableClass(ConfigClass.cap1AddrOffset); // Force default values
                    FormCustomConsole.WriteLine("Problem occurred while initializing availability for Capacitor 1, default values are applied");
                    Console.WriteLine("Problem occurred while initializing availability for Capacitor 1, default values are applied");
                    System.Windows.Forms.MessageBox.Show("Problem occurred while initializing availability for Capacitor 1, default values are applied");
                }
            }
            else
            {
            }
        }
Ejemplo n.º 3
0
        private void buttonDebugCompositeFinishDisch100A_Click(object sender, EventArgs e)
        {
            UInt32 ms;

            try
            {
                ms = Convert.ToUInt32(textBoxDebugCompositeMsDelay.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Insert valid number for delay!");
                return;
            }

            com.AppendDischarger100AOffS1();
            textBoxDebugInstructionPool.Text += "Discharger100AOff S1\r\n";
            FormCustomConsole.WriteLine("Discharger100AOff S1");

            com.AppendWaitForMs(ms);
            textBoxDebugInstructionPool.Text += "Delay in ms: " + ms.ToString() + "\r\n";
            FormCustomConsole.WriteLine("Delay in ms: " + ms.ToString());

            com.AppendDischarger100AOffS2();
            textBoxDebugInstructionPool.Text += "Discharger100AOff S2\r\n";
            FormCustomConsole.WriteLine("Discharger100AOff S2");
        }
        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");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// When measurement data is downloaded (measurement header included), this fucntion should be called for processing and display
        /// </summary>
        /// <param name="b">Message containing header + data</param>
        private void ProcessReceivedMeasurements(byte[] b)
        {
            FormCustomConsole.WriteLine("in ProcessReceivedMeasurements, read bytes: " + (b.Length - ConfigClass.HEADER_LENGTH - 2)); // -2 for data len

            int channel = b[15];

            if (channel == 0 || channel == 1)
            {
                this.Invoke(new Action(() =>
                {
                    FormMeasurementSingleChannelPresenter fdp = new FormMeasurementSingleChannelPresenter(b);
                    fdp.Show();
                }));
            }
            else if (channel == 2)
            {
                this.Invoke(new Action(() =>
                {
                    FormMeasurementDualChannelPresenter fdp = new FormMeasurementDualChannelPresenter(b);
                    fdp.Show();
                }));
            }
            else
            {
                FormCustomConsole.WriteLine("Channel not recognized");
            }
        }
Ejemplo n.º 6
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!*****");
        }
Ejemplo n.º 7
0
        private void buttonDebugSetCutoffValue_Click(object sender, EventArgs e)
        {
            float value = float.Parse(textBoxDebugSetCutoffValue.Text);
            float gain  = ConfigClass.deviceGainCH1;

            value = value / gain;
            com.SetCutoffValueCH1(value);

            textBoxDebugInstructionPool.Text += "SetCutoffValue(" + value + ") " + textBoxDebugSetCutoffValue.Text + "\r\n";
            FormCustomConsole.WriteLine("SetCutoffValue(" + value + ")" + textBoxDebugSetCutoffValue.Text);
        }
Ejemplo n.º 8
0
        private void buttonDebugSetCriticalLow_Click(object sender, EventArgs e)
        {
            byte  ch;
            float value, gain;

            if (checkBoxDebugUseDefGain.Checked)
            {
                // Use gain that is inferred from configuration file
                try
                {
                    ch    = InputValidatorHelperClass.GetChModeFromComboBox(comboBoxDebugSetCritLow);
                    value = float.Parse(textBoxDebugSetCriticalLow.Text);
                    if (ch == 0)
                    {
                        gain = ConfigClass.deviceGainCH0;
                    }
                    else
                    {
                        gain = ConfigClass.deviceGainCH1;
                    }
                    value = value / gain;
                }
                catch (Exception)
                {
                    MessageBox.Show("Insert valid values!");
                    return;
                }
            }
            else
            {
                // Use gain that is parsed from textbox
                try
                {
                    ch    = InputValidatorHelperClass.GetChModeFromComboBox(comboBoxDebugSetCritLow);
                    value = float.Parse(textBoxDebugSetCriticalLow.Text);
                    gain  = float.Parse(textBoxDebugSetCriticalLowGain.Text);
                    value = value / gain;
                }
                catch (Exception)
                {
                    MessageBox.Show("Insert valid values!");
                    return;
                }
            }


            com.AppendSetCriticalLow(value, ch);
            textBoxDebugInstructionPool.Text += "SetCriticalLow(" + value + ", " + comboBoxDebugSetCritLow.Text + ")\r\n";
            FormCustomConsole.WriteLine("SetCriticalLow(" + value + ", " + comboBoxDebugSetCritLow.Text + ")");
        }
Ejemplo n.º 9
0
        private void buttonDebugPinSetLow_Click(object sender, EventArgs e)
        {
            byte pinNum;

            try
            {
                pinNum = Convert.ToByte(textBoxDebugPinSetLow.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Insert valid value!");
                return;
            }
            com.AppendPinSetLow(pinNum);
            textBoxDebugInstructionPool.Text += "PinSetLow(" + pinNum + ")\r\n";
            FormCustomConsole.WriteLine("PinSetLow(" + pinNum + ")");
        }
Ejemplo n.º 10
0
        private void buttonDebugLedOff_Click(object sender, EventArgs e)
        {
            byte ledNum;

            try
            {
                ledNum = Convert.ToByte(textBoxDebugLedOff.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Insert valid value!");
                return;
            }
            com.AppendLedOff(ledNum);
            textBoxDebugInstructionPool.Text += "LedOff(" + ledNum + ")\r\n";
            FormCustomConsole.WriteLine("LedOff(" + ledNum + ")");
        }
Ejemplo n.º 11
0
        private void buttonDebugWaitForMs_Click(object sender, EventArgs e)
        {
            UInt32 ms;

            try
            {
                ms = Convert.ToUInt32(textBoxDebugWaitInMiliseconds.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Insert valid number for delay!");
                return;
            }

            com.AppendWaitForMs(ms);
            textBoxDebugInstructionPool.Text += "Delay in ms: " + ms.ToString() + "\r\n";
            FormCustomConsole.WriteLine("Delay in ms: " + ms.ToString());
        }
Ejemplo n.º 12
0
        private void buttonDebugDiasbleCriticalHigh_Click(object sender, EventArgs e)
        {
            byte ch;

            try
            {
                ch = InputValidatorHelperClass.GetChModeFromComboBox(comboBoxDebugDisableCritHigh);
            }
            catch (Exception)
            {
                MessageBox.Show("Insert valid values!");
                return;
            }
            UInt16 temp = 0x8000;

            com.AppendSetCriticalHigh(temp, ch);
            textBoxDebugInstructionPool.Text += "DisableCriticalHigh(" + comboBoxDebugDisableCritHigh.Text + ")\r\n";
            FormCustomConsole.WriteLine("DisableCriticalHigh()\r\n");
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Measurement info is received, decode data and send requests to read measurement headers
        /// </summary>
        /// <param name="b"></param>
        private void ProcessGetMeasurementInfo(byte[] b)
        {
            ByteArrayDecoderClass decoder = new ByteArrayDecoderClass(b);

            decoder.Get2BytesAsInt(); // Ignore first 2 values (message length)
            this.Invoke(new Action(() =>
            {
                dataGridViewDataDownloadMesHeaders.DataSource = null;
                dataGridViewDataDownloadMesHeaders.Rows.Clear();
                dataGridViewDataDownloadMesHeaders.Refresh();
            }));

            // Get number of measurements and their header starting addresses
            int numOfMeasurements = decoder.Get2BytesAsInt();

            FormCustomConsole.WriteLine("Number of measurements: " + numOfMeasurements);
            Console.WriteLine("Number of measurements: " + numOfMeasurements);
            if (numOfMeasurements == 0)
            {
                // if no measurements leave it as it is
                MessageBox.Show("No saved measurements in device");
                return;
            }
            headers = new List <MeasurementHeaderClass>(); // Reset headers list
            // For now only header addresses are received, which can be used to fetch headers
            for (int i = 0; i < numOfMeasurements; i++)
            {
                headers.Add(new MeasurementHeaderClass(decoder.Get4BytesAsInt()));
            }
            currentHeader = 0; // Reset header index

            // Bootstrap
            // Send command to get measurement header
            CommandFormerClass cm = new CommandFormerClass(ConfigClass.startSeq, ConfigClass.deviceAddr);

            cm.AppendReadFromAddress(headers[0].headerAddress, ConfigClass.HEADER_LENGTH);
            var data = cm.GetFinalCommandList();

            //Console.WriteLine("Fetching headers from ProcessGetMeasurementInfo");
            SerialDriver.Send(data, FetchHeaders, FailCallback);
        }
Ejemplo n.º 14
0
        private void buttonDebugExecute_Click(object sender, EventArgs e)
        {
            var data = com.GetFinalCommandList();

            labelDebugBytesUsed.Text = "Bytes Used : " + data.Length;
            try
            {
                SerialDriver.Send(data, DebugExecuteSuccessCallback, DebugExecuteFailCallback);
            }
            catch (Exception)
            {
                MessageBox.Show("Problem occured while trying to send data to serial port!");
                FormCustomConsole.WriteLine("------- Commands not sent --------\r\n");
                return;
            }
            labelExecuteStatus.Text      = "Pending";
            labelExecuteStatus.ForeColor = System.Drawing.Color.Black;
            // Reset everything
            com = new CommandFormerClass(ConfigClass.startSeq, ConfigClass.deviceAddr);
            textBoxDebugInstructionPool.Text = "";
            FormCustomConsole.WriteLine("------- Commands sent --------\r\n");
        }
Ejemplo n.º 15
0
        private static void GainConfInit()
        {
            string fullPath = path + DeviceGainStorageSerializableClass.fileName;

            if (!File.Exists(fullPath))
            {
                // File does not exist, create default file and store it in application folder
                CreateFile(DeviceGainStorageSerializableClass.fileName);
                using (var stream = new FileStream(DeviceGainStorageSerializableClass.fileName, FileMode.Create))
                {
                    XmlSerializer xml = new XmlSerializer(typeof(DeviceGainStorageSerializableClass));
                    xml.Serialize(stream, new DeviceGainStorageSerializableClass());
                }
            }
            else
            {
                // File already exists, load it in memory
                try
                {
                    using (var stream = new FileStream(DeviceGainStorageSerializableClass.fileName, FileMode.Open))
                    {
                        XmlSerializer xml = new XmlSerializer(typeof(DeviceGainStorageSerializableClass));
                        // No need to asign result, static reference will be updated in constructor
                        xml.Deserialize(stream);
                    }
                }
                catch (Exception)
                {
                    new DeviceGainStorageSerializableClass(); // Force default values (static reference will be updated)
                    FormCustomConsole.WriteLine("Problem occurred while loading gain configuration file, default values are applied");
                    Console.WriteLine("Problem occurred while loading gain configuration file, default values are applied");
                    System.Windows.Forms.MessageBox.Show("Problem occurred while loading gain configuration file, default values are applied");
                }
            }
            return;
        }
Ejemplo n.º 16
0
        private void buttonMiksa_Click(object sender, EventArgs e)
        {
            float tmpValue;

            // Request return ACK
            com.ReturnACK();
            textBoxDebugInstructionPool.Text += "Return ACK\r\n";
            FormCustomConsole.WriteLine("Return ACK");

            // Discharge 10 On
            com.AppendDischarger10AOn();
            textBoxDebugInstructionPool.Text += "Discharger35AOn\r\n";
            FormCustomConsole.WriteLine("Discharger35AOn");

            // Wait for value falling 2000
            tmpValue = 2000 / ConfigClass.deviceGainCH1;;
            com.AppendWaitForValueFalling(1, 3, tmpValue);
            textBoxDebugInstructionPool.Text += "WaitForValueFalling(" + "CH1" + ", " + 3 +
                                                ", " + tmpValue.ToString() + ") 2000  \r\n";
            FormCustomConsole.WriteLine("WaitForValueFalling(" + "CH1" + ", " + 3 +
                                        ", " + tmpValue.ToString() + ") 2000");

            // Discharger 10A OFF S1
            com.AppendDischarger10AOffS1();
            textBoxDebugInstructionPool.Text += "Discharger35AOff S1\r\n";
            FormCustomConsole.WriteLine("Discharger35AOff S1");

            // Delay 200ms
            com.AppendWaitForMs(200);
            textBoxDebugInstructionPool.Text += "Delay in mseconds: " + 200 + "\r\n";
            FormCustomConsole.WriteLine("Delay in mseconds: " + 200);

            // Discharger 10A OFF S2
            com.AppendDischarger10AOffS2();
            textBoxDebugInstructionPool.Text += "Discharger35AOff S2\r\n";
            FormCustomConsole.WriteLine("Discharger35AOff S2");



            // Charger on
            com.AppendChargerOn();
            textBoxDebugInstructionPool.Text += "ChargerOn\r\n";
            FormCustomConsole.WriteLine("ChargerOn");

            // Wait for value rising  16000
            tmpValue = 16000 / ConfigClass.deviceGainCH1;;

            com.AppendWaitForValueRising(1, 3, tmpValue);
            textBoxDebugInstructionPool.Text += "WaitForValueRising(" + "CH1" + ", " + 3 +
                                                ", " + tmpValue.ToString() + ") 16000 \r\n";
            FormCustomConsole.WriteLine("WaitForValueRising(" + "CH1" + ", " + 3 +
                                        ", " + tmpValue.ToString() + ") 16000");

            // Charger off
            com.AppendChargerOff();
            textBoxDebugInstructionPool.Text += "ChargerOff\r\n";
            FormCustomConsole.WriteLine("ChargerOff");


            // Data recorder task CH1 , 1- continuous, 0-target points
            com.AppendDataRecorderTask(2, 1, 0, 0, DateTime.Now);
            textBoxDebugInstructionPool.Text += "DataRecTask(" + "CH1" + ", " + "continious" + " ," + "0" +
                                                ", " + "0" + ") \r\n";
            FormCustomConsole.WriteLine("DataRecTask(" + "CH1" + ", " + "continious" + " ," + "0" +
                                        ", " + "0" + ")");

            // Delay 15sec   15000 ms
            com.AppendWaitForMs(15000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: 15\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: 15");

            // Discharge 10 On
            com.AppendDischarger10AOn();
            textBoxDebugInstructionPool.Text += "Discharger35AOn\r\n";
            FormCustomConsole.WriteLine("Discharger35AOn");

            // Wait for value falling 8000
            tmpValue = 8000 / ConfigClass.deviceGainCH1;;
            com.AppendWaitForValueFalling(1, 3, tmpValue);
            textBoxDebugInstructionPool.Text += "WaitForValueFalling(" + "CH1" + ", " + 3 +
                                                ", " + tmpValue.ToString() + ") 8000  \r\n";
            FormCustomConsole.WriteLine("WaitForValueFalling(" + "CH1" + ", " + 3 +
                                        ", " + tmpValue.ToString() + ") 8000");

            // Discharger 10A OFF S1
            com.AppendDischarger10AOffS1();
            textBoxDebugInstructionPool.Text += "Discharger35AOff S1\r\n";
            FormCustomConsole.WriteLine("Discharger35AOff S1");

            // Delay 200ms
            com.AppendWaitForMs(200);
            textBoxDebugInstructionPool.Text += "Delay in mseconds: " + 200 + "\r\n";
            FormCustomConsole.WriteLine("Delay in mseconds: " + 200);

            // Discharger 10A OFF S2
            com.AppendDischarger10AOffS2();
            textBoxDebugInstructionPool.Text += "Discharger35AOff S2\r\n";
            FormCustomConsole.WriteLine("Discharger35AOff S2");

            // Delay 5 sec
            com.AppendWaitForMs(5000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: " + 5 + "\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: " + 5);

            // Data recorder finish
            com.AppendDataRecFinish();
            textBoxDebugInstructionPool.Text += "Data recorder finish (continious mode)\r\n";
            FormCustomConsole.WriteLine("Data recorder finish (continious mode)");

            // Charger on
            com.AppendChargerOn();
            textBoxDebugInstructionPool.Text += "ChargerOn\r\n";
            FormCustomConsole.WriteLine("ChargerOn");

            // Wait for value rising  16000
            tmpValue = 16000 / ConfigClass.deviceGainCH1;;

            com.AppendWaitForValueRising(1, 3, tmpValue);
            textBoxDebugInstructionPool.Text += "WaitForValueRising(" + "CH1" + ", " + 3 +
                                                ", " + tmpValue.ToString() + ") 16000 \r\n";
            FormCustomConsole.WriteLine("WaitForValueRising(" + "CH1" + ", " + 3 +
                                        ", " + tmpValue.ToString() + ") 16000");

            // Charger off
            com.AppendChargerOff();
            textBoxDebugInstructionPool.Text += "ChargerOff\r\n";
            FormCustomConsole.WriteLine("ChargerOff");

            // Delay 1sec   5000 ms
            com.AppendWaitForMs(5000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: 5\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: 5");


            // Data recorder task DUAL CH, TARGET POINTS, 0 Prescaler, 700 points
            com.AppendDataRecorderTask(2, 2, 0, 700, DateTime.Now);
            textBoxDebugInstructionPool.Text += "DataRecTask(" + "CH1" + ", " + "continious" + " ," + "0" +
                                                ", " + "0" + ") \r\n";
            FormCustomConsole.WriteLine("DataRecTask(" + "CH1" + ", " + "continious" + " ," + "0" +
                                        ", " + "0" + ")");

            // Delay 1sec   1000 ms
            com.AppendWaitForMs(1000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: 1\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: 1");

            // Res on
            com.AppendResOn();
            textBoxDebugInstructionPool.Text += "ResOn()\r\n";
            FormCustomConsole.WriteLine("ResOn()");

            // Delay 500msec   500 ms
            com.AppendWaitForMs(500);
            textBoxDebugInstructionPool.Text += "Delay in ms: 500\r\n";
            FormCustomConsole.WriteLine("Delay in ms: 500");

            // Res off
            com.AppendResOff();
            textBoxDebugInstructionPool.Text += "ResOff()\r\n";
            FormCustomConsole.WriteLine("ResOff()");
        }
Ejemplo n.º 17
0
 private void buttonDebugDataRecFinish_Click(object sender, EventArgs e)
 {
     com.AppendDataRecFinish();
     textBoxDebugInstructionPool.Text += "Data recorder finish (continious mode)\r\n";
     FormCustomConsole.WriteLine("Data recorder finish (continious mode)");
 }
Ejemplo n.º 18
0
 private void buttonDebugDisableCutoffValue_Click(object sender, EventArgs e)
 {
     com.SetCutoffValueCH1(0x8000);
     textBoxDebugInstructionPool.Text += "DisableCutoffValue()\r\n";
     FormCustomConsole.WriteLine("DisableCutoffValue()\r\n");
 }
Ejemplo n.º 19
0
 private void buttonDebugResetInstructions_Click(object sender, EventArgs e)
 {
     com = new CommandFormerClass(ConfigClass.startSeq, ConfigClass.deviceAddr);
     textBoxDebugInstructionPool.Text = "";
     FormCustomConsole.WriteLine("------- Commands reset --------\r\n");
 }
Ejemplo n.º 20
0
        private static void DeviceAvailabilityInit()
        {
            // Init configurations for both capacitors
            // Capacitor 1 init
            string fullPath = path + ConfigClass.devPoolCap1Filename;

            if (!File.Exists(fullPath))
            {
                // File does not exist, create default file and store it in application folder
                CreateFile(ConfigClass.devPoolCap1Filename);
                using (var stream = new FileStream(ConfigClass.devPoolCap1Filename, FileMode.Create))
                {
                    XmlSerializer xml = new XmlSerializer(typeof(DevicePoolSerializableClass));
                    ConfigClass.DevPoolCap1 = new DevicePoolSerializableClass(ConfigClass.cap1AddrOffset);
                    xml.Serialize(stream, ConfigClass.DevPoolCap1);
                }
            }
            else
            {
                // File already exists, load it in memory
                try
                {
                    using (var stream = new FileStream(ConfigClass.devPoolCap1Filename, FileMode.Open))
                    {
                        XmlSerializer xml = new XmlSerializer(typeof(DevicePoolSerializableClass));
                        // No need to asign result, static reference will be updated in constructor
                        ConfigClass.DevPoolCap1 = (DevicePoolSerializableClass)xml.Deserialize(stream);
                    }
                }
                catch (Exception)
                {
                    ConfigClass.DevPoolCap1 = new DevicePoolSerializableClass(ConfigClass.cap1AddrOffset); // Force default values
                    FormCustomConsole.WriteLine("Problem occurred while initializing availability for Capacitor 1, default values are applied");
                    Console.WriteLine("Problem occurred while initializing availability for Capacitor 1, default values are applied");
                    System.Windows.Forms.MessageBox.Show("Problem occurred while initializing availability for Capacitor 1, default values are applied");
                }
            }

            // Capacitor 2 init
            fullPath = path + ConfigClass.devPoolCap2Filename;
            if (!File.Exists(fullPath))
            {
                // File does not exist, create default file and store it in application folder
                CreateFile(ConfigClass.devPoolCap2Filename);
                using (var stream = new FileStream(ConfigClass.devPoolCap2Filename, FileMode.Create))
                {
                    XmlSerializer xml = new XmlSerializer(typeof(DevicePoolSerializableClass));
                    ConfigClass.DevPoolCap2 = new DevicePoolSerializableClass(ConfigClass.cap2AddrOffset);
                    xml.Serialize(stream, ConfigClass.DevPoolCap2);
                }
            }
            else
            {
                // File already exists, load it in memory
                try
                {
                    using (var stream = new FileStream(ConfigClass.devPoolCap2Filename, FileMode.Open))
                    {
                        XmlSerializer xml = new XmlSerializer(typeof(DevicePoolSerializableClass));
                        // No need to asign result, static reference will be updated in constructor
                        ConfigClass.DevPoolCap2 = (DevicePoolSerializableClass)xml.Deserialize(stream);
                    }
                }
                catch (Exception)
                {
                    ConfigClass.DevPoolCap2 = new DevicePoolSerializableClass(ConfigClass.cap2AddrOffset); // Force default values
                    FormCustomConsole.WriteLine("Problem occurred while initializing availability for Capacitor 2, default values are applied");
                    Console.WriteLine("Problem occurred while initializing availability for Capacitor 2, default values are applied");
                    System.Windows.Forms.MessageBox.Show("Problem occurred while initializing availability for Capacitor 2, default values are applied");
                }
            }
            return;
        }
Ejemplo n.º 21
0
 private void buttonDebugFastChargerOff_Click(object sender, EventArgs e)
 {
     com.FastChargeOff();
     textBoxDebugInstructionPool.Text += "FastChargerOff\r\n";
     FormCustomConsole.WriteLine("FastChargerOff");
 }
Ejemplo n.º 22
0
 private void buttonDebugFanoxOn_Click(object sender, EventArgs e)
 {
     com.AppendFanoxOn();
     textBoxDebugInstructionPool.Text += "FanoxOn\r\n";
     FormCustomConsole.WriteLine("FanoxOn");
 }
Ejemplo n.º 23
0
        private void AppendTestSequence()
        {
            float tmpValue;

            // Request return ACK
            com.ReturnACK();
            textBoxDebugInstructionPool.Text += "Return ACK\r\n";
            FormCustomConsole.WriteLine("Return ACK");

            // First disable fanox
            com.AppendFanoxOff();
            textBoxDebugInstructionPool.Text += "Fanox off\r\n";
            FormCustomConsole.WriteLine("Fanox off");

            // Data recorder task DUAL CH, TARGET POINTS, 0 Prescaler, 700 points
            com.AppendDataRecorderTask(2, 2, 0, 700, DateTime.Now);
            textBoxDebugInstructionPool.Text += "DataRecTask(" + "CH1" + ", " + "continious" + " ," + "0" +
                                                ", " + "0" + ") \r\n";
            FormCustomConsole.WriteLine("DataRecTask(" + "CH1" + ", " + "continious" + " ," + "0" +
                                        ", " + "0" + ")");

            // Delay 1sec   1000 ms
            com.AppendWaitForMs(1000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: 1\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: 1");


            // Res on
            com.AppendResOn();
            textBoxDebugInstructionPool.Text += "ResOn()\r\n";
            FormCustomConsole.WriteLine("ResOn()");

            // Delay 500msec   500 ms
            com.AppendWaitForMs(500);
            textBoxDebugInstructionPool.Text += "Delay in ms: 500\r\n";
            FormCustomConsole.WriteLine("Delay in ms: 500");

            // Res off
            com.AppendResOff();
            textBoxDebugInstructionPool.Text += "ResOff()\r\n";
            FormCustomConsole.WriteLine("ResOff()");

            // Delay 2sec   2 sec
            com.AppendWaitForMs(2000);
            textBoxDebugInstructionPool.Text += "Delay 2sec\r\n";
            FormCustomConsole.WriteLine("Delay 2sec");

            // Discharge 10 On
            com.AppendDischarger10AOn();
            textBoxDebugInstructionPool.Text += "Discharger10AOn\r\n";
            FormCustomConsole.WriteLine("Discharger10AOn");

            // Wait for value falling 2200
            tmpValue = 2200 / ConfigClass.deviceGainCH1;;
            com.AppendWaitForValueFalling(1, 5, tmpValue);
            textBoxDebugInstructionPool.Text += "WaitForValueFalling(" + "CH1" + ", " + 0 +
                                                ", " + tmpValue.ToString() + ") 2200  \r\n";
            FormCustomConsole.WriteLine("WaitForValueFalling(" + "CH1" + ", " + 0 +
                                        ", " + tmpValue.ToString() + ") 2200");

            // Discharger 10A OFF S1
            com.AppendDischarger10AOffS1();
            textBoxDebugInstructionPool.Text += "Discharger10AOff S1\r\n";
            FormCustomConsole.WriteLine("Discharger10AOff S1");

            // Delay 200ms
            com.AppendWaitForMs(200);
            textBoxDebugInstructionPool.Text += "Delay in mseconds: " + 200 + "\r\n";
            FormCustomConsole.WriteLine("Delay in mseconds: " + 200);

            // Discharger 10A OFF S2
            com.AppendDischarger10AOffS2();
            textBoxDebugInstructionPool.Text += "Discharger10AOff S2\r\n";
            FormCustomConsole.WriteLine("Discharger10AOff S2");

            // Delay 5 sec
            com.AppendWaitForMs(5000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: " + 5 + "\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: " + 5);

            // ORIGINAL
            // Charger on
            com.AppendChargerOn();
            textBoxDebugInstructionPool.Text += "ChargerOn\r\n";
            FormCustomConsole.WriteLine("ChargerOn");


            // Wait for value rising  3800
            tmpValue = 3800 / ConfigClass.deviceGainCH1;;

            com.AppendWaitForValueRising(1, 5, tmpValue);
            textBoxDebugInstructionPool.Text += "WaitForValueRising(" + "CH1" + ", " + 0 +
                                                ", " + tmpValue.ToString() + ") 3800 \r\n";
            FormCustomConsole.WriteLine("WaitForValueRising(" + "CH1" + ", " + 0 +
                                        ", " + tmpValue.ToString() + ") 3800");

            // Fast charger off
            com.FastChargeOff();
            textBoxDebugInstructionPool.Text += "FastChargerOff\r\n";
            FormCustomConsole.WriteLine("FastChargerOff");


            // Delay 30min   1800000 ms
            com.AppendWaitForMs(1800000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: " + 1800 + "\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: " + 1800);

            // Discharge 10 On
            com.AppendDischarger10AOn();
            textBoxDebugInstructionPool.Text += "Discharger10AOn\r\n";
            FormCustomConsole.WriteLine("Discharger10AOn");


            // Delay 1sec   1000 ms
            //com.AppendWaitForMs(1000);
            //textBoxDebugInstructionPool.Text += "Delay in seconds: " + 1 + "\r\n";
            //FormCustomConsole.WriteLine("Delay in seconds: " + 1);

            // Data recorder task CH1 , 1- continuous, 0-target points
            com.AppendDataRecorderTask(2, 1, 0, 0, DateTime.Now);
            textBoxDebugInstructionPool.Text += "DataRecTask(" + "CH1" + ", " + "continious" + " ," + "0" +
                                                ", " + "0" + ") \r\n";
            FormCustomConsole.WriteLine("DataRecTask(" + "CH1" + ", " + "continious" + " ," + "0" +
                                        ", " + "0" + ")");

            // Delay 3sec   3000 ms
            com.AppendWaitForMs(3000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: " + 3 + "\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: " + 3);

            // Data recorder finish
            com.AppendDataRecFinish();
            textBoxDebugInstructionPool.Text += "Data recorder finish (continious mode)\r\n";
            FormCustomConsole.WriteLine("Data recorder finish (continious mode)");

            // Delay 3sec   1000 ms
            com.AppendWaitForMs(1000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: " + 1 + "\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: " + 1);

            // Data recorder task CH1 , 1- continuous, 0-target points
            com.AppendDataRecorderTask(2, 1, 100, 0, DateTime.Now);
            textBoxDebugInstructionPool.Text += "DataRecTask(" + "CH1" + ", " + "continious" + " ," + "100" +
                                                ", " + "0" + ") \r\n";
            FormCustomConsole.WriteLine("DataRecTask(" + "CH1" + ", " + "continious" + " ," + "100" +
                                        ", " + "0" + ")");

            // Wait for value falling 2200
            tmpValue = 2200 / ConfigClass.deviceGainCH1;;
            com.AppendWaitForValueFalling(1, 5, tmpValue);
            textBoxDebugInstructionPool.Text += "WaitForValueFalling(" + "CH1" + ", " + 0 +
                                                ", " + tmpValue.ToString() + ") 2200  \r\n";
            FormCustomConsole.WriteLine("WaitForValueFalling(" + "CH1" + ", " + 0 +
                                        ", " + tmpValue.ToString() + ") 2200");

            // Data recorder finish
            com.AppendDataRecFinish();
            textBoxDebugInstructionPool.Text += "Data recorder finish (continious mode)\r\n";
            FormCustomConsole.WriteLine("Data recorder finish (continious mode)");


            // Discharger 10A OFF S1
            com.AppendDischarger10AOffS1();
            textBoxDebugInstructionPool.Text += "Discharger10AOff S1\r\n";
            FormCustomConsole.WriteLine("Discharger10AOff S1");

            // Delay 200ms
            com.AppendWaitForMs(200);
            textBoxDebugInstructionPool.Text += "Delay in mseconds: " + 200 + "\r\n";
            FormCustomConsole.WriteLine("Delay in mseconds: " + 200);

            // Discharger 10A OFF S2
            com.AppendDischarger10AOffS2();
            textBoxDebugInstructionPool.Text += "Discharger10AOff S2\r\n";
            FormCustomConsole.WriteLine("Discharger10AOff S2");


            // Delay 1s
            com.AppendWaitForMs(1000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: " + 1 + "\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: " + 1);

            // Charger on
            com.AppendChargerOn();
            textBoxDebugInstructionPool.Text += "ChargerOn\r\n";
            FormCustomConsole.WriteLine("ChargerOn");

            // Wait for value rising  3800
            tmpValue = 3800 / ConfigClass.deviceGainCH1;;

            com.AppendWaitForValueRising(1, 5, tmpValue);
            textBoxDebugInstructionPool.Text += "WaitForValueRising(" + "CH1" + ", " + 0 +
                                                ", " + tmpValue.ToString() + ")3800 \r\n";
            FormCustomConsole.WriteLine("WaitForValueRising(" + "CH1" + ", " + 0 +
                                        ", " + tmpValue.ToString() + ") 3800");

            // Fast charger off
            com.FastChargeOff();
            textBoxDebugInstructionPool.Text += "FastChargerOff\r\n";
            FormCustomConsole.WriteLine("FastChargerOff");


            // Delay 30min   1800000 ms
            com.AppendWaitForMs(1800000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: " + 1800 + "\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: " + 1800);

            // Charger off
            com.AppendChargerOff();
            textBoxDebugInstructionPool.Text += "ChargerOff\r\n";
            FormCustomConsole.WriteLine("ChargerOff");


            // Delay 5min   300000 ms
            com.AppendWaitForMs(300000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: " + 300 + "\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: " + 300);

            // Data recorder task CH1 , 1- continuous, 0-target points
            com.AppendDataRecorderTask(2, 1, 0, 0, DateTime.Now);
            textBoxDebugInstructionPool.Text += "DataRecTask(" + "CH1" + ", " + "continious" + " ," + "0" +
                                                ", " + "0" + ") \r\n";
            FormCustomConsole.WriteLine("DataRecTask(" + "CH1" + ", " + "continious" + " ," + "0" +
                                        ", " + "0" + ")");

            // Delay 1s
            com.AppendWaitForMs(1000);
            textBoxDebugInstructionPool.Text += "Delay in seconds: " + 1 + "\r\n";
            FormCustomConsole.WriteLine("Delay in seconds: " + 1);

            // Discharger 100A On
            com.AppendDischarger100AOn();
            textBoxDebugInstructionPool.Text += "Discharger100AOn\r\n";
            FormCustomConsole.WriteLine("Discharger100AOn");

            // Wait for value falling 3000
            tmpValue = 3000 / ConfigClass.deviceGainCH1;;
            com.AppendWaitForValueFalling(1, 5, tmpValue);
            textBoxDebugInstructionPool.Text += "WaitForValueFalling(" + "CH1" + ", " + 0 +
                                                ", " + tmpValue.ToString() + ") 3000  \r\n";
            FormCustomConsole.WriteLine("WaitForValueFalling(" + "CH1" + ", " + 0 +
                                        ", " + tmpValue.ToString() + ") 3000");

            // Discharger 100A OFF S1
            com.AppendDischarger100AOffS1();
            textBoxDebugInstructionPool.Text += "Discharger100AOff S1\r\n";
            FormCustomConsole.WriteLine("Discharger100AOff S1");

            // Delay 200ms
            com.AppendWaitForMs(200);
            textBoxDebugInstructionPool.Text += "Delay in mseconds: " + 200 + "\r\n";
            FormCustomConsole.WriteLine("Delay in mseconds: " + 200);

            // Discharger 100A OFF S2
            com.AppendDischarger100AOffS2();
            textBoxDebugInstructionPool.Text += "Discharger100AOff S2\r\n";
            FormCustomConsole.WriteLine("Discharger100AOff S2");

            // Data recorder finish
            com.AppendDataRecFinish();
            textBoxDebugInstructionPool.Text += "Data recorder finish (continious mode)\r\n";
            FormCustomConsole.WriteLine("Data recorder finish (continious mode)");

            // Delay 1s
            com.AppendWaitForMs(1000);
            textBoxDebugInstructionPool.Text += "Delay in seconds 1\r\n";
            FormCustomConsole.WriteLine("Delay in seconds 1");

            // Charger on
            com.AppendChargerOn();
            textBoxDebugInstructionPool.Text += "ChargerOn\r\n";
            FormCustomConsole.WriteLine("ChargerOn");

            // Wait for value rising  3800
            tmpValue = 3800 / ConfigClass.deviceGainCH1;;

            com.AppendWaitForValueRising(1, 5, tmpValue);
            textBoxDebugInstructionPool.Text += "WaitForValueRising(" + "CH1" + ", " + 0 +
                                                ", " + tmpValue.ToString() + ")3800 \r\n";
            FormCustomConsole.WriteLine("WaitForValueRising(" + "CH1" + ", " + 0 +
                                        ", " + tmpValue.ToString() + ") 3800");


            // Charger off
            com.AppendChargerOff();
            textBoxDebugInstructionPool.Text += "ChargerOff\r\n";
            FormCustomConsole.WriteLine("ChargerOff");


            // Enable fanox
            com.AppendFanoxOn();
            textBoxDebugInstructionPool.Text += "Fanox on\r\n";
            FormCustomConsole.WriteLine("Fanox on");
        }
Ejemplo n.º 24
0
 private void buttonDebugResOff_Click(object sender, EventArgs e)
 {
     com.AppendResOff();
     textBoxDebugInstructionPool.Text += "ResOff\r\n";
     FormCustomConsole.WriteLine("ResOff");
 }
Ejemplo n.º 25
0
 private void buttonDebugWaitDataRecToFinish_Click(object sender, EventArgs e)
 {
     com.AppendWaitForDataRecorderToFinish();
     textBoxDebugInstructionPool.Text += "Wair for data recorder to finish\r\n";
     FormCustomConsole.WriteLine("Wair for data recorder to finish");
 }
Ejemplo n.º 26
0
 private void buttonDebugRequestACK_Click(object sender, EventArgs e)
 {
     com.ReturnACK();
     textBoxDebugInstructionPool.Text += "Return ACK\r\n";
     FormCustomConsole.WriteLine("Return ACK");
 }
Ejemplo n.º 27
0
 private void buttonDebugDischarger10AOffS2_Click(object sender, EventArgs e)
 {
     com.AppendDischarger10AOffS2();
     textBoxDebugInstructionPool.Text += "Discharger10AOff S2\r\n";
     FormCustomConsole.WriteLine("Discharger10AOff S2");
 }
Ejemplo n.º 28
0
        private void buttonDebugWaitForValueFalling_Click(object sender, EventArgs e)
        {
            byte   ch;
            UInt16 latency;
            float  value, gain;

            if (checkBoxDebugUseDefGain.Checked)
            {
                // Use gain that is inferred from configuration file
                try
                {
                    ch = InputValidatorHelperClass.GetChModeFromComboBox(comboBoxDebugWaitForValueFalling);
                    string corectedValue = textBoxDebugWaitForValueFallingValue.Text;
                    string correctedGain = textBoxDebugWaitForValueFallingGain.Text;
                    value = float.Parse(corectedValue);
                    if (ch == 0)
                    {
                        gain = ConfigClass.deviceGainCH0;
                    }
                    else
                    {
                        gain = ConfigClass.deviceGainCH1;
                    }
                    value = value / gain;
                }
                catch (Exception)
                {
                    MessageBox.Show("Insert valid values!");
                    return;
                }
            }
            else
            {
                // Use gain that is parsed from textbox
                try
                {
                    ch = InputValidatorHelperClass.GetChModeFromComboBox(comboBoxDebugWaitForValueFalling);
                    string corectedValue = textBoxDebugWaitForValueFallingValue.Text;
                    string correctedGain = textBoxDebugWaitForValueFallingGain.Text;
                    value = float.Parse(corectedValue);
                    gain  = float.Parse(correctedGain);
                    value = value / gain;
                }
                catch (Exception)
                {
                    MessageBox.Show("Insert valid values!");
                    return;
                }
            }

            // parse latency
            try
            {
                latency = Convert.ToUInt16(textBoxDebugWaitForValueFallingLatency.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Insert valid value for latency!");
                return;
            }

            com.AppendWaitForValueFalling(ch, latency, value);
            textBoxDebugInstructionPool.Text += "WaitForValueFalling(" + comboBoxDebugWaitForValueFalling.Text + ", " + latency +
                                                ", " + value.ToString() + ")\r\n";
            FormCustomConsole.WriteLine("WaitForValueFalling(" + comboBoxDebugWaitForValueFalling.Text + ", " + latency +
                                        ", " + value.ToString() + ")");
        }