Exemple #1
0
        public bool ReadTimeOut(ref byte[] buf)
        {
            try
            {
                byte[] msg = new byte[64];
                short  res = 0;

                if (dev == 0)
                {
                    strStatus = "device = 0" + "\r\n";
                    return(false);
                }

                res = HIDFunction.hid_ReadTimeOut(dev, ref buf[0], 64, 500);
                if (res <= 0)
                {
                    strStatus += " error (res=" + res + ")" + "\r\n";
                    HIDFunction.hid_Error(dev, ref msg[0]);
                    strStatus += "Error= " + msg.ToString() + "\r\n";
                    return(false);
                }
                return(true);
            }
            catch (Exception)
            {
                MessageBox.Show("Read_setting false. status=" + strStatus);
                return(false);
            }
        }
Exemple #2
0
        public bool ReadG(ref byte[] buf)
        {
            try
            {
                byte[] msg = new byte[64];
                int    res = 0;

                //if (dev == 0)
                //{
                //    strStatus = "device = 0" + "\r\n";
                //    return false;
                //}

                //res = HIDFunction.hid_Get_Feature_Report(dev, ref buf[0], 64);
                res = HIDFunction.hid_ReadG(devG, buf, 64);

                if (res <= 0)
                {
                    strStatus += " error (res=" + res + ")" + "\r\n";
                    HIDFunction.hid_Error(dev, ref msg[0]);
                    strStatus += "Error= " + msg.ToString() + "\r\n";
                    return(false);
                }

                res = HIDFunction.hid_Exit();
                return(true);
            }
            catch (Exception)
            {
                MessageBox.Show("Read_setting false. status=" + strStatus);
                return(false);
            }
        }
Exemple #3
0
        public static string nhanDang(long dev)
        {
            if (dev != 0)
            {
                bool   dem  = true;
                string name = "";
                while (true)
                {
                    short  res = 0;
                    byte[] buf = new byte[64];

                    buf[0] = byte.Parse(0x01.ToString());
                    buf[1] = byte.Parse(0xa8.ToString());
                    //buf[2] = byte.Parse(0x50.ToString());
                    //buf[3] = byte.Parse(0x43.ToString());

                    //HIDFunction.hid_SetNonBlocking(dev, 1);

                    res = HIDFunction.hid_Write(dev, ref buf[0], 64);
                    if (res < 0)
                    {
                        return("Cannot connect to device a8.");
                    }
                    //Thread.Sleep(5);
                    buf[0] = 0x02;
                    res    = HIDFunction.hid_Read(dev, ref buf[0], 64);
                    if (res < 0)
                    {
                        return("Cannot connect to device a8.");
                    }

                    if (buf[2] == 238 && buf[3] == 238 && dem)
                    {
                        //dem = false;
                        Thread.Sleep(200);
                        continue;
                        //goto Line0;
                    }
                    else
                    {
                        for (int i = 0; i < 7; i++)
                        {
                            name += (char)buf[i + 2];
                        }
                        break;
                    }
                }
                return(name);
            }
            else
            {
                return("er");
            }
        }
Exemple #4
0
        public static void getActiveDevice()
        {
            Li :  activeSerialAL.Clear();
            activeDeviceListAl.Clear();

            byte[] buf = new byte[500];
            string s   = "";

            Int64 devs;
            Int64 curdev;

            //HIDFunction.hid_Init();

            devs = HIDFunction.hid_Enumerate(0, 0);
            //MessageBox.Show(devs.ToString());
            curdev = devs;

            while (curdev != 0)
            {
                //ushort vid = HIDFunction.hid_DeviceVendorID(curdev);
                //ushort pid = HIDFunction.hid_DeviceProductID(curdev);

                Device device = Device.DelInstance();
                device = Device.Instance;
                s      = device.getHostPort(curdev);

                //MessageBox.Show(s);

                if (s == "er")
                {
                    //HIDFunction.hid_FreeEnumeration(curdev);
                    HIDFunction.hid_FreeEnumeration(devs);
                    goto Li;
                }

                //if (device.Product == "Datalogger8S" || device.Product == "Datalogger4S")
                if (device.Product != "(null)" && device.Serial != "(null)" && s.Contains("483"))
                {
                    //MessageBox.Show(device.Serial);
                    activeDeviceListAl.Add(s);
                    activeSerialAL.Add(device.Serial);

                    mGlobal.usb_id     = s;
                    mGlobal.usb_search = true;
                }
                curdev = HIDFunction.hid_DeviceNext(curdev);
            }
            HIDFunction.hid_Exit();
            HIDFunction.hid_FreeEnumeration(curdev);
            HIDFunction.hid_FreeEnumeration(devs);
            //HIDFunction.hid_Exit();
        }
Exemple #5
0
        public static string nhanDang34(long dev)
        {
            if (dev != 0)
            {
                bool dem = true;
                Line0 : string name = "";
                short  res = 0;
                byte[] buf = new byte[65];

                buf[0] = byte.Parse(0x01.ToString());
                buf[1] = byte.Parse(0xa8.ToString());

                res = HIDFunction.hid_Write(dev, ref buf[0], 65);
                if (res < 0)
                {
                    HIDFunction.hid_Error(dev, ref buf[10]);
                    string b = "";
                    for (int i = 0; i < buf.Length; i++)
                    {
                        char a = (char)buf[i];
                        b += a.ToString();
                    }
                    return("Cannot connect to device.");
                }
                Thread.Sleep(50);

                res = HIDFunction.hid_Read(dev, ref buf[0], 65);
                if (res < 0)
                {
                    return("Cannot connect to device.");
                }

                if (buf[2] == 238 && buf[3] == 238 && dem)
                {
                    dem = false;
                    Thread.Sleep(200);
                    goto Line0;
                }
                else
                {
                    for (int i = 0; i < 7; i++)
                    {
                        name += (char)buf[i + 2];
                    }
                }
                return(name);
            }
            else
            {
                return("er");
            }
        }
Exemple #6
0
        public bool Read(ref byte[] buf)
        {
            try
            {
                byte[] msg = new byte[mGlobal.len];
                short  res = 0;

                if (dev == 0)
                {
                    strStatus = "device = 0" + "\r\n";
                    return(false);
                }

                //buf[0] = byte.Parse(0.ToString());
                //for (int i = 0; i < 3; i++)
                //{
                //    buf[1 + i] = cmd[i];
                //}

                //strStatus = "send_feature(CMD_READ_SS_SETTING)";
                //res = HIDFunction.hid_Write(dev, ref buf[0], 64);
                //if (res < 0)
                //{
                //    strStatus += " error(res=" + res + ")" + "\r\n";
                //    return false;
                //}
                //strStatus += " ok" + "\r\n";
                //strStatus += "Get feature";

                //buf[0] = byte.Parse(0x02.ToString());
                //HIDFunction.hid_SetNonBlocking(dev, 1);
                res = HIDFunction.hid_Read(dev, ref buf[0], mGlobal.len);
                //res = HIDFunction.hidRead(dev, ref buf[0], 64);
                //res = HIDFunction.hid_ReadTimeOut(dev, ref buf[0], 64, 3);
                if (res <= 0)
                {
                    //strStatus += " error (res=" + res + ")" + "\r\n";
                    //HIDFunction.hid_Error(dev, ref msg[0]);
                    //strStatus += "Error= " + msg.ToString() + "\r\n";
                    return(false);
                }

                //res = HIDFunction.hid_Exit();
                return(true);
            }
            catch (Exception)
            {
                MessageBox.Show("Read_setting false. status=" + strStatus);
                return(false);
            }
        }
Exemple #7
0
        public static string readSerial(long dev)
        {
            string name = "";
            short  res  = 0;

            byte[] bufSerial = new byte[65];
            bufSerial[0] = 0x01;
            bufSerial[1] = 0xa1;
            bufSerial[2] = 0x01;

            res = HIDFunction.hid_Write(dev, ref bufSerial[0], 64);

            if (res < 0)
            {
                return("Cannot connect to device.");
            }

            res = HIDFunction.hid_Read(dev, ref bufSerial[0], 64);

            if (bufSerial[2] == 238 && bufSerial[3] == 238)
            {
                return("Cannot connect to device.");
            }
            else
            {
                for (int i = 0; i < 10; i++)
                {
                    if (bufSerial[i + 2] == 0xff)
                    {
                        name += "FF";
                    }
                    else
                    {
                        name += (char)bufSerial[i + 2];
                    }
                }
            }
            return(name);
        }
Exemple #8
0
        public bool WriteG(byte[] buf)
        {
            byte[] msg = new byte[100];
            int    res = 0;

            //if (dev == 0)
            //{
            //    strStatus = "device = 0" + Environment.NewLine;
            //    return false;
            //}

            //res = HIDFunction.hid_SendFeatureReport(dev, ref buf[0], 64);
            res = HIDFunction.hid_WriteG(devG, buf, 64);

            if (res < 0)
            {
                //HIDFunction.hid_Error(dev, ref msg[0]);
                //MessageBox.Show(msg.ToString());
                return(false);
            }
            res = HIDFunction.hid_Exit();
            return(true);
        }
Exemple #9
0
        public bool Send(byte[] buf)
        {
            byte[] msg = new byte[100];
            short  res = 0;

            if (dev == 0)
            {
                strStatus = "device = 0" + Environment.NewLine;
                return(false);
            }

            strStatus = "send_feature(CMD_WRITE_SERIAL_NUM)";
            res       = HIDFunction.hid_SendFeatureReport(dev, ref buf[0], 3);

            if (res < 0)
            {
                strStatus += "error (res=" + res + Environment.NewLine;
                HIDFunction.hid_Error(dev, ref msg[0]);
                MessageBox.Show(msg.ToString());
                strStatus += "Error = " + msg.ToString() + Environment.NewLine;
                return(false);
            }
            return(true);
        }
Exemple #10
0
        public bool Write(byte[] buf)
        {
            byte[] msg = new byte[100];
            short  res = 0;

            if (dev == 0)
            {
                strStatus = "device = 0" + Environment.NewLine;
                return(false);
            }
            //strStatus = "send_feature(CMD_WRITE_SERIAL_NUM)";
            res = HIDFunction.hid_Write(dev, ref buf[0], mGlobal.len);

            if (res < 0)
            {
                //strStatus += "error (res=" + res + Environment.NewLine;
                //HIDFunction.hid_Error(dev, ref msg[0]);
                //MessageBox.Show(msg.ToString());
                //strStatus += "Error = " + msg.ToString() + Environment.NewLine;
                return(false);
            }
            //res = HIDFunction.hid_Exit();
            return(true);
        }
Exemple #11
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);
            }
        }