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