| Online Development Notebook > Index > Programming Overview > Device Commands > InitPorts (and variations) |
InitPorts (and variations) - Initialize device, ports
Description:
This is a function that initializes both ports, and resets the device's internal latches.
There are two 8-bit ports on the U401⁄421⁄U451, 16 I⁄O lines. The 16 total I⁄O lines can be set to inputs or outputs on an individual per-line basis. The initial state of the ports on power up is that all of the 16 lines are set to be inputs.
Command Syntax: (USBm.dll)
USBm_InitPorts( device )
The USBm_InitPorts function syntax has these parts:
| Part | Description |
| device | A zero-based index to address the appropriate USB device. |
Remarks:
Calling USBm_InitPorts will reset the ports to input and will clear the internal latches.
Calling USBm_InitPortsU401 will reset the ports to input and will clear the internal latches.
Calling USBm_InitPortsU421 will reset the ports to input and will clear the internal latches.
Calling USBm_InitPortsU451 will reset port A to input, port B to output and will clear the internal latches.
There is nothing stopping you from calling the USBm_InitPortsU421 when connected to a U401, for instance. Or any of the other combinations. The different flavors of init are provided for user convenience. USBm_InitPortsU451 is currently the only different one in the group as it sets port B to all output.
USBm_InitPorts is in all versions of the DLL. The variations are present in version 65 or newer.
VB Declaration
| Public Declare Function USBm_InitPorts _ Lib "USBm.dll" _ (ByVal device As Byte) _ As Integer Public Declare Function USBm_InitPortsU401 _ Lib "USBm.dll" _ (ByVal device As Byte) _ As Integer Public Declare Function USBm_InitPortsU421 _ Lib "USBm.dll" _ (ByVal device As Byte) _ As Integer Public Declare Function USBm_InitPortsU451 _ Lib "USBm.dll" _ (ByVal device As Byte) _ As Integer |
VB Example
| USBm_InitPorts (3) |
This code fragment initializes the ports of device number three.
C Prototype
| int USBm_InitPorts( unsigned char device ); int USBm_InitPortsU401( unsigned char device ); int USBm_InitPortsU421( unsigned char device ); int USBm_InitPortsU451( unsigned char device ); |
C Example
| USBm_InitPorts( 0 ); |
This code fragment initializes the ports of device number 0 (the first U4x1 device that is found).
RobotBASIC
usbm_InitPorts(ne_DeviceNumber)
Returns true if successful, false otherwise. This function resets the A and B ports as Input Ports, which is the default state upon connecting the device to the PC.
Raw Command Format:
| Byte Number | Description |
| 0 | 00h: InitPortsCmd |
| 1 | <not used> |
| 2 | <not used> |
| 3 | <not used> |
| 4 | <not used> |
| 5 | <not used> |
| 6 | <not used> |
| 7 | <not used> |
Raw Command Format Details:
Byte 0 contains the command. Byte 1 through byte 7 are unused.
Raw Command Response Format:
| Byte Number | Description |
| 0 | 00h: InitPortsCmd |
| 1 | <not used> |
| 2 | <not used> |
| 3 | <not used> |
| 4 | <not used> |
| 5 | <not used> |
| 6 | <not used> |
| 7 | <not used> |
Raw Command Response Format Details:
Byte 0 contains the command. Byte 1 through byte 7 are unused.
Raw Command Example Usage:
Sending the InitPortsCmd command to the device will reset the ports.
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