The Serial Control is the control through which serial data may be sent and received via a standard RS-232 COM Port or a virtual COM using USB or other protocols.
Some basic information about using it:
•Ensure the correct port is selected.
•Ensure the baud rates match with the device.
•Ensure the COM Port is NOT in use by any other application.
•Other serial port settings, such as Bits and parity may be set through its properties.
•On many controllers, having the DTR line cycle on connect will cause the controller to reset. Un-check this box to not cycle DTR on connect.
•When connected, a string in properties is processed called ConnectionString. By default the code it holds resets the plot named 'plot. !plot.reset When "Use Conn Str" is not checked, this action will not be performed. The Connection String can be changed as desired.
•The RX and TX indicators will blink as serial data is received and transmitted.
•The progress bar directly under the Connect button shows how many bytes are in the buffer awaiting processing.
•The next progress bar down shows how many lines of data are in the processing queue of the main interface.
Receiving Data
MakerPlot, based on data string format, handles most actions for received data. Please see topics in Processing Concepts.
Sending (Reading) Data
MakerPlot's main processes contain a send and read instruction through which data for a Serial Control, named serial, may be sent. The send and read instructions are identical in function, but from MPJ's perspective, it sends data, and from the controller's perspective, it reads data.
Using send (or read) data may be sent to the controller. Such as sending the value of a slider called sldPower: !send [sldPower] // MPJ code to send value
data = Serial.parseInt(); // controller code to accept data
Serial.println("!read [sldPower]"); // controller code to request (read) and accept data data = Serial.parseInt();
The Serial Control has instructions as well, in the event more options are needed, or the control is not named serial.
!serialControlName.send string - Sends the string with end of line - EOL - added as new line, carriage return. !serialControlName.read string - Sends the string with end of line - EOL - added as new line, carriage return. !serialControlName.sendNoEOL string - Sends the string without end of line - EOL.
!serialControlName.sendBytes - Uses decimal values to send a string of bytes, or if non-numeric, their ASCII values are sent.
!serial.sendBytes 64,65,66,A,B,C
From the controller's side, using read as either the main process read, or a serial control's read instruction, will bypass the processing queue providing a much faster return of data to the controller.
As mentioned, using !read from the main processes instructions uses the default control named serial. When the controller issues the !read, it will specify which serial control was used so that data can be returned to the correct controller. This allows all !read instructions from the controller side to be processed correctly regardless of the serial control's name.
Interactive Data
Please see Controller Interactive Data from recommendations of interactive interfaces.
Instructions
The serial port supports the following instructions:
A few not discussed so far:
openPort: Opens the selected Port on the control
closePort: Closes the port.
flush: Flushes the port of data
Properties
The Serial Control has a number of properties of interest.
•(need to revisit port & port select)
•processMain: Processing of the incoming serial data by the main processes can be disabled. This can help prevent confusion is using multiple serial ports - values such as [serial.ain0] can be accessed from the serial control.
•delimiter: By default the delimiter is a comma for strings. This may be changed for the serial control and for the main interface. Use spc for a space and tab for a tab.
•maxBufferSize: Defines how many bytes to hold in the buffer. If exceeded, the buffer will empty so that 'old' data is not being plotted.
•maxQueSize: This does not control the size of the processing queue, but is a limiter on how big it should grow as serial data is placed into it. If the value is exceeded from serial data, the queue will empty.
•connectString: When a serial connection is opened, this string will be placed in the queue for processing. It may be disabled by setting useConnectString to 0.
•redundancyCheck: For simple error checking, the same string must be received twice to be processed. Disabled by default.
Values
The serial control has the following values that may be accessed by code, such as: ? [serial.ain0]
Event Triggers
The following event triggers can be used in the Event Code:
<load> Triggers on control load or !runLoad issued.
<analog> Triggered on incoming analog data.
<digital> Triggered on incoming digital data.
<message> Triggered on incoming message data.
<open> Triggered on port opening.
<close> Triggered on port closing.
|