rocrail-server-scripting-en
RCP Scripting
- RCP Scripting | SRCP Scripting
- Rocrail Client Protocol (RCP)
The only thing new about scripting is the fact that it is now documented; Rocrail scripting has been available from the early beginnings of the project.
HowTo
Only a few steps are needed to execute a user defined script. The following pages provide the necessary information:
- Scripts can be activated by actions of type "External".
- The protocol is the same as all clients are using to communicate with the server.
It is also possible to activate the script manually, from the command line, or by another application.
Python
Example
A Python example for turning on the global power:
#!/usr/bin/python # Rocrail XML script example: Power ON. from socket import * # Subroutine for adding the XML-Header and send it to the server def sendMsg( s, xmlType, xmlMsg ): buffer = "<xmlh><xml size=\"%d\" name=\"%s\"/></xmlh>%s" %(len(xmlMsg), xmlType, xmlMsg) s.send(buffer.encode()) # Create the server connection s = socket(AF_INET, SOCK_STREAM) s.connect(('localhost', 8051)) # Compose the power on command and send it rrMsg = "<sys cmd=\"go\"/>" sendMsg( s, "sys", rrMsg ) # Close server connection s.close()
Just copy and paste this Python example in a text editor and save it in a file with the ".py" extension.
(Linux: Add the execution bit with "chmod +x myscript.py
".)
Server trace
The erros of the closed connection are normal and can be ignored.
20110515.150347.205 r9999I cconmngr OClntCon 0354 client connect count: 18 20110515.150347.206 r9999I cmdrB730 OClntCon 0209 cmdReader started for:127.0.0.1. 20110515.150347.206 r9999I infwB730 OClntCon 0104 infoWriter started for:127.0.0.1. 20110515.150348.206 r9999c cmdrB730 OVirtual 0324 Power ON 20110515.150348.207 r9999I cmdrB730 OControl 0826 State event from=vcs-1 20110515.150348.207 r9999I cmdrB730 OModel 1704 informing 1 listeners of a system event... (Ignore the errors:) 20110515.150348.209 r8030E infwB730 OSocket 0626 send() failed [32] [Broken pipe] 20110515.150348.209 r9999E infwB730 OSocket 0630 Connection broken! 20110515.150348.217 r9999E cmdrB730 OSocket 0685 Socket 0x00000000 error 88 20110515.150348.217 r9999I cmdrB730 OClntCon 0322 Server ended. 20110515.150348.220 r9999I infwB730 OClntCon 0172 InfoService ended.
rocrail-server-scripting-en.txt · Last modified: 2024/05/12 15:06 by rjversluis