示例#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 = ".....";
        }