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