Example #1
0
        private void AddData()
        {
            DateTime timeStamp = DateTime.Now;
            int      channel   = 0;

            int dem = 0;

            double[] data = new double[12];
            byte[]   buf  = new byte[64];

            string StrDevs = host;

            try
            {
                device_dashboard.Close();
                device_dashboard.USBOpen(host);
                //if (device_dashboard.USBOpen(StrDevs) == true)
                //{
                device_dashboard.readSettingDevice();
                if (device_dashboard.byteLogging == 0xaa)
                {
                    if (addDataRunner.IsAlive == true)
                    {
                        addDataRunner.Suspend();
                    }
                    this.Close();
                }
                //Thread.Sleep(500);

                //HIDFunction.hid_SetNonBlocking(device_dashboard.dev, 1);
                device_dashboard.readDataProbe(ref buf);

                if (buf[1] != 28)
                {
                    device_dashboard.Close();
                    HIDFunction.hid_Exit();
                    device_dashboard.USBOpen(StrDevs);
                    //MessageBox.Show(res_man.GetString("Read data fail", cul));
                    return;
                }

                int count = 0;
                //for (int i = 0; i < 4; i++)
                //{
                //    string hexSensor = buf[2 + i * 7].ToString("X");
                //    if (hexSensor != "0")
                //    {
                //        if (hexSensor.Substring(1, 1) == "3")
                //        {
                //            for (int j = 0; j < 3; j++)
                //            {
                //                data[count] = mGlobal.get_temp(buf[3 + i * 7 + 2 * j], buf[3 + i * 7 + 2 * j + 1]) / 1000;
                //                count += 1;
                //            }
                //        }
                //        else if (hexSensor.Substring(1, 1) == "1" || hexSensor.Substring(1, 1) == "2")
                //        {
                //            data[count] = mGlobal.get_temp(buf[3 + i * 7], buf[3 + i * 7 + 1]) / 10.0;
                //            count += 1;
                //        }
                //        else if (hexSensor.Substring(1, 1) == "0")
                //        {
                //            continue;
                //        }
                //        else
                //        {
                //            data[count] = mGlobal.get_temp(buf[3 + i * 7], buf[3 + i * 7 + 1]);
                //            count += 1;
                //        }
                //    }

                //    //for (int j = 0; j < 6; j++)
                //    //{
                //    //    if (buf[3 + i * 7 + j] != 0)
                //    //    {
                //    //        data[i * j] = buf[3 + i * 7 + j];
                //    //    }
                //    //}
                //}

                for (int i = 0; i < 4; i++)
                {
                    string hexSensor = buf[2 + i * 7].ToString("X");
                    if (hexSensor != "0")
                    {
                        if (hexSensor.Substring(1, 1) == "3")
                        {
                            for (int j = 0; j < 3; j++)
                            {
                                data[i * 3 + j] = mGlobal.get_temp(buf[3 + i * 7 + 2 * j], buf[3 + i * 7 + 2 * j + 1]) / 1000.0;
                                //data[i * 3 + j] = mGlobal.get_temp(buf[3 + i * 7 + 2 * j], buf[3 + i * 7 + 2 * j + 1]) / 1000.0;
                                count += 1;
                            }
                        }
                        else if (hexSensor.Substring(1, 1) == "1" || hexSensor.Substring(1, 1) == "2")
                        {
                            data[i * 3] = mGlobal.get_temp(buf[3 + i * 7], buf[3 + i * 7 + 1]) / 10.0;
                            count      += 1;
                        }
                        else if (hexSensor.Substring(1, 1) == "0")
                        {
                            continue;
                        }
                        else
                        {
                            data[i * 3] = mGlobal.get_temp(buf[3 + i * 7], buf[3 + i * 7 + 1]);
                            count      += 1;
                        }
                    }

                    //for (int j = 0; j < 6; j++)
                    //{
                    //    if (buf[3 + i * 7 + j] != 0)
                    //    {
                    //        data[i * j] = buf[3 + i * 7 + j];
                    //    }
                    //}
                }
                //device_dashboard.Close();
                //}
            }
            catch
            {
                MessageBox.Show(device_dashboard.dev.ToString());
                device_dashboard.Close();
            }
            //device_dashboard.Close();


            int c = 0;

            foreach (Series ptSeries in chart1.Series)
            {
                //channel += 1;
                string num = "";
                num = ptSeries.Name.ToString().Substring(8, 1);
                string name = "";
                name = ptSeries.Name.ToString().Substring(10, 1);

                if (name == "(" || name == "X")
                {
                    dem = (Int32.Parse(num) - 1) * 3;
                    AddNewPoint(timeStamp, ptSeries, dem, data, c);
                    c = c + 1;
                }
                else if (name == "Y")
                {
                    dem = (Int32.Parse(num) - 1) * 3 + 1;
                    AddNewPoint(timeStamp, ptSeries, dem, data, c);
                    c = c + 1;
                }
                else
                {
                    dem = (Int32.Parse(num) - 1) * 3 + 2;
                    AddNewPoint(timeStamp, ptSeries, dem, data, c);
                    c = c + 1;
                }

                //channel = Int32.Parse(name.Substring(8, 1));

                //AddNewPoint(timeStamp, ptSeries, channel);


                //ptSeries.Points.AddXY(timeStamp.ToOADate(), );
                //dem += 1;
                //AddNewPoint(timeStamp, ptSeries, dem, data);
            }
        }
Example #2
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            chDesAl.Clear();
            btnPrint.Enabled = true;
            StrDev           = txtHostPort.Text;

            dev_general.USBOpen(StrDev);

            if (!dev_general.readSerial())
            {
                MessageBox.Show(res_man.GetString("Read setting fail", cul) + "1");
                dev_general.Close();
                return;
            }
            //if (dev_general.FirmVer > 128)
            //{
            //    txtFirmWare.Text = "No Wifi _ " + (dev_general.FirmVer - 128).ToString();
            //}
            //else
            //{
            //    txtFirmWare.Text = "Wifi _ " + dev_general.FirmVer.ToString();
            //}
            //txtHardWare.Text = dev_general.HardVer.ToString();
            txtFirmWare.Text  = dev_general.HardVer + "." + dev_general.FirmVer;
            txtSerialNum.Text = dev_general.Serial;

            dev_general.Close();
            dev_general.USBOpen(StrDev);

            if (!dev_general.readDescription())
            {
                MessageBox.Show(res_man.GetString("Read setting fail", cul) + "2");
                dev_general.Close();
                return;
            }
            textBox1.Text = dev_general.Description;

            dev_general.Close();
            dev_general.USBOpen(StrDev);

            if (!dev_general.readLocation())
            {
                MessageBox.Show(res_man.GetString("Read setting fail", cul) + "3");
                dev_general.Close();
                return;
            }
            txtLocation.Text = dev_general.Location;

            dev_general.Close();
            dev_general.USBOpen(StrDev);

            if (!dev_general.readSettingDevice())
            {
                MessageBox.Show(res_man.GetString("Read setting fail", cul) + "4");
                dev_general.Close();
                return;
            }
            txtTimeSetting.Text = dev_general.SettingTime.ToLongTimeString();
            txtDelay.Text       = dev_general.Delay.ToString() + " Min(s)";
            txtDuration.Text    = dev_general.Duration.ToString() + " Day(s)";

            if (!dev_general.readSettingChannel())
            {
                MessageBox.Show(res_man.GetString("Read setting fail", cul) + "5");
                dev_general.Close();
                return;
            }

            this.Refresh();

            if (!dev_general.readDataProbe(ref buf))
            {
                //MessageBox.Show(res_man.GetString("Read data fail", cul));
                dev_general.Close();
                //return;
            }

            dev_general.Close();

            int num = 0;

            for (int i = 0; i < 4; i++)
            {
                if (dev_general.Channels[i].Sensor == 0)
                {
                    num += 0;
                }
                else if (dev_general.Channels[i].Sensor == 3)
                {
                    num += 3;
                }
                else
                {
                    num += 1;
                }
            }

            int sec = 0;
            int min = 0;
            int tg  = 0;
            int x   = 0;

            if (num != 0)
            {
                x = (128 * 1024) / num;
            }
            else
            {
                x = 128 * 1024;
            }

            tg = mGlobal.duration35(Convert.ToInt32(dev_general.Duration), x);
            dev_general.Interval = tg.ToString();
            if (tg > 60)
            {
                min = tg / 60;
                sec = tg % 60;
                txtMeasurenment.Text = min + " min(s) " + sec + " sec(s).";
            }
            else
            {
                txtMeasurenment.Text = tg + " sec(s).";
            }

            txtChannel      = new TextBox[num];
            txtCurrentValue = new TextBox[num];
            txtUnit         = new TextBox[num];
            txtHighAlarm    = new TextBox[num];
            txtLowAlarm     = new TextBox[num];
            txtDescription  = new TextBox[num];

            //declare
            for (int i = 0; i < num; i++)
            {
                txtChannel[i]           = new TextBox();
                txtChannel[i].Name      = "txtChannel" + i.ToString();
                txtChannel[i].Width     = 80;
                txtChannel[i].Top       = (int)(220 + 1.5 * i * txtChannel[i].Height);
                txtChannel[i].Left      = 20;
                txtChannel[i].TextAlign = HorizontalAlignment.Center;
                this.groupBox1.Controls.Add(txtChannel[i]);

                txtUnit[i]           = new TextBox();
                txtUnit[i].Name      = "txtUnit" + i.ToString();
                txtUnit[i].Width     = 90;
                txtUnit[i].Top       = (int)(220 + 1.5 * i * txtChannel[i].Height);
                txtUnit[i].Left      = 140;
                txtUnit[i].TextAlign = HorizontalAlignment.Center;
                this.groupBox1.Controls.Add(txtUnit[i]);

                txtCurrentValue[i]           = new TextBox();
                txtCurrentValue[i].Name      = "txtValue" + i.ToString();
                txtCurrentValue[i].Width     = 110;
                txtCurrentValue[i].Top       = (int)(220 + 1.5 * i * txtChannel[i].Height);
                txtCurrentValue[i].Left      = 260;
                txtCurrentValue[i].TextAlign = HorizontalAlignment.Center;
                this.groupBox1.Controls.Add(txtCurrentValue[i]);

                txtHighAlarm[i]           = new TextBox();
                txtHighAlarm[i].Name      = "txtHigh" + i.ToString();
                txtHighAlarm[i].Width     = 130;
                txtHighAlarm[i].Top       = (int)(220 + 1.5 * i * txtChannel[i].Height);
                txtHighAlarm[i].Left      = 410;
                txtHighAlarm[i].TextAlign = HorizontalAlignment.Center;
                this.groupBox1.Controls.Add(txtHighAlarm[i]);

                txtLowAlarm[i]           = new TextBox();
                txtLowAlarm[i].Name      = "txtLow" + i.ToString();
                txtLowAlarm[i].Width     = 130;
                txtLowAlarm[i].Top       = (int)(220 + 1.5 * i * txtChannel[i].Height);
                txtLowAlarm[i].Left      = 580;
                txtLowAlarm[i].TextAlign = HorizontalAlignment.Center;
                this.groupBox1.Controls.Add(txtLowAlarm[i]);


                txtDescription[i]           = new TextBox();
                txtDescription[i].Name      = "txtDescription" + i.ToString();
                txtDescription[i].Width     = 200;
                txtDescription[i].Top       = (int)(220 + 1.5 * i * txtChannel[i].Height);
                txtDescription[i].Left      = 760;
                txtDescription[i].TextAlign = HorizontalAlignment.Center;
                this.groupBox1.Controls.Add(txtDescription[i]);
            }


            addData();
            ////add data
            //int channel = 0;

            //for (int i = 0; i < 4; i++)
            //{
            //    int tmpDiv;
            //    if (dev_general.Channels[i].Unit == 175 || dev_general.Channels[i].Unit == 172 || dev_general.Channels[i].Sensor == 2)
            //    {
            //        tmpDiv = 10;
            //    }
            //    else if (dev_general.Channels[i].Sensor == 3)
            //    {
            //        tmpDiv = 1000;
            //    }
            //    else
            //    {
            //        tmpDiv = 1;
            //    }
            //    if (dev_general.Channels[i].Sensor == 3)
            //    {
            //        int dem = 0;
            //        for (int j = 0; j < 3; j++)
            //        {
            //            switch (dem)
            //            {
            //                case 0:
            //                    txtChannel[channel].Text = (i + 1).ToString() + "(X)";
            //                    txtUnit[channel].Text = mGlobal.IntToUnit35(dev_general.Channels[i].Sensor);
            //                    txtHighAlarm[channel].Text = res_man.GetString("No Alarm",cul);
            //                    txtLowAlarm[channel].Text = res_man.GetString("No Alarm", cul);
            //                    txtDescription[channel].Text = dev_general.Channels[i].Desc;
            //                    txtCurrentValue[channel].Text = (mGlobal.get_temp(buf[3 + 7 * i], buf[4 + 7 * i])/tmpDiv).ToString();
            //                    channel += 1;
            //                    dem += 1;
            //                    break;

            //                case 1:
            //                    txtChannel[channel].Text = (i + 1).ToString() + "(Y)";
            //                    txtUnit[channel].Text = mGlobal.IntToUnit35(dev_general.Channels[i].Sensor);
            //                    txtHighAlarm[channel].Text = res_man.GetString("No Alarm", cul);
            //                    txtLowAlarm[channel].Text = res_man.GetString("No Alarm", cul);
            //                    txtDescription[channel].Text = dev_general.Channels[i].Desc;
            //                    txtCurrentValue[channel].Text = (mGlobal.get_temp(buf[5 + 7 * i], buf[6 + 7 * i]) / tmpDiv).ToString();
            //                    channel += 1;
            //                    dem += 1;
            //                    break;

            //                case 2:
            //                    txtChannel[channel].Text = (i + 1).ToString() + "(Z)";
            //                    txtUnit[channel].Text = mGlobal.IntToUnit35(dev_general.Channels[i].Sensor);
            //                    txtHighAlarm[channel].Text = res_man.GetString("No Alarm", cul);
            //                    txtLowAlarm[channel].Text = res_man.GetString("No Alarm", cul);
            //                    txtDescription[channel].Text = dev_general.Channels[i].Desc;
            //                    txtCurrentValue[channel].Text = (mGlobal.get_temp(buf[7 + 7 * i], buf[8 + 7 * i]) / tmpDiv).ToString();
            //                    channel += 1;
            //                    dem += 1;
            //                    break;
            //            }
            //        }
            //    }
            //    else if (dev_general.Channels[i].Sensor == 1)
            //    {
            //        txtChannel[channel].Text = (i + 1).ToString();
            //        txtUnit[channel].Text = mGlobal.IntToUnit35(dev_general.Channels[i].Unit);
            //        if (dev_general.Channels[i].NoAlarm)
            //        {
            //            txtHighAlarm[channel].Text = res_man.GetString("No Alarm", cul);
            //            txtLowAlarm[channel].Text = res_man.GetString("No Alarm", cul);
            //        }
            //        else
            //        {
            //            txtHighAlarm[channel].Text = (dev_general.Channels[i].AlarmMax / 10).ToString();
            //            txtLowAlarm[channel].Text = (dev_general.Channels[i].AlarmMin / 10).ToString();
            //        }
            //        txtDescription[channel].Text = dev_general.Channels[i].Desc;
            //        txtCurrentValue[channel].Text = (mGlobal.get_temp(buf[3 + 7 * i], buf[4 + 7 * i]) / tmpDiv).ToString();
            //        channel += 1;
            //    }
            //    else if (dev_general.Channels[i].Sensor == 2)
            //    {
            //        txtChannel[channel].Text = (i + 1).ToString();
            //        txtUnit[channel].Text = mGlobal.IntToUnit35(dev_general.Channels[i].Sensor);
            //        if (dev_general.Channels[i].NoAlarm)
            //        {
            //            txtHighAlarm[channel].Text = res_man.GetString("No Alarm", cul);
            //            txtLowAlarm[channel].Text = res_man.GetString("No Alarm", cul);
            //        }
            //        else
            //        {
            //            txtHighAlarm[channel].Text = (dev_general.Channels[i].AlarmMax / 10).ToString();
            //            txtLowAlarm[channel].Text = (dev_general.Channels[i].AlarmMin / 10).ToString();
            //        }
            //        txtDescription[channel].Text = dev_general.Channels[i].Desc;
            //        txtCurrentValue[channel].Text = (mGlobal.get_temp(buf[3 + 7 * i], buf[4 + 7 * i]) / tmpDiv).ToString();
            //        channel += 1;
            //    }
            //    else if(dev_general.Channels[i].Sensor == 4)
            //    {
            //        txtChannel[channel].Text = (i + 1).ToString();
            //        txtUnit[channel].Text = mGlobal.IntToUnit35(dev_general.Channels[i].Sensor);
            //        txtHighAlarm[channel].Text = res_man.GetString("No Alarm", cul);
            //        txtLowAlarm[channel].Text = res_man.GetString("No Alarm", cul);
            //        txtDescription[channel].Text = dev_general.Channels[i].Desc;
            //        txtCurrentValue[channel].Text = (mGlobal.get_temp(buf[3 + 7 * i], buf[4 + 7 * i]) / tmpDiv).ToString();
            //        channel += 1;
            //    }
            //}
        }
Example #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            int count = 0;

            if (viewGraph == true)
            {
                btnStart.Enabled = false;
                btnGraph.Enabled = false;
                return;
            }

            for (int i = 0; i < getDeviceInfo.activeDeviceListAl.Count; i++)
            {
                if (getDeviceInfo.activeDeviceListAl[i].ToString().Contains("Pexo35 Custm HID"))
                {
                    string[] show    = new string[4];
                    float[]  CH      = new float[dev_dashboard35.numOfChannel];
                    string   StrDevs = getDeviceInfo.activeDeviceListAl[i].ToString();

                    if (dev_dashboard35.USBOpen(StrDevs))
                    {
                        byte[] buf = new byte[64];

                        dev_dashboard35.readDataProbe(ref buf);
                        //dev_dashboard35.readSettingChannel();

                        dev_dashboard35.Close();

                        DateTime _time = DateTime.Now;

                        string tmpStr = "";
                        for (int j = 0; j < 4; j++)
                        {
                            string hexSensor = buf[2 + j * 7].ToString("X");
                            if (hexSensor != "0")
                            {
                                if (hexSensor.Substring(1, 1) == "3")
                                {
                                    for (int k = 0; k < 3; k++)
                                    {
                                        show[j] += mGlobal.format_numDB35(mGlobal.get_temp(buf[3 + j * 7 + 2 * k], buf[3 + j * 7 + 2 * k + 1]) / 1000.0).ToString() + "  |  ";
                                    }

                                    show[j] = show[j].Substring(0, show[j].Length - 3) + "  (" + arrUnit[i, j] + ")";
                                }
                                else if (hexSensor.Substring(1, 1) == "1" || hexSensor.Substring(1, 1) == "2")
                                {
                                    show[j] = (mGlobal.get_temp(buf[3 + j * 7], buf[3 + j * 7 + 1]) / 10.0).ToString() + "  (" + arrUnit[i, j] + ")";
                                }
                                else
                                {
                                    show[j] = mGlobal.get_temp(buf[3 + j * 7], buf[3 + j * 7 + 1]).ToString() + "  (" + arrUnit[i, j] + ")";
                                }
                            }

                            //show[j] = mGlobal.format_num(dev_dashboard35.Channels[j].Val) + " " + arrUnit[i, j];
                            tmpStr += show[j];
                            if (arrUnit[i, j] == "--")
                            {
                                show[j] = "---";
                            }
                        }

                        for (int k = 5; k < 5 + 4; k++)
                        {
                            dataGridView1.Rows[count].Cells[k].Value = show[k - 5];
                            if (show[k - 5] != "---" && show[k - 5] != null)
                            {
                                //if (dev_dashboard35.Channels[k - 5].Sensor == 1 || dev_dashboard35.Channels[k - 5].Sensor == 2)
                                //{
                                if (arrMin[i, k - 5] != 65535 && arrMax[i, k - 5] != 65535)
                                {
                                    //double tampMax = (double)dev_dashboard35.Channels[k - 5].AlarmMax / 10.0;
                                    //double tampMin = (double)dev_dashboard35.Channels[k - 5].AlarmMin / 10.0;
                                    if (double.Parse(show[k - 5].Substring(0, show[k - 5].IndexOf(" "))) >= arrMax[i, k - 5])
                                    {
                                        dataGridView1.Rows[count].Cells[k].Style.ForeColor = Color.Red;
                                    }
                                    else if (double.Parse(show[k - 5].Substring(0, show[k - 5].IndexOf(" "))) <= arrMin[i, k - 5])
                                    {
                                        dataGridView1.Rows[count].Cells[k].Style.ForeColor = Color.Blue;
                                    }
                                    else
                                    {
                                        dataGridView1.Rows[count].Cells[k].Style.ForeColor = Color.Black;
                                    }
                                }
                                //}
                            }
                        }
                    }
                    else
                    {
                        dataGridView1.Rows[count].Cells[4].Value = "Connecting";
                        dataGridView1.Rows[count].Cells[1].Value = getDeviceInfo.activeDeviceListAl[i].ToString();
                    }
                    count += 1;
                }
            }
        }