|Online Development Notebook > Index > Programming Overview > Device Commands > ReadB|
ReadB - Read byte value from port B
This is a function that 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.
Command Syntax: (USBm.dll)
USBm_ReadB( device, dataarray )
The USBm_ReadB function syntax has these parts:
|device||A zero-based index to address the appropriate USB device.|
|dataarray||A byte array where the returned data will be stored. Minimum size of the array must be 1 byte|
Port B does not have to have all 8 bits set to input for this to work. You can have a mix of inputs and outputs on the port and this command will read the entire port.
|Public Declare Function USBm_ReadB _|
Lib "USBm.dll" _
(ByVal device As Byte, _
ByRef dataarray As Byte) _
|Dim dataarray(1) As Byte|
USBm_ReadB 4, dataarray(0)
This code fragment reads port B of device 4, placing the result into "dataarray(0)".
|int USBm_ReadB( unsigned char device, unsigned char *data );|
Returns the byte value representing the states of the pins on Port A⁄B. The value returned is not a valid value if the device is not a validly active device.
Raw Command Format:
Raw Command Format Details:
Byte 0 contains the command. Byte 1 through byte 7 are unused.
Raw Command Response Format:
|1||Data read from port B|
Raw Command Response Format Details:
Byte 0 contains the command. Byte 1 contains the current value of port B. Byte 2 through byte 7 are unused.
Raw Command Example Usage:
If the port lines were hi⁄hi⁄hi⁄hi⁄lo⁄lo⁄lo⁄lo (msb high), the command 06-00-00-00-00-00-00-00 would return 06-F0-00-00-00-00-00-00 (assuming that the port is set as all inputs).
Hardware: U401 USB Interface U421 USB Interface U451 USB Interface
Programming: USBm DLL Programming Download Files
Application Notes: U4x1 Application Notes Misc Applications and Information FAQ
While every effort has been made to make sure that the information posted on this site is correct, the author can not be held liable for any damages whatsoever for losses as a result of the application of this information. Use this information at your own risk.
USBmicro can design your custom and semi-custom USB product. Email about USB design can be directed to " Robert " at usbmicro.com.
Copyright © USBmicro, L.L.C., 2002-2010