FAST SDK Coding Reference 1.0.3
Loading...
Searching...
No Matches
SerialConnection Class Reference

Provides methods to communicate over a serial port. More...

Public Types

enum  BaudRates
 The baud rates available for Arduino. More...
 

Public Member Functions

bool Open ()
 Opens a serial port connection.
 
void Send (string data)
 Writes a string to the serial port.
 
void SendAsLine (string data)
 Writes a string with a new line character to the serial port.
 

Public Attributes

BaudRates baudRate = BaudRates._9600
 Settings, Inspector, Code
The baud rate to use for serial communication.
 
int comPort = 1
 Settings, Inspector, Code
The COM port to use for serial communication.
 
string id
 Settings, Inspector, Code
Identifies this instance.
 
bool isLogging = true
 Inspector, Code
Set to true if all serial activity should be logged to the Editor Console or Player log.
 
UnityAction< string > onDataReceivedEvent
 Inspector, Code
Calls the function(s) subscribed to this UnityAction when data is received.
 
int readTimeout = 10
 Inspector, Code
The number of milliseconds before a time-out occurs when a read operation does not finish.
 
int writeTimeout = 10
 Inspector, Code
The number of milliseconds before a time-out occurs when a write operation does not finish.
 

Properties

List< string > Data [get]
 Gets the list of data recieved since the last read.
 

Private Attributes

bool isOverwrite = false
 Inspector
Set to true if incoming the data should overwrite the previous data. Otherwise the data will added to FAST.SerialConnection.Data in the order it is recieved.
 

Detailed Description

Provides methods to communicate over a serial port.

Receiving data is threaded for high-performance.

Note
This class is designed for string messages.
See also
System.IO.Ports.SerialPort
System.Threading.Thread

Member Enumeration Documentation

◆ BaudRates

enum BaudRates

The baud rates available for Arduino.

Member Function Documentation

◆ Open()

bool Open ( )

Opens a serial port connection.

A Thread is started if one doesn't exist.

Returns
true if successful, else false
Note
Instead of calling Open() and configuring a FAST.SerialConnection yourself, FAST.SerialConnectionLoader and FAST.SerialConnectionSettings should be used to open a serial connection with settings from file during the application load screen.

◆ Send()

void Send ( string data)

Writes a string to the serial port.

Parameters
dataThe string data to send.

◆ SendAsLine()

void SendAsLine ( string data)

Writes a string with a new line character to the serial port.

Parameters
dataThe string data to send.

Member Data Documentation

◆ baudRate

BaudRates baudRate = BaudRates._9600

Settings, Inspector, Code
The baud rate to use for serial communication.

Loaded from FAST.SerialConnectionSettings at runtime.

◆ comPort

int comPort = 1

Settings, Inspector, Code
The COM port to use for serial communication.

Loaded from FAST.SerialConnectionSettings at runtime.

◆ id

string id

Settings, Inspector, Code
Identifies this instance.

Loaded from FAST.SerialConnection at runtime.

◆ isLogging

bool isLogging = true

Inspector, Code
Set to true if all serial activity should be logged to the Editor Console or Player log.

Recieved messages are not logged because the communication may be too frequent.

◆ isOverwrite

bool isOverwrite = false
private

Inspector
Set to true if incoming the data should overwrite the previous data. Otherwise the data will added to FAST.SerialConnection.Data in the order it is recieved.

◆ onDataReceivedEvent

UnityAction<string> onDataReceivedEvent

Inspector, Code
Calls the function(s) subscribed to this UnityAction when data is received.

Warning
Use with caution if communication might be frequent. FAST.SerialConnection receives data on a separate thread, but these callbacks execute on Unity's main thread. Use FAST.SerialConnection.isOverwrite to only invoke this event on the most recent data received.

◆ readTimeout

int readTimeout = 10

Inspector, Code
The number of milliseconds before a time-out occurs when a read operation does not finish.

◆ writeTimeout

int writeTimeout = 10

Inspector, Code
The number of milliseconds before a time-out occurs when a write operation does not finish.

Property Documentation

◆ Data

List<string> Data
get

Gets the list of data recieved since the last read.

The list of data is ordered from oldest to newest. If FAST.SerialConnection.isOverwrite is true, the list only has 1 element.
After reading, the list is cleared from FAST.SerialConnection.


The documentation for this class was generated from the following file: