Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def CounterInit(self, counter):
'''
This command initializes the 32-bit event counter. On a write, the
counter will be initialized to zero.
'''
request_type = libusb1.LIBUSB_TYPE_VENDOR
wValue = 0
wIndex = 0
result = self.udev.controlWrite(request_type, self.COUNTER, wValue, wIndex, [counter], timeout = 100)
def DIn(self, port=0):
'''
This command reads the current state of the digital port pins.
port: the port to read (there is only one) 0: onboard (pins 0-7)
'''
request_type = libusb1.LIBUSB_TYPE_VENDOR
wValue = 0
wIndex = 0
data = self.udev.controlRead(request_type, self.DIN, port, wIndex, 2, timeout = 100)
return data[0]
def AOutScanStop(self):
'''
This command stops the analog output scan (if running) and
clears the output FIFO data. Any data in the endpoint buffers will
be flushed, so this command is useful to issue prior to the
beginning of an output scan.
'''
request_type = libusb1.LIBUSB_TYPE_VENDOR
result = self.udev.controlWrite(request_type, self.AOUT_SCAN_STOP, 0x0, 0x0, [0x0], timeout = 100)
def AInScanStop(self):
'''
This command stops the analog input scan (if running)
'''
request_type = libusb1.LIBUSB_TYPE_VENDOR
wValue = 0
wIndex = 0
result = self.udev.controlWrite(request_type, self.AIN_SCAN_STOP, wValue, wIndex, [0], timeout = 100)
def readReply(self):
"""
Get a raw binary reply from device.
Returns the reply.
"""
reply_length = 0
while reply_length == 0:
reply_length = self._getReplyLength()
if reply_length == 0: sleep(0.1)
reply = self.usb_handle.controlRead(libusb1.LIBUSB_TYPE_VENDOR | \
libusb1.LIBUSB_RECIPIENT_INTERFACE,
0x81, 0, 0, reply_length)
#print '%04i< %s' % (len(reply), dump(reply))
return reply
def MemoryR(self, address, length):
'''
This command reads data from the available data EEPROM memory.
The number of bytes to read is specified in the wLength (for
writes it is wLength - sizeof(address)). The first 2 byes of data is
the address.
Note: this function is not reentrant
*/
'''
request_type = libusb1.LIBUSB_TYPE_VENDOR
wValue = address
wIndex = 0
try:
result = self.udev.controlRead(request_type, self.MEMORY, wValue, wIndex, length, timeout = 100)
except:
print('MemoryR: error')
return result
def DIn(self, port=0):
'''
This command reads the current state of the digital port pins.
port: the port to read (there is only one) 0: onboard (pins 0-7)
'''
request_type = libusb1.LIBUSB_TYPE_VENDOR
wValue = 0
wIndex = 0
data = self.udev.controlRead(request_type, self.DIN, port, wIndex, 2, timeout = 100)
return data[0]
def AInScanStop(self):
'''
This command stops the analog input scan (if running)
'''
request_type = libusb1.LIBUSB_TYPE_VENDOR
wValue = 0
wIndex = 0
result = self.udev.controlWrite(request_type, self.AIN_SCAN_STOP, wValue, wIndex, [0], timeout = 100)
def AOutScanStatus(self):
'''
This comamnd reads the status of the analog output scan:
depth: the number of samples currently in the FIFO (max 1024)
status: bit 0: 1 = scan running
bit 1: 1 = scan underrun
bits 2-7: reserved
'''
request_type = libusb1.LIBUSB_TYPE_VENDOR
result = unpack('BBB',self.udev.controlRead(request_type, self.AOUT_SCAN_STATUS, 0x0, 0x0, 3, timeout = 100))
depth = (result[0] | result[1] << 8)
status = result[2]
return (depth, status)
5: AIn offset calibration
6: AIn gain calibration
7: TC Offset Calibration
8: TC Gain Calibration Positive
9: TC Gain Calibration Negative
10: Thermocouple no burnout detect
range: 0-8
rate: 0-15
value: signed 24 bit value frad from the analog input channel
flags: bits 0-6: reserved
bit7: 1 = TC open detected, 0 = normal reading
'''
wValue = (mode << 8) | channel
wIndex = (rate << 8) | gain
request_type = libusb1.LIBUSB_TYPE_VENDOR
data ,= unpack('I',self.udev.controlRead(request_type, self.AIN, wValue, wIndex, 4, timeout = 200))
flags = (data >> 24)
data = self.int24ToInt(data)
return (data, flags)