OpenSerialPort()

Syntax

Result = OpenSerialPort(#SerialPort, SerialPortName$, Bauds, Parity, Data, Stop.f, HandshakeMode, InputBufferSize, OutputBufferSize)
Description
Opens a serial port for use.

Parameters

#SerialPort A number to identify the new serial port. #PB_Any can be used to auto-generate this number.
SerialPortName$ Text identifier for the serial port, for example "COM1" on Windows or "/dev/ttyS0" on Linux.
Bauds Defines the speed of the serial connection and can be one of the following values:
    50, 75, 110, 150, 300, 600, 1200, 1800, 2400
    4800, 9600, 19200, 38400, 57600 or 115200
Parity Defines how the parity will be handled on the connection. It can be one of the following values:
  #PB_SerialPort_NoParity   : No parity
  #PB_SerialPort_EvenParity : Even parity
  #PB_SerialPort_MarkParity : Mark parity
  #PB_SerialPort_OddParity  : Odd parity
  #PB_SerialPort_SpaceParity: Space parity
Data Defines the data length, in byte (usually 7 or 8).
Stop Sets the number of stop bits (1, 1.5 or 2).
HandshakeMode The handshake mode. It can be one of the following values:
  #PB_SerialPort_NoHandshake     : No handshaking
  #PB_SerialPort_RtsHandshake    : No handshaking but RTS is set to 1
  #PB_SerialPort_RtsCtsHandshake : RTS/CTS
  #PB_SerialPort_XonXoffHandshake: Xon/Xoff
InputBufferSize Defines the size of the input buffer, in bytes.
OutputBufferSize Defines the size of the output buffer, in bytes.

Return value

Nonzero if the serial port was successfully opened, zero otherwise (it may be already in use, or the parameters are wrong). If #PB_Any was used for the #SerialPort parameter then the generated number is returned on success.

Example

  If OpenSerialPort(0, "COM1", 300, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
    Debug "Success"
  Else
    Debug "Failed"
  EndIf

See Also

CloseSerialPort()

Supported OS

All

<- IsSerialPort() - SerialPort Index - ReadSerialPortData() ->