ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
  • Operating mode
  • Features specific to Android and Android widget
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Opens and initializes:
  • a serial port.
  • a parallel port.
  • an infrared port. In this case, only the second syntax is available.
The default values are as follows:
  • Transfer rate: 9600 Bauds
  • Parity: None
  • 8 data bits
  • 1 stop bit
AndroidAndroid Widget Parallel and infrared ports are not supported.
// Open IR1 (using the port name)
IR1 = sOpen("IR1", 2000, 2000)
IF IR1 <> 0 THEN
// Configure IR1
sParameter(IR1, 9600, 1, 8, 1)
// Rest of process...
// Close IR1
sClose(IR1)
ELSE
Error("Error while opening IR1")
END
Syntax
AndroidAndroid Widget Not available in Linux, Android and Android widget

Opening and initializing a port by specifying its number Hide the details

<Result> = sOpen(<Port number> , <Size of input buffer> , <Size of output buffer> [, <Timeout> [, <Managing events>]])
<Result>: Boolean
  • True if the port was opened and initialized,
  • False otherwise.
<Port number>: Integer
Number of relevant port:
  • Number of the serial port: 1, 2, 3, ... 256 for COM1, COM2, COM3, ... COM256.
  • Number of the parallel port: -1, -2, -3 or -4 for LPT1, LPT2, LPT3 or LPT4.
<Size of input buffer>: Integer
Size of input buffer in bytes (up to 32768).
<Size of output buffer>: Integer
Size of output buffer in bytes (up to 32768).
<Timeout>: Optional integer or optional Duration
Duration (expressed in milliseconds) for reading or writing a character. If <Timeout> is set to 1s when writing 1024 bytes, the waiting time will be 1024s.
This parameter is used to avoid a lock when a read or write problem occurs on the print port.
  • New in version 28
    if <Timeout> is negative, the waiting time will be constant. For example, if <Timeout> time is set to "-1s" when reading 1024 bytes, the waiting time will be 1s.
  • When <Timeout> has expired, the read or write function returns 0.
  • The default value of this parameter is defined at system level.
    The sDefaultTimeout constant allows you to use the default timeout.
This parameter can be:
  • an integer corresponding to the number of milliseconds,
  • a Duration variable,
  • the duration in a readable format (e.g., 1 s or 10 ms).
<Managing events>: Optional boolean
  • True to detect the events on the serial port,
  • False (default value) to avoid managing the events. These events can be managed by sEvent.

Opening and initializing a port by specifying its name Hide the details

<Result> = sOpen(<Port name> , <Size of input buffer> , <Size of output buffer> [, <Timeout>])
<Result>: Integer
  • Identifier of open port. This identifier can be used in the functions for managing ports.
    This identifier corresponds to:
    • the number of the relevant serial port: 1, 2, 3, ... 256 for COM1, COM2, COM3, ... COM256.
    • the number of the relevant parallel port: -1, -2, -3 or -4 for LPT1, LPT2, LPT3 or LPT4.
    • the number of the relevant infrared port: 1, 2, 3, ... 256 for IR1, IR2, IR3, ... IR256.
  • 0 if an error occurs.
AndroidAndroid Widget Caution:
  • This identifier does not correspond to the serial port number.
  • Parallel port management is not available.
<Port name>: Character string
Name of relevant port:
  • Name of serial port::
    • COM1, COM2, COM3, ... COM256.
    • AndroidAndroid Widget Name of the serial port returned by sListPort.
  • Name of parallel port: LPT1, LPT2, LPT3 or LPT4.
  • Name of infrared port: IR1, IR2, ... IR256.
AndroidAndroid Widget Reminder:
  • Parallel port management is not available.
<Size of input buffer>: Integer
Size of input buffer in bytes (up to 32768).
<Size of output buffer>: Integer
Size of output buffer in bytes (up to 32768).
<Timeout>: Optional integer
Duration (expressed in milliseconds) for reading or writing a character. If <Timeout> is set to 1s when writing 1024 bytes, the waiting time will be 1024s.
This parameter is used to avoid a lock when a read or write problem occurs on the print port.
  • New in version 28
    if <Timeout> is negative, the waiting time will be constant. For example, if <Timeout> time is set to "-1s" when reading 1024 bytes, the waiting time will be 1s.
  • When <Timeout> has expired, the read or write function returns 0.
  • The default value of this parameter is defined at system level.
    The sDefaultTimeout constant allows you to use the default timeout.
This parameter can be:
  • an integer corresponding to the number of milliseconds,
  • a Duration variable,
  • the duration in a readable format (e.g., 1 s or 10 ms).
Remarks

Operating mode

  • A port cannot be opened if this port was not closed properly.
  • Important: A port must be opened by sOpen before it can be configured by sParameter.
  • WLanguage does not allow you to manage the control signals.
  • Two computers send each other characters via a port: if the second computer calls sOpen once the characters have been sent by the first computer, these characters are ignored.
Remarks:
    AndroidAndroid Widget

    Features specific to Android and Android widget

    In Android and Android widget mode, the serial and parallel port functions can be used:
    • Only on serial (not parallel or infrared) ports.
    • Only with devices that support the CDC/ACM protocol (Arduino ATmega32U4) and the following USB to serial converter chips:
      • FTDI FT232R, FT232H, FT2232H, FT4232H, FT230X, FT231X, FT234XD
      • Silabs CP210x
      • Qinheng CH340, CH341A
      • Prolific PL2303
    Specific features of sOpen:
    • Only serial ports can be opened and initialized.
    • The user will see a dialog box to allow the application to connect to the device.
    • This function must be called in the main the thread of the application.
    • Events are not supported.
    • Only the syntax to open and initialize a port by specifying its name is available.
    Business / UI classification: Business Logic
    Component: wd280com.dll
    Minimum version required
    • Version 9
    This page is also available for…
    Comments
    exemplo
    sClose(EDT_Porta_COM)
    // Open COM (using the port number)
    // sOpen(Porta,SizeInBuffer,SizeOutBuffer,Timeout,ManagerEvents)
    LineCom is boolean = sOpen(EDT_Porta_COM, EDT_Buffer_de_Entrada, EDT_Buffer_de_Saida)

    IF LineCom = True THEN
    // Configure COM1: Rate 9600, even parity,
    // 8 data bits, 1 stop bit
    //sParameter()
    LineCom = sParameter(EDT_Porta_COM, EDT_Bit_por_segundos, EDT_Paridade, EDT_Bit_de_Dados, EDT_Bit_de_Parada)
    // Rest of process...
    EDT_Historico += sRead(EDT_Porta_COM,EDT_Buffer_de_Entrada) + CR + CR

    EDT_Historico += sWrite(EDT_Porta_COM,EDT_Comando_AT) + CR + CR

    EDT_Historico += sRead(EDT_Porta_COM,EDT_Buffer_de_Entrada) + CR + CR
    // Close COM1
    sClose(EDT_Porta_COM)
    ELSE
    Error("Error while opening COM"+EDT_Porta_COM)
    END




    Boller
    20 May 2022