Running VBA script in openhab / communication with PLC through DLL file

Tags: #<Tag:0x00007efebf1e2688> #<Tag:0x00007efebf1e2598>

Hi,

At home I have an elder PLC (Moeller PS4 - ± 20 years old :sweat_smile: )
The PLC is controlling all lights, hot water boiler, … and the entire house is foreseen with push buttons.
As I already have this splendid system, it would be a pity if I couldn’t integrate it with openhab.
The PLC itself communicates with RS232, but there is an DLL file so you can communicate to excel, …
I have bought a second one to experiment and I already was able to access, read and write in Excel Merker Values to and from the PLC using VBA.
I can write in VBA and, as Java is not very much different then Visual Basic, I think I can manage Java also.
Currently I have already a (very basic) project working with openhab and my intentions are to run it on a Windows PC which I also will use as a multimedia server.

To continue with my OpenHab project (view which lights are on, …), I need to find a way to read the data of the PLC in OpenHab (through the DLL-file). Would anybody have any idea what would be the best solution?

If desired, I can upload tonight a part of the VBA script (but can’t upload yet any file as a new member of Openhab :wink: )

Kind regards,
Bastn

If the DLL was not written and compiled with Java Native Interface (JNI) in mind I’m afraid you may be out of luck. Your best bet may be to somehow wrap the DLL with some sort of script or executable that OH can call from the command line.

But my Java programming skills are getting pretty old at this point. There might be something that has changed in Java 11 to make this easier, but I doubt it based on some Google searches.

If you know the RS232 communication protocol you could write your own code to communicate with it. This is could either be done I will rules in openHAB via the serial binding, or by an external script that communicates with openhab.

unfortunately I only have the DLL file and an example in excel.
So I can change values in excel from and to the plc.

Would a possible solution be to write an exe program (in Visual Basic) where I can read / write to a “log” file (or database) where I can name by example “light bulb 1.value = 1” and read (/write) from this file in OH to control my lamps / switches?

that is not true. JNA is a standard way to use DLL’s in Java: GitHub - java-native-access/jna: Java Native Access

What about create Win32 service that will communicate with PLC and act as TCP server with some OH supported protocol (e.g. Modbus)?
Another approach may be not use library at all and try to capture Moeller protocol.