Thank you. I have a working solution now. It uses three item definitions:
String Projector_RS232 "Projector RS232 [%s]" { tcp="<[myIP:23:'REGEX(([INFOK0-9]+))']" } //catch any response from projector
String Projector_RS232out "Projector RS232out [%s]" { tcp=">[myIP:23:default]" } //send data to Projector
String Projector_RS232tmp "Projector tmp [%s]" // remember last send command
and theses rules:
rule "rProjectorCommunication"
when
Item Projector_RS232 changed
then
if (Projector_RS232.state.toString.contains ("INFO")) {
switch E_Wo_Beam_RS232.state.toString {
case "INFO0": { Projector_Status.postUpdate("Standby") }
case "INFO1": { Projector_Status.postUpdate("Warming") }
// ... repeat for all other INFO codes
}
Projector_RS232tmp.sendCommand("")
}
if (Projector_RS232.state.toString.contains ("OK")) {
switch Projector_RS232tmp.state.toString {
case "~01124 1": { // repeat the case part for all other commands that will be send
if (Projector_RS232.state.toString == "OK1") { logInfo("Projector.rules", " Projector is ON ") }
if (Projector_RS232.state.toString == "OK0") { logInfo("Projector.rules", " Projector is Standby") }
}
}
}
if (Projector_RS232.state.toString.contains ("~")) {
logInfo("Projector.rules", "RS232 Command to Projector: "+E_Wo_Beam_RS232.state)
Projector_RS232out.sendCommand(Projector_RS232.state.toString)
Projector_RS232tmp.postUpdate(Projector_RS232.state.toString)
}
end
And from anywhere needed, I send the necessary command with e.g.:
Projector_RS232.postUpdate("~01124 1")
This is maybe not the most elegant way to do it. So I am happy for any advice to improve the code.
The other problem with the TCP binding is the spamming of the log (see here