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
  • Closing the port after a read or write operation
  • Using an external library: RXTX
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Closes the specified serial port, parallel port or infrared port.
Remarks:
  • A port must be closed as soon as it is no longer used.
  • Java Infrared ports are not supported.
  • Linux Only serial ports are supported.
Example
NumPort is int
NumPort = sOpen("COM1", 2000, 2000) // Ouverture de COM1
IF NumPort <> 0 THEN
	// Paramétrage de COM1 : Taux 9600, parité paire, 
	// 8 bits de données, 1 bit de stop
	sParameter(NumPort, 9600, 1, 8, 0)
	// Suite traitement...
	sClose(NumPort) // Fermeture de COM1
ELSE
	Error("Erreur d'ouverture de COM1")
END
Syntax
sClose(<Port number>)
<Port number>: Integer
Identifier of the port used:
  • Port number:
    • Serial port number: 1, 2, 3, ... 32 for COM1, COM2, COM3, ... COM32.
    • Parallel port number: -1, -2, -3 or -4 for LPT1, LPT2, LPT3 or LPT4.
    • Infrared port number: 1, 2, 3, ... 32 for IR1, IR2, IR3, ... IR32.
  • Port identifier returned by sOpen (if this function was called with a port name).
    Linux Only this type of parameter is available.
Remarks

Closing the port after a read or write operation

If sClose is run just after sWrite or sRead, some characters may not be written or read. Indeed, sClose can close the port before all the characters are written or read. To avoid this behavior, use Multitask.
Res = sOpen("COM2", 2000, 2000)
IF Res <> 0 THEN
	sParameter(Res, 9600, 0, 8, 0)
	sWrite(Res, Ch)
	Multitask()
	sClose(Res)
END
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.
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