Component: USB Serial (Comms: USB)

From Flowcode Help
Revision as of 15:46, 16 February 2017 by BenR (talk | contribs) (XML import BR)
Jump to navigationJump to search


Author Matrix Ltd.
Version 1.6 (Development)
Category Comms: USB


Image 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.

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.

File:USBSerial Driver.zip


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

Downloadable macro reference

SendString

Sends the specified data string to the host

Parameters

<- STRING Data
Data string to send to the host
This parameter may be returned back to the caller


Return value

BYTE


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.

Parameters

BYTE Timeout_ms
Length of time to wait before timing out
BYTE Length
Maximum number of bytes to try and read


Return value

STRING


SendByte

Sends the specified data byte to the host

Parameters

BYTE data
Data byte to send to the host


Return value

BYTE


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.

Parameters

BYTE Timeout_ms
Number of milliseconds to wait before timing out


Return value

UINT


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

BYTE


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

Return Type

This property is of type Fixed list of ints and can be referenced with the variable name RETURN.

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

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.

Transmit Buffer Size

This property is of type Unsigned integer and can be referenced with the variable name TXBUFSZ.

Sets the size of the transmit buffer.

Recommended to be between 8 and 64 bytes.

Receive Buffer Size

This property is of type Unsigned integer and can be referenced with the variable name RXBUFSZ.

Sets the size of the receive buffer.

Recommended to be between 8 and 64 bytes.

Driver Directory

This property is of type Directory 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 to give to the generated driver file.

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.

COM Port

This property is of type Fixed list of text and can be referenced with the variable name COM_port.

Hardware COM port to communicate with any connected USB serial devices or any other virtual COM ports.

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.