Component: USB Slave Free (Misc): Difference between revisions
m Text replacement - "class="wikitable" style="width:60%; background-color:#FFFFFF;"" to "class="mtx-class-macrotable wikitable"" |
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder"" |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 150: | Line 150: | ||
{| class="mtx-class-macrotable wikitable" | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''CheckRx''' | ||
|- | |- | ||
| colspan="2" | 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. | | colspan="2" | 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. | ||
| Line 164: | Line 164: | ||
{| class="mtx-class-macrotable wikitable" | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''GetByte''' | ||
|- | |- | ||
| colspan="2" | Retreives the byte at location Idx from the incoming data buffer. | | colspan="2" | Retreives the byte at location Idx from the incoming data buffer. | ||
| Line 183: | Line 183: | ||
{| class="mtx-class-macrotable wikitable" | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''GetString''' | ||
|- | |- | ||
| colspan="2" | Retreives a string of data from the incoming data buffer starting from location 0 and incrementing up to the NumBytes parameter. | | colspan="2" | Retreives a string of data from the incoming data buffer starting from location 0 and incrementing up to the NumBytes parameter. | ||
| Line 202: | Line 202: | ||
{| class="mtx-class-macrotable wikitable" | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Initialise''' | ||
|- | |- | ||
| colspan="2" | Starts up the USB communications and attempts to enumerate. Returns 0 for a successful startup or 255 for a enumeration timeout. | | colspan="2" | Starts up the USB communications and attempts to enumerate. Returns 0 for a successful startup or 255 for a enumeration timeout. | ||
| Line 216: | Line 216: | ||
{| class="mtx-class-macrotable wikitable" | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''RunSlaveService''' | ||
|- | |- | ||
| colspan="2" | 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. | | colspan="2" | 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. | ||
| Line 230: | Line 230: | ||
{| class="mtx-class-macrotable wikitable" | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''SendByte''' | ||
|- | |- | ||
| colspan="2" | Adds the byte onto the end of the outgoing data buffer. | | colspan="2" | Adds the byte onto the end of the outgoing data buffer. | ||
| Line 249: | Line 249: | ||
{| class="mtx-class-macrotable wikitable" | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''SendByteArray''' | ||
|- | |- | ||
| colspan="2" | Adds an array of bytes onto the end of the outgoing data buffer. | | colspan="2" | Adds an array of bytes onto the end of the outgoing data buffer. | ||
| Line 273: | Line 273: | ||
{| class="mtx-class-macrotable wikitable" | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''SendString''' | ||
|- | |- | ||
| colspan="2" | Adds a string of bytes onto the end of the outgoing data buffer. | | colspan="2" | Adds a string of bytes onto the end of the outgoing data buffer. | ||
| Line 297: | Line 297: | ||
{| class="mtx-class-macrotable wikitable" | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''StopSlaveService''' | ||
|- | |- | ||
| colspan="2" | 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. | | colspan="2" | 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. | ||
| Line 312: | Line 312: | ||
{| class="mtx-class-macrotable wikitable" | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Properties''' | ||
|- | |- | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-propfolder" | USB Properties | ||
|- | |- | ||
|- | |- | ||
| Line 365: | Line 365: | ||
| colspan="2" | Maximum amount of current the USB host will provide before shutting down the USB channel. | | colspan="2" | Maximum amount of current the USB host will provide before shutting down the USB channel. | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-propfolder" | Slave Macro Properties | ||
|- | |- | ||
|- | |- | ||
| Line 379: | Line 379: | ||
| colspan="2" | Defines the parameters for the slave service macro allowing data from the host to be automatically passed into the macro. | | colspan="2" | Defines the parameters for the slave service macro allowing data from the host to be automatically passed into the macro. | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-propfolder" | USB Driver | ||
|- | |- | ||
|- | |- | ||
| Line 398: | Line 398: | ||
| colspan="2" | Generates a driver file when set to Yes, Automatically jumps back to No when complete. | | colspan="2" | Generates a driver file when set to Yes, Automatically jumps back to No when complete. | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-propfolder" | Simulation | ||
|- | |- | ||
|- | |- | ||
Latest revision as of 14:37, 13 July 2026
| Author | Matrix Ltd. |
| Version | 1.1 |
| Category | Misc |
USB Slave Free 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).
Component Source Code
Please click here to download the component source project: FC_Comp_Source_USBSlave_Free.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_USBSlave_Free.fcfx
Detailed description
No detailed description exists yet for this component
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.
Macro reference
CheckRx
| 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. | |
| Return | |
GetByte
| GetByte | |
| Retreives the byte at location Idx from the incoming data buffer. | |
| Idx | |
| Specifies the location in the incoming buffer | |
| Return | |
GetString
Initialise
| Initialise | |
| Starts up the USB communications and attempts to enumerate. Returns 0 for a successful startup or 255 for a enumeration timeout. | |
| Return | |
RunSlaveService
SendByte
| SendByte | |
| Adds the byte onto the end of the outgoing data buffer. | |
| Data | |
| Data byte to transmit to the host | |
| Return | |
SendByteArray
SendString
| SendString | |
| Adds a string of bytes onto the end of the outgoing data buffer. | |
| Data | |
| Data String To Send | |
| Length | |
| Max number of bytes to try and add to the outgoing buffer. | |
| Return | |
StopSlaveService




