public bool UpdateDevice(byte[] pBuf) { InteractionData tx = new InteractionData(); tx.buff[0] = 0x03; tx.buff[1] = 0x55; //主机-->设备 InteractionData rx = DeviceInteraction(tx); if (rx == null || rx.CheckDataList() == false) { return(false); } HexID[0] = rx.buff[0x10]; HexID[1] = rx.buff[0x11]; HexID[2] = rx.buff[0x12]; HexID[3] = rx.buff[0x13]; tx = new InteractionData(); rx = DeviceInteraction(tx); if (rx == null || rx.CheckDataList() == false) { return(false); } HexVer[0] = rx.buff[0x10]; HexVer[1] = rx.buff[0x11]; return(true); }
public HIDResult CANInfoDataStep(int step, out InteractionData rx) { InteractionData tx = new InteractionData(); tx.buff[0] = 0x14; tx.buff[1] = 0x55; //主机-->设备 tx.buff[4] = 0x20; for (int i = 0; i < 0x10; i++) { tx.buff[i + 0x10] = CANInfo_AT[step, i]; } rx = DeviceInteraction(tx); if (rx == null) { return(HIDResult.USBError); } else if (rx.CheckDataList() == false) { return(HIDResult.RxError); } else if (rx.buff[1] == 0x00) { return(HIDResult.OK); } else { return(HIDResult.CANErr); } }
//public byte[] SwVer=new byte[2]{0x20,0x01}; public bool CheckDevice() { InteractionData tx = new InteractionData(); tx.buff[0] = 0x03; tx.buff[1] = 0x55; //主机-->设备 InteractionData rx = DeviceInteraction(tx); if (rx == null || rx.CheckDataList() == false) { return(false); } HexID[0] = rx.buff[0x10]; HexID[1] = rx.buff[0x11]; HexID[2] = rx.buff[0x12]; HexID[3] = rx.buff[0x13]; // if (HexID[0] != 0x01) // return false; // // if (HexID[0] != 0x04 || HexID[1] != 0x45 || HexID[2] != 0x61 || HexID[3] != 0x67) // // return false; tx = new InteractionData(); rx = DeviceInteraction(tx); if (rx == null || rx.CheckDataList() == false) { return(false); } HexVer[0] = rx.buff[0x10]; HexVer[1] = rx.buff[0x11]; return(true); }
public HIDResult CANEeprom2Step(int step, out InteractionData rx, out int rxCount) { InteractionData tx = new InteractionData(); tx.buff[0] = 0x14; tx.buff[1] = 0x55; //主机-->设备 tx.buff[4] = 0x20; for (int i = 0; i < 0x10; i++) { tx.buff[i + 0x10] = CANEeprom_b[step % 3, i]; } rxCount = CANEeprom_b[step % 3, 0x0f]; if (0x01 == (step % 3)) { tx.buff[0x0A + 0x10] = CANEeprom_Cmd00[step / 3]; } rx = DeviceInteraction(tx); if (rx == null) { return(HIDResult.USBError); } else if (rx.CheckDataList() == false) { return(HIDResult.RxError); } else if (rx.buff[1] == 0x00) { return(HIDResult.OK); } else { return(HIDResult.CANErr); } }
public HIDResult EZSReadDataStep(int step, EZSMode mode, out InteractionData rx) { InteractionData tx = new InteractionData(); tx.buff[0] = 0x0D; tx.buff[1] = 0x55; //主机-->设备 tx.buff[0x0A] = 0x02; //cnt tx.buff[0x0B] = 0x6F; // if (mode == EZSMode.NEC) // { // tx.buff[0x0C] = DTnec[step]; // } // else if (mode == EZSMode.MOT) // { // tx.buff[0x0C] = DTmot[step]; // } tx.buff[0x0C] = (byte)step; byte tmp_cmd = tx.buff[0x0C]; rx = DeviceInteraction(tx); if (rx == null) { return(HIDResult.USBError); } else if (rx.CheckDataList() == false) { return(HIDResult.RxError); } else if (rx.buff[0x01] == 0x01) { return(HIDResult.ReadEZSError1); } else if (rx.buff[0x01] == 0x02) { return(HIDResult.ReadEZSError2); } else if (rx.buff[0x0B] != 0x70) { return(HIDResult.ReadEZSError3); } // else if (rx.buff[0x0C] != tmp_cmd) // { // return HIDResult.ReadEZSError4; // } else if (rx.buff[1] == 0x00) { return(HIDResult.OK); } else { return(HIDResult.ReadEZSError5); } }
public InteractionData DeviceInteraction(InteractionData tx, int n) { try { //int rxCount = HIDStream.Read(InputReport, 0, m_nInputReportLength); if (HIDProcCallback != null) { HIDProcCallback(-2); } HIDStream.Write(tx.GetDataList(), 0, m_nOutputReportLength); byte[] InputReport = new byte[m_nInputReportLength]; IAsyncResult ia = HIDStream.BeginRead(InputReport, 0, m_nInputReportLength, null, null); for (int s = 0; s < n; s++) { if (ia.AsyncWaitHandle.WaitOne(500, false)) { if (HIDProcCallback != null) { HIDProcCallback(-1); } InteractionData rx = new InteractionData(InputReport); return(rx); } else { if (HIDProcCallback != null) { HIDProcCallback(s + 1); } } } if (HIDProcCallback != null) { HIDProcCallback(-1); } HIDStream.Close(); HIDStream.Dispose(); HIDStream = null; m_hHandle = CreateFile(hidPath, GENERIC_READ | GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, IntPtr.Zero); HIDStream = new FileStream(m_hHandle, FileAccess.Read | FileAccess.Write, m_nInputReportLength, true); return(null); } catch (IOException ex) { // The device was removed! throw new HIDDeviceException(ex.Message + ":Device was removed"); } }
public HIDResult CANWrite4Step(int step, out InteractionData rx) { InteractionData tx = new InteractionData(); tx.buff[0] = 0x14; tx.buff[1] = 0x55; //主机-->设备 tx.buff[4] = 0x20; for (int i = 0; i < 0x10; i++) { tx.buff[i + 0x10] = CANwr_d[step % 2, i]; } if (step % 2 == 1) { for (int i = 0; i < 0x08; i++) { tx.buff[i + 0x13] = DTwr[0x08 * DTwrIndex + i];//DATAwr[k][i]; } tx.buff[0x12] = (byte)DTwrIndex; DTwrIndex++; } rx = DeviceInteraction(tx); if (rx == null) { return(HIDResult.USBError); } else if (rx.CheckDataList() == false) { return(HIDResult.RxError); } else if (rx.buff[1] == 0x00) { return(HIDResult.OK); } else if (rx.buff[1] == 0x03) { return(HIDResult.CANWriteWait); } else { return(HIDResult.CANErr); } }
public bool Check_mima() { InteractionData tx = new InteractionData(); tx.buff[0] = 0x03; tx.buff[1] = 0x55; //主机-->设备 InteractionData rx = DeviceInteraction(tx); if (rx == null || rx.CheckDataList() == false) { return(false); } KEY[0] = 0x02; KEY[1] = 0x58; KEY[2] = 0xBE; KEY[3] = 0x24; // KEY[4] = 0x8A; // KEY[5] = 0x95; // KEY[6] = 0x60; // KEY[7] = 0x3D; KEY[4] = (byte)(HexID[0] - 0x77); KEY[5] = (byte)(HexID[1] - 0x55); KEY[6] = (byte)(HexID[2] - 0x33); KEY[7] = (byte)(HexID[3] - 0x11); HOP[0] = rx.buff[0x14]; HOP[1] = rx.buff[0x15]; HOP[2] = rx.buff[0x16]; HOP[3] = rx.buff[0x17]; DECRYPT(); if ((HOP[0x02] == rx.buff[0x18]) && (HOP[3] == rx.buff[0x19])) { return(true); } else { return(false); } }
public InteractionData DeviceInteraction(InteractionData tx) { return(DeviceInteraction(tx, 80)); }