public static int DDR_MassWrite(uint wCmd, int wCmdLen, byte[] xferBuf, int wDataLen) { bool ret = true; if (wDataLen > xferBuf.Length) { return(Chip.ERROR_BUFLEN_ERR); } if (wCmdLen < 1 || wCmdLen > 4) { return(Chip.ERROR_BUFLEN_ERR); } IntPtr WriteDataPtr = Marshal.AllocHGlobal(wDataLen); for (int i = wCmdLen; i > 0; i--) { if (!SL_AddrWrite((byte)((wCmd >> (8 * (wCmdLen - 1))) & 0xff))) { return(Chip.ERROR_DISDATAWR); } } Marshal.Copy(xferBuf, 0, WriteDataPtr, wDataLen); // xferBuf to WriteDataPtr ret = Epp2USB.UsbWriteScanner(WriteDataPtr, (uint)wDataLen, RWSCANNER_EPPCTL_8BIT); Marshal.FreeHGlobal(WriteDataPtr); return((ret == true) ? Chip.ERROR_RESULT_OK : Chip.ERROR_DISDATAWR); }
public static int SL_CommBase_MassRead(uint wCmd, int wCmdLen, ref byte[] xferBuf, int xbufLen) { if (xferBuf.Length < xbufLen) { return(Chip.ERROR_BUFLEN_ERR); } if (wCmdLen < 1 || wCmdLen > 4) { return(Chip.ERROR_BUFLEN_ERR); } if (!SL_AddrWrite(ADDRWRMODE)) { return(Chip.ERROR_DISADDRWR); } for (int i = wCmdLen; i > 0; i--) { if (!SL_DataWrite((byte)((wCmd >> (8 * (wCmdLen - 1))) & 0xff))) { return(Chip.ERROR_DISDATAWR); } } if (!SL_AddrWrite(DATARDMODE)) { return(Chip.ERROR_DISDATAWR); } IntPtr ReadBackDatapPtr = Marshal.AllocHGlobal(xbufLen); bool ret = Epp2USB.UsbReadScanner(ReadBackDatapPtr, (uint)xbufLen, RWSCANNER_EPPCTL_8BIT); Marshal.Copy(ReadBackDatapPtr, xferBuf, 0, xbufLen); //ReadBackDatapPtr to xferBuf Marshal.FreeHGlobal(ReadBackDatapPtr); return((ret == true) ? Chip.ERROR_RESULT_OK : Chip.ERROR_RESULT_FAIL); }
public static byte GpioWR(int g1, int g2, int g3, int g4, int g5, int g6, int g7) { // Bit 0~6 are mapped to GPIO 1~7, "0"-> input, "1"-> output byte x = (byte)((g7 << 6) + (g6 << 5) + (g5 << 4) + (g4 << 3) + (g3 << 2) + (g2 << 1) + g1); Epp2USB.GLGpioWrite(x); return(x); }
public static int SL_CommBase_MassDataWrite(byte[] xferBuf) { bool Ret = true; int xferLen = xferBuf.Length; if (!SL_AddrWrite(DATAWRMODE)) { return(Chip.ERROR_DISADDRWR); } IntPtr WriteDataPtr = Marshal.AllocHGlobal(xferLen); Marshal.Copy(xferBuf, 0, WriteDataPtr, xferLen); // xferBuf to WriteDataPtr Ret = Epp2USB.UsbWriteScanner(WriteDataPtr, (uint)xferLen, RWSCANNER_EPPCTL_8BIT); Marshal.FreeHGlobal(WriteDataPtr); return((Ret == true) ? Chip.ERROR_RESULT_OK : Chip.ERROR_DISDATAWR); }
public static int SL_CommBase_WriteCommand(byte[] xferBuf, int xbufLen) { if (xferBuf.Length < xbufLen || xbufLen > 64) { return(Chip.ERROR_BUFLEN_ERR); } if (xbufLen % 2 == 1) { return(Chip.ERROR_BUFLEN_ERR); } IntPtr WriteDataPtr = Marshal.AllocHGlobal(xbufLen); Marshal.Copy(xferBuf, 0, WriteDataPtr, xbufLen); // xferBuf to WriteDataPtr bool ret = Epp2USB.UsbWriteCommand(WriteDataPtr, xbufLen); Marshal.FreeHGlobal(WriteDataPtr); return((ret == true) ? Chip.ERROR_RESULT_OK : Chip.ERROR_DISDATAWR); }
public static int SL_CommBase_MassRead(ref byte[] xferBuf, int xbufLen, bool Mass) { bool ret = true; if (!SL_AddrWrite(DATARDMODE)) { return(Chip.ERROR_DISDATAWR); } if (Mass) { IntPtr ReadBackDatapPtr = Marshal.AllocHGlobal(xbufLen); ret = Epp2USB.UsbReadScanner(ReadBackDatapPtr, (uint)xbufLen, RWSCANNER_EPPCTL_8BIT); Marshal.Copy(ReadBackDatapPtr, xferBuf, 0, xbufLen); //ReadBackDatapPtr to xferBuf Marshal.FreeHGlobal(ReadBackDatapPtr); } else { for (int i = 0; i < xbufLen; i++) { xferBuf[i] = SL_DataRead(); } } return((ret == true) ? Chip.ERROR_RESULT_OK : Chip.ERROR_RESULT_FAIL); }
public static int GpioRD() { // Bit 0~6 are mapped to GPIO 1~7, "0"-> input, "1"-> output return(Epp2USB.GLGpioRead()); }
public static byte SL_DataRead() { return(Epp2USB.GLReadEPPDataPort()); }
public static bool SL_DataWrite(byte Data) { return(Epp2USB.GLWriteEPPDataPort(Data)); }
public static bool SL_AddrWrite(byte Data) { return(Epp2USB.GLWriteEPPAddressPort(Data)); }
public static bool Device_Close() { return(Epp2USB.GeneCloseHandle()); }
public static bool Device_Open(ushort Vid, ushort Pid) { return(Epp2USB.FindScanner(Vid, Pid)); }