Documente Academic
Documente Profesional
Documente Cultură
CoDeSys V 3.x
SysCom.library
CONTENT
1 OVERVIEW 3
2 LIBRARY MODULES 4
2.1 SysComOpen 4
2.2 SysComOpen2 4
2.3 SysComPurge 4
2.4 SysComRead 5
2.5 SysComSetSettings 5
2.6 SysComSetTimeout 6
2.7 SysComGetSettings 6
2.8 SysComClose 6
2.9 SysComWrite 7
2.10 Structure ComSettings 7
2.11 Structure ComSettingsEx 8
2.12 Enumeration COM_Baudrate 9
2.13 Enumeration COM_Parity 9
2.14 Enumeration COM_Ports 9
2.15 Enumeration COM_StopBits 10
2.16 Enumeration COM_Timeout 10
CHANGE HISTORY 11
libdoc_e.dot / V1.0
1 Overview
Note: It depends on the target system, which system libraries can be used in the application program.
This library supports the serial communication with a target system. If the target system
provides the functionality, then the following library functions can be used to open or close a
serial port and to read or write data via this port (The execution is synchronous.):
SysComOpen
SysComOpen2
SysComPurge
SysComRead
SysComSetSettings
SysComSetTimeout
SysComGetSettings
SysComClose
SysComWrite
ComSettings
ComSettingsEx
COM_Baudrate
COM_Parity
COM_Ports
COM_StopBits
COM_Timeout
libdoc_e.dot / V1.0
2 Library Modules
2.1 SysComOpen
This function opens a serial port.
The return value of type RTS_IEC_HANDLE is a handle for the respective port, which can be
passed to other library functions. If the port cannot be opened, 0xFFFFFFFF will be returned.
Input Variable Data type Description
2.2 SysComOpen2
This function opens a serial port. Thereby additional settings concerning the opening of the
port can be passed via structures COMSettings and COMSettingsEX.
The return value of type RTS_IEC_HANDLE gives a handle for the port. This handle can be
passed to other library functions. If the port cannot be opened, 0xFFFFFFFF will be returned
as handle.
Input Variable Data type Description
2.3 SysComPurge
This function empties the input and output buffer of the serial interface.
The return value of type RTS_IEC_RESULT is an error code which tells about the success of
the operation. See document Runtime Error Codes.
Input Variable Data type Description
hCom RTS_IEC_HANDLE Handle for the currently opened port, received from
SysComOpen
libdoc_e.dot / V1.0
2.4 SysComRead
This function reads data from the COM-PORT. For this purpose you have to pass the handle
of the serial port, the address where the read data should be copied, the size of data to be
read and a function timeout.
The return value of type DINT gives the number of actually read bytes.
Input Variable Data type Description
2.5 SysComSetSettings
This function sets the default parameters for a serial port (baudrate, stopbits, parity, function
timeout, buffer size, scan time) resp. extended settings (character size, parameters for
hardware handshake, DTR/RTS control, CTS/DSR flow control and DSR sensitivity etc.). This
is done via the structures COMSettings (standard settings) resp. COMSettingsEx (extended
settings).
Depending on the target system the parameters of an interface may be modified during run
time. However ONCE after having opened the port it must be guaranteed that the parameters
get accepted. Thus, depending on the controller, it might be necessary to close and re-open
the port in order to be able to set the parameters.
The return value of type RTS_IEC_RESULT is an error code which tells about the success of
the operation. See document Runtime Error Codes.
Input Variable Data type Description
hCom RTS_IEC_HANDLE Handle for the port, for which the settings should be
made; acquired by SysComOpen.
pSettings POINTER TO Pointer on structure COMSettings, describing the port
COMSettings standard settings (see chap. 2.10); Operator ADR can
be used.
pSettingsEx POINTER TO Pointer on structure COMSettingsEx, describing
COMSettingsEX additional port settings (see chap. 2.11); Operator
ADR can be used.
libdoc_e.dot / V1.0
2.6 SysComSetTimeout
This function sets a timeout at the currently opened port. After the given time any currently
called Read resp. Write function will return.
The return value of type RTS_IEC_RESULT is an error code which tells about the success of
the operation. See document Runtime Error Codes.
Input Variable Data type Description
hCom RTS_IEC_HANDLE Handle for the port, for which the timeout should be
set; acquired by SysComOpen.
ulTimeout COM_Timeout Time in milliseconds, after which the function returns
at latest;
see enumeration COM_Timeout (chap. 2.16).
2.7 SysComGetSettings
This function reads the parameters of a serial port (e.g. baudrate, stopbits, parity, function
timeout, buffer size and scan time. This is done via structure COMSettings (standard
parameters) resp. COMSettingsEx (extended settings).
The return value of type RTS_IEC_RESULT is an error code which tells about the success of
the operation. See document Runtime Error Codes.
Input Variable Data type Description
hCom RTS_IEC_HANDLE Handle for the port, for which the settings should be
read; acquired by SysComOpen.
pSettings POINTER TO Pointer on structure ComSettings describing the port
COMSettings standard parameters (see chap. 2.10);
Operator ADR can be used for this purpose.
pSettingsEx POINTER TO Pointer on structure ComSettingsEx describing
COMSettingsEX additional port parameters (see Chap. 2.11);
Operator ADR can be used for this purpose.
2.8 SysComClose
This function closes the COM-Port.
The return value of type RTS_IEC_RESULT is an error code which tells about the success of
the operation. See document Runtime Error Codes.
Input Variable Data type Description
2.9 SysComWrite
This function writes data to the given port. You have to pass the port handle, the address and
size of the data to be written and a timeout for the function.
The return value of type DINT gives the number of actually written bytes.
Input Variable Data type Description
hCom RTS_IEC_HANDLE Handle for the port, to which the data should be
written; acquired by SysComOpen.
pbyBuffer POINTER TO BYTE Memory address, from which the data to be written
should be read (can be acquired via ADR operator).
ulSize UDINT Number of bytes to be written.
Component Description
Component Description
SYS_COMPORT3, SYS_COMPORT4);
END_TYPE
Component Description
SYS_COMPORT_NONE := 0 no Port
SYS_COMPORT1 := 1 Port 1
SYS_COMPORT2 Port 2
SYS_COMPORT3 Port 3
SYS_COMPORT4 Port 4
Component Description
Component Description
SYS_INFINITE := The function waits until the reading resp. writing of the given
16#FFFFFFFF number of bytes has been finished.
libdoc_e.dot / V1.0
Change History