def readPipe(self, channel, data, datalen, timeout=1000): """Recv the data to the device.""" bytesTransferred = _ft.ULONG() self.status = call_ft(_ft.FT_ReadPipeEx, self.handle, _ft.UCHAR(channel), data, _ft.ULONG(datalen), c.byref(bytesTransferred), timeout) return bytesTransferred.value
def readPipe(self, pipe, data, datalen): """Recv the data to the device.""" bytesTransferred = _ft.ULONG() self.status = call_ft(_ft.FT_ReadPipe, self.handle, _ft.UCHAR(pipe), data, _ft.ULONG(datalen), c.byref(bytesTransferred), None) return bytesTransferred.value
def readPipeEx(self, channel, datalen, timeout=1000, raw=False): """Recv the data to the device.""" bytesTransferred = _ft.ULONG() data = c.c_buffer(datalen) self.status = call_ft(_ft.FT_ReadPipeEx, self.handle, _ft.UCHAR(channel), data, _ft.ULONG(datalen), c.byref(bytesTransferred), timeout) return { 'bytesTransferred': bytesTransferred.value, 'bytes': data.value[:bytesTransferred.value] if raw == False else data.raw[:bytesTransferred.value] }
def readPipeEx(self, pipe, datalen, raw=True): """Recv the data to the device.""" bytesTransferred = _ft.ULONG() data = c.c_buffer(datalen) self.status = call_ft(_ft.FT_ReadPipe, self.handle, _ft.UCHAR(pipe), data, _ft.ULONG(datalen), c.byref(bytesTransferred), None) return { 'bytesTransferred': bytesTransferred.value, 'bytes': data.raw[:bytesTransferred.value] if raw == True else data.value[:bytesTransferred.value] }
def getUnsentBuffer(self, channel): """Get the current bytes not yet sent to device.""" # get size only bytesTransferred = _ft.ULONG() self.status = call_ft(_ft.FT_GetUnsentBuffer, self.handle, None, c.byref(bytesTransferred)) if (bytesTransferred == 0): return {'bytesTransferred': 0, 'bytes': None} # get and buffer data = c.c_buffer(bytesTransferred) bytesTransferred = 0 self.status = call_ft(_ft.FT_GetUnsentBuffer, self.handle, data, c.byref(bytesTransferred)) return { 'bytesTransferred': bytesTransferred.value, 'bytes': data.raw[:bytesTransferred.value] if raw == True else data.value[:bytesTransferred.value] }
def getWriteQueueStatus(self, channel): """Get the current bytes in the write queue.""" bytesInQueue = _ft.ULONG() self.status = call_ft(_ft.FT_GetWriteQueueStatus, self.handle, channel, c.byref(bytesInQueue)) return bytesInQueue
def getSuspendTimeout(self): """Get suspend timeout""" timeout = _ft.ULONG() self.status = call_ft(_ft.FT_GetSuspendTimeout, self.handle, c.byref(timeout)) return timeout.value
def setSuspendTimeout(self, timeout): """Set suspend timeout""" self.status = call_ft(_ft.FT_SetSuspendTimeout, self.handle, _ft.ULONG(timeout)) return None
def setStreamPipe(self, pipe, size): """Set stream pipe for continous transfer of fixed size""" self.status = call_ft(_ft.FT_SetStreamPipe, self.handle, _ft.BOOLEAN(0), _ft.BOOLEAN(0), _ft.UCHAR(pipe), _ft.ULONG(size)) return None
def getPipeTimeout(self, pipeid): """Get pipe timeout""" timeoutMS = _ft.ULONG() self.status = call_ft(_ft.FT_GetPipeTimeout, self.handle, _ft.UCHAR(pipeid), c.byref(timeoutMS)) return timeoutMS.value
def setPipeTimeout(self, pipeid, timeoutMS): """Set pipe timeout""" self.status = call_ft(_ft.FT_SetPipeTimeout, self.handle, _ft.UCHAR(pipeid), _ft.ULONG(timeoutMS)) return None
def setGPIOPull(self, mask, pull): """Set GPIO pull""" self.status = call_ft(_ft.FT_SetGPIOPull, self.handle, _ft.ULONG(mask), _ft.ULONG(pull)) return None
def readGPIO(self): """Read GPIO""" gpio = _ft.ULONG() self.status = call_ft(_ft.FT_ReadGPIO, self.handle, c.byref(gpio)) return gpio.value
def writeGPIO(self, mask, data): """Write GPIO""" self.status = call_ft(_ft.FT_WriteGPIO, self.handle, _ft.ULONG(mask), _ft.ULONG(data)) return None
def enableGPIO(self, mask, direction): """Enable GPIO""" self.status = call_ft(_ft.FT_EnableGPIO, self.handle, _ft.ULONG(mask), _ft.ULONG(direction)) return None