A newer version of Max is available. Click here to access the latest version of this document.

serial

Send and receive characters from serial ports and cards

Description

The serial object works only with ports and devices supported by the standard serial driver. It does not work with USB ports and devices, unless a USB to Serial adaptor is connected.

Arguments

Name Type Opt Description
symbol a-z symbol opt Specifies the serial port to be used by the serial object. If alphabetic shortcuts are used, a specifies the first logical serial port in the computer, and b- z are used to specify additional ports.
symbol portname symbol If actual portnames are used, the symbol is the name given by the Operating System to your port. The print to the serial object (see above) can be used to create a list of available portnames and alphabetic shortcuts. If the port chosen is currently in use or unavailable when the serial object is instantiated, an error message will be displayed and the object will not function. If no port is specified, the default port is a.
baud-rate int opt An optional argument may be used after the port name or alphabetic shortcut to specify the baud rate of the serial port (the default rate is 4800 baud). Any value is allowable (although not all ports can be set to all baud rates). Some common rates are 300, 600, 1200, 1800, 2400, 3600, 7200, 9600, 19200, 38400, 57600 and 115200.
data-bits int opt After the baud rate, the next arguments specifies the number of data bits for the serial port (the default is 8 data bits). Other possible values are 5, 6 and 7.
stop-bits int opt The next argument specifies the number of stop bits for the serial port. The default is 1. Other possible values are 1.5 (Windows only) and 2.
serial-port-parity int or symbol opt The next argument specifies the parity for the serial port (the default is no parity, specified by 0 or no).Other possible values are odd, 1 (odd), even, and 2 (odd).

Messages

bang Sends each character received on the serial port since the last bang message out the serial object's left outlet as an integer in the order that the characters were received. Before output data is sent, the message read, followed by a number specifying the number of bytes received is sent out the right outlet of the serial object.
int input (0 through 255) [int]
Sends the number out the serial port accessed by the serial object. Numbers outside the range 0-255 are wrapped to that range using a modulo operator. After the data is sent, the message write, followed by a number specifying the number of bytes sent is sent out the right outlet of the serial object.
float input (0 through 255) [float]
Converted to int.
list input-list (0 through 255) [list]
Sends each number in the list out the serial port, in order. Numbers outside the range 0-255 are wrapped to that range using a modulo operator. After the data is sent, the message write, followed by a number specifying the number of bytes sent is sent out the right outlet of the serial object.
break Sends a break command to the serial port used by the serial object. After the break has completed, the message break is sent out the object's right outlet.
close Closes an open serial connection, permitting use of the serial port by other applications.
getport Sends the name or shortcut of the currently open serial port out the serial object's right outlet, prepended by the word port.
port serial-port (shortcut or portname) [list]
The word port, followed by a symbol, specifies the serial port to be used by the object. If alphabetic shortcuts are used, a specifies the first logical serial port in the computer. b - z specify additional ports. If actual portnames are used, the symbol is the name given by the operating system to your port. See the print message, above, for a way to list available portnames and alphabetic shortcuts. If the port chosen is currently in use or unavailable when the port message is sent, an error message will be displayed and the object will revert to its previously chosen port, or won't function if there was none.
print Sends a list of available serial ports to the Max window, along with their alphabetic shortcuts. The message port [portname] [portname]... is also sent from the object's right outlet, with a list of available ports.
open Opens a new serial connection.
refresh Refreshes the list of known/available serial ports. See the print message for additional information.
reset (Mac only) Resets the currently open serial port using the Basic Stamp initialization sequence.

Attributes

Name Type g/s Description
autoopen int Toggles automatically opening the serial port.
baud int Sets the port's baud rate.
bufsize int Sets the input buffer size used by the serial object.
chunk int Sets the data chunk size (data list length) for output.
databits int Sets the number of data bits (acceptable values are 5, 6, 7, or 8).
drain int (Mac only) Toggles drain enable. When enabled, communication waits until all data has been transmitted to the terminal when writing. The default value is 0 (disabled).
dtr int Enables or disables the DTR (data terminal ready) function of the serial port used by the serial object.
parity int Sets the parity for the port. The options are:

0: no parity
1: odd
2: even
serport int Used by the object Inspector only. Users should use the port message.
stopbits int Sets the number of stop bits used when communicating with the serial port.
xonxoff int Enables Xon/Xoff serial flow control.

Information for box attributes common to all objects

Output

(serial output): When a number or list is received in its inlet, serial sends the data out the specified serial port at the current baud rate.
int: When serial receives a bang message and characters have been received in the serial port, the received characters are sent as numbers in the order they were received.
list: When serial receives a bang message, characters have been received in the serial port, and chunking is enabled, the received characters are sent as a list in the order the characters were received. The length of the list is determined by the argument to the chunk message (see the message listing for chunk for more information).

Out right outlet: Reports error and status messages.

Examples

When the button is clicked this patch resets the modem begins polling for a response and stops polling when a response has been received

See Also

Name Description
match Look for a series of arguments, output it as a list whenever an input matches
spell Convert input to ASCII codes
vdp Control a videodisk player through a serial port
Max Comm Tutorial 2: Serial Communication Max Comm Tutorial 2: Serial Communication