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