ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Serial/Parallel Ports functions
  • Operating mode
  • Using an external library: RXTX
  • Features specific to Android and Android widget
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
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
LinuxAndroidAndroid Widget Java Parallel and infrared ports are not supported.
WEBDEV - Server code This function affects the server.
WindowsJava
// Ouverture de COM1 (en utilisant le numéro du port)
LigneCom1 = sOpen(1, 2000, 2000)
IF LigneCom1 = True THEN
	// Paramétrage de COM1 : Taux 9600, parité paire, 
	// 8 bits de données, 1 bit de stop
	sParameter(1, 9600, 1, 8, 0)
	// Suite traitement...
	// Fermeture de COM1
	sClose(1)
ELSE
	Error("Erreur d'ouverture de COM1")
END
// Ouverture de IR1 (en utilisant le nom du port)
IR1 = sOpen("IR1", 2000, 2000)
IF IR1 <> 0 THEN
	// Paramétrage de IR1
	sParameter(IR1, 9600, 1, 8, 1)
	// Suite traitement...
	// Fermeture de IR1
	sClose(IR1)
ELSE
	Error("Erreur d'ouverture de IR1")
END
Syntax
LinuxAndroidAndroid 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:
  • Serial port number: 1, 2, 3, ... 256 for COM1, COM2, COM3, ... COM256.
  • Parallel port number: -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.
  • 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 correspond to:
  • an integer representing the number of milliseconds,
  • a Duration variable,
  • the duration in a readable format (e.g., 1 s or 10 ms).
Java No timeout will be applied if this parameter is not specified. The sDefaultTimeout constant is not available. If a timeout is specified, it will be applied to the read operations performed on the serial ports.
<Managing events>: Optional boolean
  • True to detect the events on the serial port,
  • False (default) 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:
    • or the number of the serial port concerned: 1, 2, 3, ... 256 for COM1, COM2, COM3, ... COM256.
    • or the relevant parallel port number: -1, -2, -3 or -4 for LPT1, LPT2, LPT3 or LPT4.
    • or the relevant infrared port number: 1, 2, 3, ... 256 for IR1, IR2, IR3, ... IR256.
  • 0 if an error occurs.
LinuxAndroidAndroid Widget Caution:
  • This identifier does not correspond to the serial port number.
  • Parallel port management is not available.
  • Java Infrared ports are not supported.
<Port name>: Character string
Name of relevant port:
  • Name of serial port::
    • COM1, COM2, COM3, ... COM256.
    • Java Java serial port name: /dev/ttyS4, /dev/ttyS5, ... /dev/ttyS9.
    • Linux Serial port number in Linux (for example /dev/ttyS1).
    • AndroidAndroid Widget Name of the serial port returned by sListPort.
  • Parallel port name: LPT1, LPT2, LPT3 or LPT4.
  • Infrared port name: IR1, IR2, ... IR256.
LinuxAndroidAndroid Widget Reminder:
  • Parallel port management is not available.
  • Java Infrared ports are not supported.
<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.
  • 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 correspond to:
  • an integer representing the number of milliseconds,
  • a Duration variable,
  • the duration in a readable format (e.g., 1 s or 10 ms).
Java No timeout will be applied if this parameter is not specified. The sDefaultTimeout constant is not available. If a timeout is specified, it will be applied to the read operations performed on the serial ports.
Remarks

Operating mode

  • A port cannot be opened if this port was not closed properly.
  • Important: A port must be opened with sOpen before it can be set with sParameter.
  • WLanguage does not support control signals.
  • Two stations send characters to each other via a port: if the second station uses the function sOpen function after the first station has sent characters, these characters are ignored.
Remarks:
  • WINDEV If the WIN.INI file contains initialization values for the specified serial port, these values are used.
  • Windows The following entries of the registry return the list of serial ports and parallel ports:
    • "HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM" for the serial ports.
    • "HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\PARALLEL PORTS" for the parallel ports.
Linux Special case for Linux:
  • Only serial ports can be opened and initialized.
  • By default, users do not have access to serial ports. It is necessary to grant them specific rights to manage serial ports.
Java

Using an external library: RXTX

In Java, the use of serial and parallel port manipulation functions (functions sOpen, sWrite, sRead, ...) requires the presence of an external library: RXTX.
This library includes a Jar archive and one or more native libraries that depend on the operating system on which the application is run. To use these functions:
  • the Jar archive (RXTXComm.jar) must:
    • be found in the same directory as the Java application generated by WINDEV,
    • be found in the execution classpath of the application,
    • be directly included in the generated application (from the wizard for Java generation).
  • the native libraries corresponding to the operating system on which the application is run must be found:
    • in the same directory as the Java application generated by WINDEV,
    • in the path of the application libraries (librarypath).
You can download the RXTX library and its documentation from the following link: http://users.frii.com/jarvi/rxtx/index.html (link valid at the time of writing).
Attention: Infrared port management not available in Java.
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: wd300com.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 03/27/2025

Send a report | Local help