OpenSerialPort()

Syntax

Result = OpenSerialPort(#SerialPort, SerialPortName$, Bauds, Parity, Data, Stop, HandshakeMode, InputBufferSize, OutputBufferSize)
Description
Open a serial port for use. If #PB_Any is used as '#SerialPort' parameter, the new serial port number will be returned as 'Result'. 'SerialPortName$' is the text identifier for the serial port, for example "COM1" on Windows or "/dev/ttyS0" on Linux. 'Bauds' determines the speed of the serial connection and may 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 may 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' may 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 in bytes of the input buffer. 'OutputBufferSize' defines the size in bytes of the output buffer.

If the serial port can't be opened (it may be already in use, or the parameters are wrong), 'Result' will be 0.

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

Supported OS

All

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