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); } }
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(); }
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); }
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); } }