TwinCAT System Service

The TwinCAT System Service offers an interface for the TwinCAT server for Windows NT services. At present, data access and "System Shutdown" are supported. Refer to the documentation for the ADS DLL and for the ADS OCX for further explanations of ADS services. 

File access

Files can be opened or closed, read, and written via ADS index group and ADS index offset. The index groups and index offsets are described below.

Process

Description

Open/create file

 

Indexgroup:
SYSTEMSERVICE_OPENCREATE= 100

Indexoffset:
SYSTEMSERVICE_OPENGENERIC = 1

The stated file is opened for read and write access. If the file does not exist, a file is created and opened. If the file exists, it is opened, and the contents are deleted. ADS Service: ADS Write
Parameter: Length of the path name
Path name as a character string
Return value:
If successful: file handle for the opened file
In the event of an error: -1

Opening file for reading

 

Indexgroup:
SYSTEMSERVICE_OPENREAD = 101

Indexoffset:
SYSTEMSERVICE_OPENGENERIC = 1

The stated field is opened for read access. If the file does not exist, the service returns the value -1.
ADS service: ADS Write Parameter: Length of the path name
Path name as a character string
Return value
If successful: file handle for the opened file
In the event of an error: -1

Opening file for writing

 

Indexgroup:
SYSTEMSERVICE_OPENWRITE = 102

Indexoffset:
SYSTEMSERVICE_OPENGENERIC = 1

The stated file is opened for read and write access. If the file does not exist, the service returns the value -1. If the file exists. it is opened and the contents are deleted.
ADS service: ADS Write
Parameter: Length of the path name
Path name as a character string
Return value
If successful: file handle for the opened file

In the event of an error: -1

Close file

 

Indexgroup:
File Handle

Indexoffset:
SYSTEMSERVICE_NOSEEK = -1

The file which belongs to the File Handle is closed. It must be noted that the data length for this service must be 0!
ADS service: ADS Write
Data length: 0

Write data to file

 

Indexgroup:
File Handle

Indexoffset:
SYSTEMSERVICE_NOSEEK = -1 or

Seek Offset in byte

The number of bytes stated in the data length is written to the file. If an index offset is not equal to -1, the index offset is interpreted as the offset in the file.
The number of written bytes is returned by this service in the reply. In the event of an error, the service returns the value -1.
ADS service: ADS Write
Data length: number of bytes to be written.

Read data from file

Indexgroup:
File Handle

Indexoffset:
SYSTEMSERVICE_NOSEEK = -1 or

Seek Offset in byte

The number of bytes stated in the data length is read from the file. If the index offset is unequal to -1, the index offset is interpreted as the offset in the file. With a data length of 0, only the file indicator in the file is offset by the value in the index offset.
The number of read bytes is returned by this service in the reply. In the event of an error, the services returns the value -1.
ADS service: ADS Read
Data length: number of bytes to be read.

System shutdown

ADS WriteControl enables the TwinCAT System Service to be instructed to shut down the operating system.
ADS service: ADS WriteControl
AdsState: ADSSTATE_SHUTDOWN = 12
DeviceState: Shutdown of Windows NT with DEVICESTATE = 0, restart of Windows NT with DEVICESTATE = 1
DeviceData: timeout in seconds until system shutdown
Data length: 4 bytes