Cognitive Vision icon Cognitive Vision — Microsoft Cognitive Vision integration for ARC: real-time object, face, emotion detection, OCR, confidence data and script-triggered robot actions. Try it →
 

COM

Use the serial (COM) ports of the computer ARCx runs on, such as a USB to serial adapter or an Arduino plugged in by USB. Open the port with its name and speed, write text or bytes, read what comes back, and close it when done. For the serial ports of an EZB, use the UART group instead.

Where to find it: type COM. in a JavaScript script, or open the ARCx API view of the script editor and expand COM


Commands

Command What it does
COM.available Returns how many received bytes are waiting to be read on an open serial (COM) port.
COM.availablePorts Lists the serial (COM) ports on this computer, such as COM3 on Windows or /dev/ttyUSB0 on Linux.
COM.clearInputBuffer Throws away any received data waiting on an open serial (COM) port.
COM.close Closes a serial (COM) port that was opened by a script.
COM.isPortOpen Checks whether a serial (COM) port on this computer is currently open by a script.
COM.open Opens a serial (COM) port on this computer at the given baud rate.
COM.read Reads the given number of bytes from an open serial (COM) port.
COM.readAllText Reads all text received so far on an open serial (COM) port, without waiting for more.
COM.readByte Reads one byte from an open serial (COM) port, waiting until one arrives.
COM.readLine Reads text from an open serial (COM) port up to the next newline character.
COM.write Sends one byte to an open serial (COM) port.
COM.writeString Sends text as ASCII to an open serial (COM) port, without adding a line ending.
COM.writeStringNewLine Sends text as ASCII to an open serial (COM) port, followed by a newline character.

Details

COM.available

Returns how many received bytes are waiting to be read on an open serial (COM) port. An error is raised if the port is not open.

COM.available(port)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.

Gives back: number. The number of bytes waiting.

COM.availablePorts

Lists the serial (COM) ports on this computer, such as COM3 on Windows or /dev/ttyUSB0 on Linux.

COM.availablePorts()

Gives back: string[]. The port names.

COM.clearInputBuffer

Throws away any received data waiting on an open serial (COM) port. An error is raised if the port is not open.

COM.clearInputBuffer(port)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.

COM.close

Closes a serial (COM) port that was opened by a script. Does nothing if the port is not open.

COM.close(port)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.

COM.isPortOpen

Checks whether a serial (COM) port on this computer is currently open by a script.

COM.isPortOpen(port)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.

Gives back: boolean. Whether the port is open.

COM.open

Opens a serial (COM) port on this computer at the given baud rate. An error is raised if the port is already open or cannot be opened.

COM.open(port, baud)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.
baud number The baud rate in bits per second, such as 9600 or 115200.

COM.read

Reads the given number of bytes from an open serial (COM) port. An error is raised if fewer bytes have arrived, so check how many are available first.

COM.read(port, bytesToRead)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.
bytesToRead number How many bytes to read.

Gives back: number[]. The bytes read.

COM.readAllText

Reads all text received so far on an open serial (COM) port, without waiting for more. An error is raised if the port is not open.

COM.readAllText(port)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.

Gives back: string. The received text, or an empty string when nothing has arrived.

COM.readByte

Reads one byte from an open serial (COM) port, waiting until one arrives. The raw byte is returned unchanged, so every value from 0 to 255 comes back as sent.

COM.readByte(port)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.

Gives back: number. The byte read, 0 to 255.

COM.readLine

Reads text from an open serial (COM) port up to the next newline character. The script waits until a full line arrives.

COM.readLine(port)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.

Gives back: string. The line of text, without the newline.

COM.write

Sends one byte to an open serial (COM) port. An error is raised if the port is not open.

COM.write(port, @byte)
COM.write(port, byteArray)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.
byteArray number[] Only in some forms. The bytes to send, as an array of numbers from 0 to 255.
@byte number Only in some forms.
  • COM.write(port, @byte): Sends one byte to an open serial (COM) port. An error is raised if the port is not open.
  • COM.write(port, byteArray): Sends bytes to an open serial (COM) port. An error is raised if the port is not open.

COM.writeString

Sends text as ASCII to an open serial (COM) port, without adding a line ending. An error is raised if the port is not open.

COM.writeString(port, str)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.
str string The text to send.

COM.writeStringNewLine

Sends text as ASCII to an open serial (COM) port, followed by a newline character. An error is raised if the port is not open.

COM.writeStringNewLine(port, str)
Value Type What it is
port string The port name, such as COM3 on Windows or /dev/ttyUSB0 on Linux.
str string The text to send.