Difference between revisions of "Component: USB Serial (Comms: USB)"
(3 intermediate revisions by the same user not shown) | |||
Line 104: | Line 104: | ||
[[File:SerialComms.jpg]] | [[File:SerialComms.jpg]] | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Line 109: | Line 117: | ||
==Macro reference== | ==Macro reference== | ||
+ | ===Initialise=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Starts up the USB communications and attempts to enumerate. Returns 0 for a successful startup or 255 for a enumeration timeout. |
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
− | |||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
Line 127: | Line 131: | ||
+ | ===ReadByte=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadByte''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Retreives the byte from the incoming data buffer. If data is available then the macro will return straight away. If there is no data available then the macro waits up the the period specified by the timeout before returning the value 255. |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE |
− | | width="90%" | | + | | width="90%" | Timeout_ms |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Number of milliseconds to wait before timing out |
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
+ | ===ReadString=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 168: | Line 174: | ||
+ | ===SendByte=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 186: | Line 193: | ||
+ | ===SendByteArray=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 209: | Line 217: | ||
+ | ===SendNumber=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SendNumber''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Sends the specified numeric value as an ASCII string to the host. |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-s16-icon.png]] - INT |
− | | width="90%" | | + | | width="90%" | Number |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Range -32768 to 32767 |
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
+ | ===SendString=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SendString''' |
+ | |- | ||
+ | | colspan="2" | Sends the specified data string to the host | ||
+ | |- | ||
|- | |- | ||
− | | | + | | width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING |
+ | | width="90%" | Data | ||
|- | |- | ||
+ | | colspan="2" | Data string to send to the host | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
− | |||
− | |||
Latest revision as of 13:13, 7 February 2023
Author | Matrix Ltd. |
Version | 1.6 |
Category | Comms: USB |
Contents
USB Serial component
Component to create and communicate using a standard CDC type COM port. Compatible with simulation and USB enabled microcontroller devices PIC/dsPIC/AVR.
Component Source Code
Please click here to download the component source project: FC_Comp_Source_USBSerial.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_USBSerial.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.
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 Serial Simple Receive
The example requires a device driver to function correctly. The driver can be generated by selecting the USB Serial 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 file into the same directory as the Flowcode fcfx project file is located.
Here is a signed version of the USB Serial device driver using the default VID/PID properties.
Here is an example file which is designed to run in simulation to communicate with the connected embedded device. The COM port property will have to match the COM port for the embedded device to allow the communications to work correctly. Alternatively a program like Hyperterminal or RealTerm can be used to generate the COM port data to send to the connected device.
USB Serial Simulation
Finding which COM port has been allocated to your embedded device is as easy as opening the Windows device manager and looking under Ports.
Assigning the correct COM port in the simulation needs to be done to allow the communications to work correctly.
Example of the data console with data being passed back and forth between the simulation and the embedded device.
Macro reference
Initialise
![]() |
Initialise |
Starts up the USB communications and attempts to enumerate. Returns 0 for a successful startup or 255 for a enumeration timeout. | |
![]() |
Return |
ReadByte
ReadString
SendByte
![]() |
SendByte |
Sends the specified data byte to the host | |
![]() |
data |
Data byte to send to the host | |
![]() |
Return |
SendByteArray
![]() |
SendByteArray |
Sends the specified data array to the host | |
![]() |
Data |
Data array to send to the host | |
![]() |
NumBytes |
Max bytes is set by the Transmit Buffer Size property | |
![]() |
Return |
SendNumber
![]() |
SendNumber |
Sends the specified numeric value as an ASCII string to the host. | |
![]() |
Number |
Range -32768 to 32767 | |
![]() |
Return |
SendString
![]() |
SendString |
Sends the specified data string to the host | |
![]() |
Data |
Data string to send to the host | |
![]() |
Return |