The USBm.dll can be called from a Python script by using ctypes.
Create a buffer to hold strings and data. Using ctypes, load the USBm32.dll.
1 2 |
USBbuff = create_string_buffer(200) USBpy = windll.USBm32 |
USBpy will then have the following functions:
Discover U4xx devices
USBm_FindDevices() Scan all of the HID devices available on the bus. If a device qualifies as a U4xx, then place the device into the data structure for U4xx devices.
DLL text/string info
USBm_RecentError(buff) Call with a pointer to a string. Modify the string with an error.
USBm_ClearRecentError(buff) Clear error string.
USBm_DebugString(buff) Call with a pointer to a string. Modify the string with a message.
USBm_Copyright(buff) Modify the string with a message.
USBm_About(buff) Modify the string with a message.
USBm_Version(buff) Return version
# Device information – device is an index to U4xx devices only
USBm_NumberOfDevices() Return the number of valid devices on USB bus. (0 to 20)
USBm_DeviceValid(index) Valid “device” from 1 to MAX_U4xx_DEVICES. Any other number results in a FALSE return. Return VB_TRUE(-1) or VB_FALSE(0) for valid devices on USB bus.
USBm_DeviceVID(index) Valid “device” from 1 to MAX_U4xx_DEVICES. Any other number results in a FALSE return. Return False(0) or VID for valid device.
USBm_DevicePID(index) Valid “device” from 1 to MAX_U4xx_DEVICES. Any other number results in a FALSE return. Return False or PID for valid device.
USBm_DeviceDID(index) Valid “device” from 1 to MAX_U4xx_DEVICES. Any other number results in a FALSE return. Return False or DID for valid device.
USBm_DeviceFirmwareVer(index) Return False or DID for a valid device.
USBm_DeviceMfr(index,buff) Valid “device” from 1 to MAX_U4xx_DEVICES. Any other number results in a FALSE return. Set string to manuf name. Return T/F for valid device.
USBm_DeviceProd(index,buff) Valid “device” from 1 to MAX_U4xx_DEVICES. Any other number results in a FALSE return. Set string to prod name. Return T/F for valid device.
USBm_DeviceSer(index,buff) Valid “device” from 1 to MAX_U4xx_DEVICES. Any other number results in a FALSE return. Set string to ser name. Return T/F for valid device.
# General device I/O (partial list)
USBm_InitPorts(index) Initialize both ports, and resets the device’s internal latches.
USBm_InitPortsU401(index) Initialize both ports, and resets the device’s internal latches.
USBm_InitPortsU421(index) Initialize both ports, and resets the device’s internal latches.
USBm_InitPortsU431(index) Reset port A and B to output and will clear the internal latches.
USBm_InitPortsU451(index) Reset port A to input, port B to output and will clear the internal latches.
USBm_WriteA(index,data) Write a byte value to port A when the port is set as an output.
USBm_WriteB(index,data) Write a byte value to port B when the port is set as an output.
USBm_WriteABit(index,andterm,orterm)) Writes masked values to port A when the port is set as an output. The net result of writing masked values is that only the specified bits will be written. The resulting port condition is the logic combination of the current port state ANDed with the first term and then ORed with the second. This command can affect any number of lines on the port.
USBm_WriteBBit(index,andterm,orterm)) Writes masked values to port B when the port is set as an output. The net result of writing masked values is that only the specified bits will be written. The resulting port condition is the logic combination of the current port state ANDed with the first term and then ORed with the second. This command can affect any number of lines on the port.
USBm_ReadA(index,buff) Reads a byte value from port A. The returned value is the state of the port lines that an external device has set, if the line is an input. The lines that might be configured as outputs return the output state.
USBm_ReadB(index,buff) Reads a byte value from port B. The returned value is the state of the port lines that an external device has set, if the line is an input. The lines that might be configured as outputs return the output state.
USBm_SetBit(index,data) Set a single bit/line high.
USBm_ResetBit(index,data) Set a single bit/line low.
USBm_DirectionA(index,dir0,dir1) Set the i/o direction of port A.
USBm_DirectionAOut(index) Set port A to output.
USBm_DirectionAIn(index) Set port A to input.
USBm_DirectionAInPullup(index) Set port A to input with pull-up resistors enabled.
USBm_DirectionB(index,dir0,dir1) Set the i/o direction of port B.
USBm_DirectionBOut(index) Set port B to output.
USBm_DirectionBIn(index) Set port B to input.
USBm_DirectionBInPullup(index) Set port B to input with pull-up resistors enabled.
USBm_StrobeWrite(index,data,port,sel,len,del) Strobes the write of a byte value to a port. This command selects port A or B for the written byte, as well as a polarity (negative or positive) and a line (A.0 – B.7) to toggle, strobe pulse length, delay between multiple bytes. The byte is written and then the line toggled.
USBm_StrobeRead(index,data,port,sel,len,del) Strobes the read of a byte value from a port. This command selects port A or B for the read byte, as well as a polarity (negative or positive) and a line (A.0 – B.7) to toggle, strobe pulse length, delay between multiple bytes. The line is toggled to one state, the byte is read, and then the line is returned to the initial state.
USBm_ReadLatches(index,buff) Return the values of the internal pin-change latches. After reading changed latches the latches are reset.