Exemple #1
0
        private void btnReadSetting_Click(object sender, EventArgs e)
        {
            getDeviceInfo.getActiveDevice();
            if (getDeviceInfo.activeDeviceListAl.Count == 0)
            {
                MessageBox.Show("Troi oi! Chua cam logger kia thim 2!");
                return;
            }
            device35.hostport = getDeviceInfo.activeDeviceListAl[0].ToString();

            lblStatus.Text = "Reading.....Please wait";
            lblStatus.Update();

            string StrDevs = device35.hostport;

            //Open Device
            if (device35.USBOpen(StrDevs) == false)
            {
                MessageBox.Show("Open USB fail. Please try again.");
                lockButton(false);
                this.Close();
                return;
            }
            //read Serial
            if (device35.readSerial() == false)
            {
                MessageBox.Show("Read Eeprom fail. Please check USB caple!");
                lockButton(false);
                device35.Close();
                return;
            }
            txtSerial.Text = device35.Serial;
            rtxtEventLog.Clear();
            rtxtEventLog.Text += "Hardware: " + device35.HardVer + " Firmware: " + device35.FirmVer;
            device35.Close();


            //read Location
            device35.USBOpen(StrDevs);
            if (device35.readLocation() == false)
            {
                MessageBox.Show("Read Location fail");
                lockButton(false);
                device35.Close();
                return;
            }
            txtLocation.Text = device35.Location;
            device35.Close();


            //read Description
            device35.USBOpen(StrDevs);
            if (device35.readDescription() == false)
            {
                MessageBox.Show("Read description fail");
                lockButton(false);
                device35.Close();
                return;
            }

            txtDescription.Text = device35.Description;
            device35.Close();


            //read Description
            device35.USBOpen(StrDevs);

            //--------------read Setting (Time, TimeZone, Delay, Duration)
            if (device35.readSettingDevice() == false)
            {
                MessageBox.Show("Read Setting fail");
                lockButton(false);
                device35.Close();
                return;
            }


            string TimeZone = mGlobal.FindSystemTimeZoneFromString(device35.Timezone.ToString()).ToString();

            for (int i = 0; i <= cbbTimeZone.Items.Count - 1; i++)
            {
                if (cbbTimeZone.Items[i].ToString() == TimeZone)
                {
                    cbbTimeZone.Text = cbbTimeZone.Items[i].ToString();
                }
            }
            if (device35.Duration != 65535)
            {
                int sec1 = 0;
                int min2 = 0;

                if (Convert.ToInt32(device35.Duration) > 60)
                {
                    min2             = Convert.ToInt32(device35.Duration) / 60;
                    sec1             = Convert.ToInt32(device35.Duration) % 60;
                    lb_interval.Text = "Sample interval: " + min2 + " min " + sec1 + " sec.";
                }
                else
                {
                    lb_interval.Text = "Sample interval: " + Convert.ToInt32(device35.Duration) + " sec.";
                }
            }
            else
            {
                lb_interval.Text = 0.ToString();
            }

            if (device35.Delay == 255)
            {
                cbbStartDelay.Text = cbbStartDelay.Items[0].ToString();
            }
            else
            {
                cbbStartDelay.Text = device35.Delay.ToString();
            }

            if (device35.Duration == 65535)
            {
                cbbDuration.Text = cbbDuration.Items[0].ToString();
            }
            else
            {
                cbbDuration.Text = device35.Duration.ToString();
            }

            device35.Close();

            for (int i = 0; i < 4; i++)
            {
                device35.USBOpen(StrDevs);
                if (device35.readSettingChannel1(i) == false)
                {
                    MessageBox.Show("Read Setting fail");
                    lockButton(false);
                    device35.Close();
                    return;
                }
                device35.Close();
            }

            cbbChannel_SelectedIndexChanged(sender, e);

            lblStatus.Text = ".....";
        }
Exemple #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;
            //    }
            //}
        }
Exemple #3
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            string str_device   = "";
            int    numofChannel = 0;
            int    count        = 0;

            for (int i = 0; i < getDeviceInfo.activeDeviceListAl.Count; i++)
            {
                dev_dashboard35 = Device35.DelInstance();
                dev_dashboard35 = Device35.Instance;
                str_device      = getDeviceInfo.activeDeviceListAl[i].ToString();
                if (getDeviceInfo.activeDeviceListAl[i].ToString().Contains("Pexo35 Custm HID"))
                {
                    dev_dashboard35.USBOpen(str_device);

                    dev_dashboard35.readLocation();
                    dev_dashboard35.readDescription();
                    dev_dashboard35.readSerial();
                    dev_dashboard35.readSettingDevice();

                    dev_dashboard35.Channels = new Channel[4];
                    for (int k = 0; k < 4; k++)
                    {
                        dev_dashboard35.Channels[k] = new Channel();
                    }
                    dev_dashboard35.readSettingChannel();


                    for (int j = 0; j < 4; j++)
                    {
                        if (dev_dashboard35.Channels[j].Sensor == 3)
                        {
                            numofChannel += 3;
                        }
                        else if (dev_dashboard35.Channels[j].Sensor != 0)
                        {
                            numofChannel += 1;
                        }
                    }


                    for (int j = 0; j < 4; j++)
                    {
                        if (dev_dashboard35.byteLogging == 0x44)
                        {
                            arrUnit[i, j] = mGlobal.IntToUnit_Dashboard35(dev_dashboard35.Channels[j].Unit, dev_dashboard35.Channels[j].Sensor);
                        }
                        else
                        {
                            arrUnit[i, j] = "--";
                        }
                        if (!dev_dashboard35.Channels[j].NoAlarm)
                        {
                            arrMax[i, j] = (double)dev_dashboard35.Channels[j].AlarmMax / 10.0;
                            arrMin[i, j] = (double)dev_dashboard35.Channels[j].AlarmMin / 10.0;
                        }
                        else
                        {
                            arrMax[i, j] = 65535;
                            arrMin[i, j] = 65535;
                        }
                    }


                    dataGridView1.Rows.Add("", "");
                    dataGridView1.Rows[count].Cells[0].Value = count.ToString();
                    dataGridView1.Rows[count].Cells[1].Value = getDeviceInfo.activeDeviceListAl[i].ToString();
                    dataGridView1.Rows[count].Cells[2].Value = dev_dashboard35.Location;
                    dataGridView1.Rows[count].Cells[3].Value = dev_dashboard35.Description;
                    dataGridView1.Rows[count].Cells[4].Value = dev_dashboard35.Serial;

                    count += 1;

                    dev_dashboard35.Close();
                }
            }
            if (btnStart.Text == "Run")
            {
                btnStart.Text  = "Stop";
                timer1.Enabled = true;
            }
            else
            {
                btnStart.Text  = "Run";
                timer1.Enabled = false;
            }

            if (count == 0)
            {
                btnGraph.Enabled = false;
                btnStart.Enabled = false;
            }
        }