Difference between revisions of "Bot test"

From Flowcode Help
Jump to navigationJump to search
Line 4: Line 4:
 
|-
 
|-
 
| width="20%" style="color: gray;" | Author
 
| width="20%" style="color: gray;" | Author
| Matrix TSL
+
| Matrix Ltd.
 
|-
 
|-
 
| width="20%" style="color: gray;" | Version
 
| width="20%" style="color: gray;" | Version
| 1.0 (Release)
+
| 2.0 (Release)
 
|-
 
|-
 
| width="20%" style="color: gray;" | Category
 
| width="20%" style="color: gray;" | Category
| Comms: Networking
+
| Wireless
 
|}
 
|}
  
  
  
==[[File:Component Icon 91049bf5_2436_42dc_947a_c30c86463d98.png|Image]] Network Communications component==
+
==[[File:Component Icon cff93310_545b_4948_a8fa_12b119c5f7a7.png|Image]] Bluetooth (EB024, Generic AT) component==
A component designed to simplify the process of TCP/IP communications.
+
Low level routines for controlling a standard AT Bluetooth interface.
Compatible with most of the Flowcode supported TCP/IP and WIFI components.
+
Also available in the form of the EB024 Bluetooth E-block.
A useful building block for creating components such as IoT and Modbus TCP.
 
  
 
==Examples==
 
==Examples==
 +
===Making a device discoverable===
  
 +
Example program to set up the Bluetooth module to be discoverable with a pair key. Any data received is then output onto the LCD component. You can connect to the Bluetooth device using a PC with Bluetooth connection and using software such as Flowcode 6, RealTerm or HyperTerminal. Alternatively you can connect using a smart phone running a terminal emulator app or via another embedded Bluetooth board.
 +
{{Fcfile|BluetoothDiscover.fcfx|Bluetooth Discover}}
 +
Script 1 contains the AT commands to setup the Bluetooth device to be discoverable with pair key "1234".
  
Here are some examples showing the Network Communications component in action.
+
[[File:DiscoverableScript.jpg]]
  
By itself the component provides a generic TCP/IP layer to drive the simulation runtime.
 
  
Here is a simple example showing the component used by itself to request data from a remote server on the internet.
+
===Searching for a device===
  
{{Fcfile|NetworkComms-Client.fcfx|Example Network Comms Client}}
+
Example program to scan for local discoverable Bluetooth devices. For each device found the MAC address is displayed on to the LCD.
 +
{{Fcfile|BluetoothInquire.fcfx|Bluetooth Inquiry}}
 +
===Connecting to a device===
  
 +
Example program to connect to a specific Bluetooth device address and send data to the device.
 +
{{Fcfile|BluetoothConnect.fcfx|Bluetooth Connect}}
 +
The device MAC address is specified using the "CreateCommandString" and "SendCommand" macros.
  
===Library Components===
+
[[File:ConnectToMAC.jpg]]
  
Components such as [[Component:_Webserver_(GENERIC_ROM_FAT)_(Comms:_Networking)|Webserver (GENERIC)]], [[Component:_MQTT_Client_(Comms:_System)|MQTT]] and [[Component:_Modbus_TCP_Master_(Comms:_System)|Modbus TCP]] can connect to and control the network comms layer.
+
==Downloadable macro reference==
 +
 
 +
===<span style="font-weight: normal;"><u><tt>StringRead</tt></u></span>===
 +
Returns the ASCII value of character idx of the Response string.
 +
 
 +
'''Parameters'''
  
[[File:NetComms1.jpg]]
+
:[[Variable Types|BYTE]] ''idx''
 +
::Needs to be a equal to or less than the string length of the response in order to retrieve a valid character.
  
  
Here is a simple example showing the component used with the [[Component:_Webserver_(GENERIC_ROM_FAT)_(Comms:_Networking)|Webserver (GENERIC)]] component.
+
'''Return value'''
 +
 
 +
:[[Variable Types|BYTE]]
  
{{Fcfile|NetworkComms-Server.fcfx|Example Network Comms Web Server}}
 
  
===Embedded Components===
+
===<span style="font-weight: normal;"><u><tt>SendScript</tt></u></span>===
 +
Sends Script idx
  
The Network Communications component can also be connected to embedded TCP/IP and WIFI style modules allowing for the abstraction to work with specific networking hardware modules.
+
Note that the general property Number of Scripts needs to be set so that it allows the scripts to be accessed and sent.  
  
[[File:NetComms2.jpg]]
+
Returns 0 for success and 1 for error
  
 +
'''Parameters'''
  
Here is the current status of the Network Communications component with the various embedded modules.  
+
:[[Variable Types|BYTE]] ''idx''
 +
::Refers to the Script page to send (1-4).
  
{| class="wikitable"
 
! Embedded Component
 
! Other Variants of Component
 
! Support Status
 
|-
 
|[[Component:_TCPIP_(Raspberry_Pi)_(Comms:_Networking)|TCP/IP (Raspberry Pi)]]
 
|N/A
 
|Fully Supported
 
|-
 
|[[Component:_WLAN_(EB069,_ESP8266)_(ESP8266)_(Wireless)|WLAN (ESP8266)]]
 
|WLAN (ESP-12S), WIFI (BL0136), WIFI (ESP8266)
 
|Fully Supported
 
|-
 
|[[Component:_TCPIP_(W5500)_(Comms:_Networking)|TCP/IP (W5500)]]
 
|N/A
 
|Fully Supported
 
|-
 
|[[Component:_TCPIP_(ENC28J60)_(Comms:_Networking)|ENC28J60]]
 
|N/A
 
|On Hold
 
|-
 
|[[Component:_TCPIP_(NM7010A)_(Comms:_Networking)|TCP/IP (NM7010A)]]
 
|TCP/IP (EB023v1)
 
|On Hold
 
|-
 
|[[Component:_TCPIP_(WIZ810MJ)_(Comms:_Networking)|TCP/IP (W5100)]]
 
|TCP/IP (EB023v2), TCP/IP (WIZ810MJ)
 
|On Hold
 
|-
 
|[[Component:_WLAN_(EB069,_WIZ610wi)_(Wireless)|WLAN (WIZ610WI)]]
 
|WIFI (EB069)
 
|On Hold
 
|}
 
  
 +
'''Return value'''
  
We are working through and adding support as and when we get chance so if you have a module that isn't listed or would like to try and prioritise a specific module then you can let us know via the user forums.
+
:[[Variable Types|BYTE]]
  
==Downloadable macro reference==
 
  
===<span style="font-weight: normal;"><u><tt>Connect</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>SendCommand</tt></u></span>===
Connects to an IP address as a client on the specified port.
+
Sends the command buffer.
  
Some TCP/IP modules (RPI and ESP8266) will accept a URL instead of an IP address.
+
Returns 1 for success in sending the command.
  
Returns: 0=Fail, 1=OK
+
Returns 0 for errors.
  
 
'''Parameters'''
 
'''Parameters'''
  
:[[Variable Types|<- STRING]] ''Address''
+
:[[Variable Types|BYTE]] ''ExpectEcho''
::IP address as a string e.g. "192.168.1.1" or URL on some TCP/IP modules
+
::Remote module automatically echos back data: 1 = On (Expect echo), 0 = off
::''This parameter may be returned back to the caller''
 
  
:[[Variable Types|UINT]] ''Port''
+
:[[Variable Types|BYTE]] ''SendCR''
 +
::Automatically adds \n to the end of the command data: 1 = append CR, 0 = no CR.
  
  
 
'''Return value'''
 
'''Return value'''
  
:[[Variable Types|BOOL]] : Returns true if the operation is a success, else false
+
:[[Variable Types|BYTE]]
  
  
===<span style="font-weight: normal;"><u><tt>Receive</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>CreateCommandString</tt></u></span>===
Attempts to receive up to a specified number of bytes from the active connection.
+
Assigns a string of characters to the Command buffer.
  
Returns the number of bytes received.
+
Returns 1 for success in adding the characters to the buffer.
 +
 
 +
Returns 0 for errors, including Buffer overflow.
  
 
'''Parameters'''
 
'''Parameters'''
Line 122: Line 108:
 
::''This parameter may be returned back to the caller''
 
::''This parameter may be returned back to the caller''
  
:[[Variable Types|UINT]] ''Count''
+
 
::Maximum number of bytes to read
+
'''Return value'''
 +
 
 +
:[[Variable Types|BYTE]]
 +
 
 +
 
 +
===<span style="font-weight: normal;"><u><tt>StringReceive</tt></u></span>===
 +
Checks for a response string.
 +
 
 +
Returns the length of the response string if one is present otherwise returns 0.
 +
 
 +
'''Parameters'''
 +
 
 +
:''This macro has no parameters''
  
  
 
'''Return value'''
 
'''Return value'''
  
:[[Variable Types|UINT]]
+
:[[Variable Types|BYTE]]
  
  
===<span style="font-weight: normal;"><u><tt>Send</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>CreateCommand</tt></u></span>===
Sends the specified number of bytes via the active connection.
+
Adds a single characters to the end of the Command buffer.
  
Returns the number of bytes sent, 0=Fail.
+
Returns 1 for success in adding the characters to the buffer.
 +
 
 +
Returns 0 for errors, including Buffer overflow.
  
 
'''Parameters'''
 
'''Parameters'''
  
:[[Variable Types|<- STRING]] ''Data''
+
:[[Variable Types|BYTE]] ''Character''
::Array containing the data to send
+
::ASCII value or single character,
::''This parameter may be returned back to the caller''
 
  
:[[Variable Types|UINT]] ''Count''
 
::Number of bytes to send from the data array
 
  
 +
'''Return value'''
  
'''Return value'''
+
:[[Variable Types|BYTE]]
  
:[[Variable Types|UINT]]
 
  
 +
===<span style="font-weight: normal;"><u><tt>Send_byte</tt></u></span>===
 +
''<span style="color:red;">No additional information</span>''
  
===<span style="font-weight: normal;"><u><tt>Listen</tt></u></span>===
 
Bind the socket to a port on the local host and set to listen mode.
 
  
Returns: 0=Fail, 1=OK
 
  
 
'''Parameters'''
 
'''Parameters'''
  
:[[Variable Types|UINT]] ''Port''
+
:[[Variable Types|BYTE]] ''ByteVal''
  
  
 
'''Return value'''
 
'''Return value'''
  
:[[Variable Types|BOOL]] : Returns true if the operation is a success, else false
+
:''This call does not return a value''
 +
 
  
 +
===<span style="font-weight: normal;"><u><tt>WaitForResponse</tt></u></span>===
 +
Waits for a response message of type response_code for timeout ms.
  
===<span style="font-weight: normal;"><u><tt>SocketOpen</tt></u></span>===
+
Returns: 0 for a Response of type response_code
Attempts to create a socket on the local device.
 
  
This must be succesful to allow TCP/IP communications with a remote destination.
+
255 (0xFF) for a timeout or invalid response
  
Returns: 0=Fail / 1=OK
+
Response string length for any Response not of type response_code
  
 
'''Parameters'''
 
'''Parameters'''
  
:''This macro has no parameters''
+
:[[Variable Types|BYTE]] ''response_code''
 +
::1:OK / 2:ERROR / 3:CONNECT / 4:NO CARRIER / 5:AUDIO / 6:PAIR / 7:RING
 +
 
 +
:[[Variable Types|BYTE]] ''timeout''
 +
::The timeout value will need to set to allow sufficient time for the response to arrive.
  
  
 
'''Return value'''
 
'''Return value'''
  
:[[Variable Types|BOOL]] : Returns true if the operation is a success, else false
+
:[[Variable Types|BYTE]]
  
  
===<span style="font-weight: normal;"><u><tt>SocketClose</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>Initialise</tt></u></span>===
Closes the current socket connection
+
Required to be used whenever the Bluetooth component is used in a program.
 +
 
 +
Initialises the Bluetooth component ready for use.
  
 
'''Parameters'''
 
'''Parameters'''
Line 203: Line 207:
  
 
==Property reference==
 
==Property reference==
<span style="font-weight: normal;"><u>TCP/IP Component</u></span>
+
<span style="font-weight: normal;"><u>Command Buffer Size</u></span>
 +
 
 +
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''CommandBufferSize''.
 +
 
 +
Maximum number of bytes that can be stored in the outgoing command buffer.
 +
 
 +
<span style="font-weight: normal;"><u>Response Buffer Size</u></span>
 +
 
 +
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''ResponseBufferSize''.
 +
 
 +
Maximum number of bytes that can be stored in the incoming response buffer.
 +
 
 +
<span style="font-weight: normal;"><u>Script Count</u></span>
 +
 
 +
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''SCRIPTS''.
 +
 
 +
Controls how many AT scripts are stored into non-volatile memory
 +
 
 +
<span style="font-weight: normal;"><u>Script 1</u></span>
 +
 
 +
This property is of type ''Multiple lines of text'' and can be referenced with the variable name ''SCRIPT1''.
 +
 
 +
Data to send for script 0, each command should be terminated with a carriage return
 +
 
 +
<span style="font-weight: normal;"><u>Channel</u></span>
 +
 
 +
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_uart::CHANNEL''.
 +
 
 +
UART Channel selector
 +
 
 +
Software channels are bit banged using generic I/O pins but are not as reliable as hardware channels.
 +
 
 +
Hardware channels use the selected peripheral on-board the target microcontroller.
 +
 
 +
<span style="font-weight: normal;"><u>TX</u></span>
 +
 
 +
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_uart::TX''.
 +
 
 +
Pin to be used for Transmit data
 +
 
 +
<span style="font-weight: normal;"><u>RX</u></span>
 +
 
 +
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_uart::RX''.
 +
 
 +
Pin to be used for Receive data
 +
 
 +
<span style="font-weight: normal;"><u>Use Flow Control</u></span>
 +
 
 +
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_uart::FLOWEN''.
 +
 
 +
Flow Control (Handshake) enable or disable.
 +
 
 +
    On: Two I/O pins are used to control the flow of data in and out of the device.
 +
 
 +
    Off: Flow control is disabled.
 +
 
 +
<span style="font-weight: normal;"><u>Baud Options</u></span>
 +
 
 +
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_uart::BAUD_LIST''.
 +
 
 +
Baud rate option selector
 +
 
 +
<span style="font-weight: normal;"><u>Baud Rate</u></span>
 +
 
 +
This property is of type ''Signed integer'' and can be referenced with the variable name ''cal_uart::BAUD''.
 +
 
 +
''<span style="color:red;">No additional information</span>''
 +
 
 +
 
 +
 
 +
<span style="font-weight: normal;"><u>Console Columns</u></span>
 +
 
 +
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''cal_uart::ConsoleColumns''.
 +
 
 +
Number of characters that can be displayed on a single line of the console.
 +
 
 +
<span style="font-weight: normal;"><u>Console Data</u></span>
 +
 
 +
This property is of type ''True or false'' and can be referenced with the variable name ''cal_uart::ConsoleData''.
 +
 
 +
Selects if the console data is automatically generated or not
 +
 
 +
<span style="font-weight: normal;"><u>Scope Traces</u></span>
 +
 
 +
This property is of type ''True or false'' and can be referenced with the variable name ''cal_uart::ScopeTraces''.
 +
 
 +
Selects if the scope traces are automatically added to the data recorder window or not.
 +
 
 +
    Simulation - draws an approximation of the UART data onto the scope trace.
 +
 
 +
    ICT - sets up the scope trace for incoming data and adds UART packet decoding at the correct BAUD.
 +
 
 +
<span style="font-weight: normal;"><u>Data Source</u></span>
 +
 
 +
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_uart::DataSource''.
 +
 
 +
Simulation data source used to allow the component to connect to various remote devices
 +
 
 +
    Nothing - Simulation data is ignored
 +
 
 +
    COM port - Routes the communication data to and from a physical or virtual COM port
  
This property is of type ''Panel object'' and can be referenced with the variable name ''Component''.
+
    Injector - Routes the communication data via a data injector component on the Panel.
  
Property to point to the TCP/IP or WIFI component you want to use.
+
<span style="font-weight: normal;"><u>Injector</u></span>
  
If unconnected then default to simulated TCP/IP network communications using the PC network adapter.
+
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_uart::Injector''.
  
<span style="font-weight: normal;"><u>Status</u></span>
+
Selects which injector component to route the communication data via.
  
This property is of type ''Line of text'' and can be referenced with the variable name ''Status''.
+
Add injector components to the panel before they will be available in this list.
  
Informs the user of the current status of support for the connected component.
+
Injector components are available from the Comms component category.

Revision as of 13:11, 19 August 2021


Author Matrix Ltd.
Version 2.0 (Release)
Category Wireless


Image Bluetooth (EB024, Generic AT) component

Low level routines for controlling a standard AT Bluetooth interface. Also available in the form of the EB024 Bluetooth E-block.

Examples

Making a device discoverable

Example program to set up the Bluetooth module to be discoverable with a pair key. Any data received is then output onto the LCD component. You can connect to the Bluetooth device using a PC with Bluetooth connection and using software such as Flowcode 6, RealTerm or HyperTerminal. Alternatively you can connect using a smart phone running a terminal emulator app or via another embedded Bluetooth board. FC6 Icon.png Bluetooth Discover Script 1 contains the AT commands to setup the Bluetooth device to be discoverable with pair key "1234".

DiscoverableScript.jpg


Searching for a device

Example program to scan for local discoverable Bluetooth devices. For each device found the MAC address is displayed on to the LCD. FC6 Icon.png Bluetooth Inquiry

Connecting to a device

Example program to connect to a specific Bluetooth device address and send data to the device. FC6 Icon.png Bluetooth Connect The device MAC address is specified using the "CreateCommandString" and "SendCommand" macros.

ConnectToMAC.jpg

Downloadable macro reference

StringRead

Returns the ASCII value of character idx of the Response string.

Parameters

BYTE idx
Needs to be a equal to or less than the string length of the response in order to retrieve a valid character.


Return value

BYTE


SendScript

Sends Script idx

Note that the general property Number of Scripts needs to be set so that it allows the scripts to be accessed and sent.

Returns 0 for success and 1 for error

Parameters

BYTE idx
Refers to the Script page to send (1-4).


Return value

BYTE


SendCommand

Sends the command buffer.

Returns 1 for success in sending the command.

Returns 0 for errors.

Parameters

BYTE ExpectEcho
Remote module automatically echos back data: 1 = On (Expect echo), 0 = off
BYTE SendCR
Automatically adds \n to the end of the command data: 1 = append CR, 0 = no CR.


Return value

BYTE


CreateCommandString

Assigns a string of characters to the Command buffer.

Returns 1 for success in adding the characters to the buffer.

Returns 0 for errors, including Buffer overflow.

Parameters

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


Return value

BYTE


StringReceive

Checks for a response string.

Returns the length of the response string if one is present otherwise returns 0.

Parameters

This macro has no parameters


Return value

BYTE


CreateCommand

Adds a single characters to the end of the Command buffer.

Returns 1 for success in adding the characters to the buffer.

Returns 0 for errors, including Buffer overflow.

Parameters

BYTE Character
ASCII value or single character,


Return value

BYTE


Send_byte

No additional information


Parameters

BYTE ByteVal


Return value

This call does not return a value


WaitForResponse

Waits for a response message of type response_code for timeout ms.

Returns: 0 for a Response of type response_code

255 (0xFF) for a timeout or invalid response

Response string length for any Response not of type response_code

Parameters

BYTE response_code
1:OK / 2:ERROR / 3:CONNECT / 4:NO CARRIER / 5:AUDIO / 6:PAIR / 7:RING
BYTE timeout
The timeout value will need to set to allow sufficient time for the response to arrive.


Return value

BYTE


Initialise

Required to be used whenever the Bluetooth component is used in a program.

Initialises the Bluetooth component ready for use.

Parameters

This macro has no parameters


Return value

This call does not return a value


Simulation macro reference

This component does not contain any simulation macros


Property reference

Command Buffer Size

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

Maximum number of bytes that can be stored in the outgoing command buffer.

Response Buffer Size

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

Maximum number of bytes that can be stored in the incoming response buffer.

Script Count

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

Controls how many AT scripts are stored into non-volatile memory

Script 1

This property is of type Multiple lines of text and can be referenced with the variable name SCRIPT1.

Data to send for script 0, each command should be terminated with a carriage return

Channel

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

UART Channel selector

Software channels are bit banged using generic I/O pins but are not as reliable as hardware channels.

Hardware channels use the selected peripheral on-board the target microcontroller.

TX

This property is of type Single digital pin and can be referenced with the variable name cal_uart::TX.

Pin to be used for Transmit data

RX

This property is of type Single digital pin and can be referenced with the variable name cal_uart::RX.

Pin to be used for Receive data

Use Flow Control

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

Flow Control (Handshake) enable or disable.

   On: Two I/O pins are used to control the flow of data in and out of the device.
   Off: Flow control is disabled.

Baud Options

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

Baud rate option selector

Baud Rate

This property is of type Signed integer and can be referenced with the variable name cal_uart::BAUD.

No additional information


Console Columns

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

Number of characters that can be displayed on a single line of the console.

Console Data

This property is of type True or false and can be referenced with the variable name cal_uart::ConsoleData.

Selects if the console data is automatically generated or not

Scope Traces

This property is of type True or false and can be referenced with the variable name cal_uart::ScopeTraces.

Selects if the scope traces are automatically added to the data recorder window or not.

   Simulation - draws an approximation of the UART data onto the scope trace.
   ICT - sets up the scope trace for incoming data and adds UART packet decoding at the correct BAUD.

Data Source

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

Simulation data source used to allow the component to connect to various remote devices

   Nothing - Simulation data is ignored
   COM port - Routes the communication data to and from a physical or virtual COM port 
   Injector - Routes the communication data via a data injector component on the Panel.

Injector

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

Selects which injector component to route the communication data via.

Add injector components to the panel before they will be available in this list.

Injector components are available from the Comms component category.