Difference between revisions of "Component: USB Slave (Comms: USB)"
(XML import BR) |
|||
(One intermediate revision by the same user not shown) | |||
Line 73: | Line 73: | ||
The [[Component: ID eabeda20_432c_4554_80b3_5851d675a9e7|MIAC USB Slave]] and ECIO USB Slave Components are written based on the USB Slave component so these give a good example of what is possible using the component. | The [[Component: ID eabeda20_432c_4554_80b3_5851d675a9e7|MIAC USB Slave]] and ECIO USB Slave Components are written based on the USB Slave component so these give a good example of what is possible using the component. | ||
− | |||
==Downloadable macro reference== | ==Downloadable macro reference== |
Latest revision as of 15:45, 16 February 2017
Author | Matrix Ltd. |
Version | 1.1 (Release) |
Category | Comms: USB |
Contents
USB Slave component
Component to create and communicate using a generic USB communications profile. Has the ability to allow the device to be a slave to the PC. Compatible with simulation and USB enabled microcontroller devices (PIC/dsPIC).
Examples
The PIC based ECIOs or MIAC are good targets for USB as they do not have any additional configuration setting that need to be setup to allow the firmware to run correctly. For other targets you will have to setup the configuration correctly for your hardware to allow the USB to run correctly.
Basic Embedded Example
Here is an example file which waits for incoming data and then when valid data is received it displays this as a binary value onto the PortB pins before echoing back the data.
USB Slave Simple Receive
USB Drivers
The example requires a device driver to function correctly. The driver can be generated by selecting the USB Slave component on the System panel, Looking down the list of properties in the properties window, selecting the Generate Driver property and switching the setting to Yes. This will place the driver .inf file into the same directory as the Flowcode fcfx project file is located.
Here is a signed version of the USB Slave device driver using the default VID/PID properties. The .inf driver file generated by Flowcode also requires some associated files which are not auto generated, these files can also be downloaded here.
The final driver files can be assembled by extracting the contents of the zip archive into a folder on your computer and adding the .inf file created by your Flowcode project. Running the correct executable for your PC type should then auto install the driver for you.
When the driver is installed correctly you will get your device showing up in the Windows device manager like this.
Basic Simulations Example
Here is an example file which is designed to run in simulation to communicate with the connected embedded device. The instance property will have to match the USB instance for the embedded device to allow the communications to work correctly.
USB Slave Simulation
The USB Slave instance is selected by selecting the USB slave component on the panel and setting the instance property.
When editing the USB Slave examples the slave service macro needs to match the setting in the USB Slave properties as shown below.
Slave Macro Setup
Slave Properties
Example console showing the data passed between the simulation and the embedded hardware.
The MIAC USB Slave and ECIO USB Slave Components are written based on the USB Slave component so these give a good example of what is possible using the component.
Downloadable macro reference
SendString
Adds a string of bytes onto the end of the outgoing data buffer.
Parameters
- <- STRING Data
- Data String To Send
- This parameter may be returned back to the caller
- BYTE Length
- Max number of bytes to try and add to the outgoing buffer.
Return value
GetString
Retreives a string of data from the incoming data buffer starting from location 0 and incrementing up to the NumBytes parameter.
Parameters
- BYTE NumBytes
- Specifies the maximum number of bytes to try and read.
Return value
RunSlaveService
Stalls the microcontroller and waits for an incoming message from the USB, when a message is received the macro defined in the USB Slave properties is automatically run. While the macro is running you can choose to send data back to the PC if you wish.
Parameters
- This macro has no parameters
Return value
- This call does not return a value
SendByte
Adds the byte onto the end of the outgoing data buffer.
Parameters
- BYTE Data
- Data byte to transmit to the host
Return value
SendByteArray
Adds an array of bytes onto the end of the outgoing data buffer.
Parameters
- <- BYTE Data
- Data Bytes To Send
- This parameter may be returned back to the caller
- BYTE Length
- Max number of bytes to try and add to the outgoing buffer.
Return value
CheckRx
Called to check if there is any incoming data waiting to be received.
Returns the number of incoming data bytes.
Only needed when not running the slave service.
Parameters
- This macro has no parameters
Return value
GetByte
Retreives the byte at location Idx from the incoming data buffer.
Parameters
- BYTE Idx
- Specifies the location in the incoming buffer
Return value
StopSlaveService
Allows the microcontroller to leave the stalled slave mode and resume its normal independant functionality. Must be called from within the slave service routine to work correctly.
Parameters
- This macro has no parameters
Return value
- This call does not return a value
Initialise
Starts up the USB communications and attempts to enumerate.
Returns 0 for a successful startup or 255 for a enumeration timeout.
Parameters
- This macro has no parameters
Return value
Simulation macro reference
This component does not contain any simulation macros
Property reference
Vendor ID
This property is of type Signed integer and can be referenced with the variable name vendor_ID.
USB VID
Product ID
This property is of type Signed integer and can be referenced with the variable name product_ID.
USB PID
Device Name
This property is of type Line of text and can be referenced with the variable name dev_name.
USB Device Name
Manufacturer
This property is of type Line of text and can be referenced with the variable name dev_manufacturer.
USB Manufacturer
Major Version
This property is of type Signed integer and can be referenced with the variable name major_version.
USB Major Version Number
Minor Version
This property is of type Signed integer and can be referenced with the variable name minor_version.
USB Minor Version Number
Enumeration Timeout
This property is of type True or false and can be referenced with the variable name enumeration_tout.
Specifies if the enumeration (Initialise function) can timeout if taking too long.
Country Code
This property is of type Fixed list of ints and can be referenced with the variable name country_code.
Country code used by some regional based USB devices
Maximum Current (mA)
This property is of type Signed integer and can be referenced with the variable name max_current.
Maximum amount of current the USB host will provide before shutting down the USB channel.
Slave Macro
This property is of type Line of text and can be referenced with the variable name slave_macro.
Flowcode macro to call while the slave service is enabled
Macro Parameters
This property is of type Fixed list of ints and can be referenced with the variable name slave_params.
Defines the parameters for the slave service macro allowing data from the host to be automatically passed into the macro.
Driver Directory
This property is of type Line of text and can be referenced with the variable name driver_directory.
Directory to save the generated device driver .inf file
Driver Filename
This property is of type Line of text and can be referenced with the variable name driver_filename.
Filename assigned to the USB device driver .inf file when generated.
Generate Driver
This property is of type True or false and can be referenced with the variable name gen_driver.
Generates a driver file when set to Yes, Automatically jumps back to No when complete.
Instance
This property is of type Fixed list of ints and can be referenced with the variable name Instance.
Hardware instance to communicate with any connected USB slave devices.
Timeout (ms)
This property is of type Unsigned integer and can be referenced with the variable name SimTimeout.
Simulation host to slave communications timeout in milliseconds
Label
This property is of type Line of text and can be referenced with the variable name label.
Text displayed on the I/O flasher comms component.