Component: USB Serial (Comms: USB)

From Flowcode Help
Jump to navigationJump to search
Author Matrix Ltd.
Version 1.6
Category Comms: USB


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. FC6 Icon.png 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.

ZIP Icon.png USB Serial Driver


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. FC6 Icon.png 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.

DeviceManager.jpg


Assigning the correct COM port in the simulation needs to be done to allow the communications to work correctly.

SerialProps.jpg


Example of the data console with data being passed back and forth between the simulation and the embedded device.

SerialComms.jpg






Macro reference

Initialise

Fc9-comp-macro.png Initialise
Starts up the USB communications and attempts to enumerate. Returns 0 for a successful startup or 255 for a enumeration timeout. 
Fc9-u8-icon.png - BYTE Return


ReadByte

Fc9-comp-macro.png ReadByte
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. 
Fc9-u8-icon.png - BYTE Timeout_ms
Number of milliseconds to wait before timing out 
Fc9-u16-icon.png - UINT Return


ReadString

Fc9-comp-macro.png ReadString
Retreives a string 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. 
Fc9-u8-icon.png - BYTE Timeout_ms
Length of time to wait before timing out 
Fc9-u8-icon.png - BYTE Length
Maximum number of bytes to try and read 
Fc9-string-icon.png - STRING Return


SendByte

Fc9-comp-macro.png SendByte
Sends the specified data byte to the host 
Fc9-u8-icon.png - BYTE data
Data byte to send to the host 
Fc9-u8-icon.png - BYTE Return


SendByteArray

Fc9-comp-macro.png SendByteArray
Sends the specified data array to the host 
Fc9-u8-icon.png - BYTE Data
Data array to send to the host 
Fc9-u8-icon.png - BYTE NumBytes
Max bytes is set by the Transmit Buffer Size property 
Fc9-u8-icon.png - BYTE Return


SendNumber

Fc9-comp-macro.png SendNumber
Sends the specified numeric value as an ASCII string to the host. 
Fc9-s16-icon.png - INT Number
Range -32768 to 32767 
Fc9-u8-icon.png - BYTE Return


SendString

Fc9-comp-macro.png SendString
Sends the specified data string to the host 
Fc9-string-icon.png - STRING Data
Data string to send to the host 
Fc9-u8-icon.png - BYTE Return


Property reference

Fc9-prop-icon.png Properties
Fc9-conn-icon.png USB Properties
Fc9-type-21-icon.png Vendor ID
USB VID 
Fc9-type-21-icon.png Product ID
USB PID 
Fc9-type-10-icon.png Device Name
USB Device Name 
Fc9-type-10-icon.png Manufacturer
USB Manufacturer 
Fc9-type-14-icon.png Major Version
USB Major Version Number 
Fc9-type-14-icon.png Minor Version
USB Minor Version Number 
Fc9-type-16-icon.png Return Type
Specifies the way the receive function indicates a timeout. 8 Bit mode - Timeout is represented by the value 255. 16 Bit mode - Timeout is represented by the value 512 allowing the value 255 to represent valid data 
Fc9-type-7-icon.png Enumeration Timeout
Specifies if the enumeration (Initialise function) can timeout if taking too long. 
Fc9-conn-icon.png RAM Usage
Fc9-type-21-icon.png Transmit Buffer Size
Sets the size of the transmit buffer. Recommended to be between 8 and 64 bytes. 
Fc9-type-21-icon.png Receive Buffer Size
Sets the size of the receive buffer. Recommended to be between 8 and 64 bytes. 
Fc9-conn-icon.png USB Driver
Fc9-type-20-icon.png Driver Directory
Directory to save the generated device driver .inf file 
Fc9-type-10-icon.png Driver Filename
Filename to give to the generated driver file. 
Fc9-type-7-icon.png Generate Driver
Generates a driver file when set to Yes, Automatically jumps back to No when complete. 
Fc9-conn-icon.png Simulation
Fc9-type-12-icon.png COM Port
Hardware COM port to communicate with any connected USB serial devices or any other virtual COM ports. 
Fc9-type-10-icon.png Label
Text displayed on the I/O flasher comms component.