Simple RS232 & IP control

Hello!

I am trying to control a presentation system with projectors, HDMI switches and audio routers. All the devices can be controlled over RS232 or ethernet, and I’m going to accomplish this on a Windows PC with RS232-USB adapters and a touch screen running HABPanel.

Despite going through the documentation with thought multiple times I still can’t wrap my mind around the working logic of all the different items, things, rules and so on, especially as the Serial binding doesn’t support the Paper UI for configuration. If I could just get a complete working set of these files for a single device, I could most probably figure out the logic and the syntax.

Could someone give me an example of the files and configs needed to make buttons in HABPanel for the following scenario:

HDMI switcher with 4 inputs connected to PC’s COM6@19200. The switching command is

sw i01[enter]

and the number after the ‘i’ is changed to 02, 03, and 04 respectively for each button. The enter is important, I have tried this with other programs and the line break is needed for the command to go through.

Thank you in advance! :slight_smile:

You need to install the serial binding first
Then follow the serial binding docs to edit the serial.cfg that will be located in your configuration folder under services

Create an item in an item file (again in your conf folder under items) name it whatever.items
Follow the serial binding docs for the syntax of the binding
the string you want to send is: sw i01/n

In habpanel create button linked to that item for the command you put in the item binding

Have a go.
If it doesn’t work come back and show what you have done, we’ll point you is the right direction

Hi

I have serial binding installed. I created an .items file with

String HDMIswitch "Source selection" {serial="COM6@19200"}

After that I made a button in HABPanel connected to the new item with a command value

sw i01/n

And absolutely nothing happens. From your message I understood that the string to be sent (sw i01) should be included in the .items file, but nothing in the binding documentation states that. I have no idea what is going wrong.

Try adding a space after { and before} in the item definition
I made a mistake
The string to send should be:
SW i01\n
But also try \r or even \n\r

Still no luck. OpenHAB seems to notice the USB-serial port though, as the console gives me a warning when I launch OpenHAB with a Putty session open to the same port (the switch works perfectly on it). I tried all the possible variations with \r and \n.

I have a PC with a COM port on the motherboard. Maybe I should find the right cable and monitor OpenHAB’s output on that PC.

Does anybody have more ideas on what could be wrong with my setup?

More interesting stuff happening:

I once again tried sending the commands in HABPanel. I have four buttons that each have a different version of the “sw i01” -command. As expected, nothing happened on the switch.

I then halted OpenHAB and launched Putty, opened a session to the COM port and wrote “sw i03”. When I hit enter, the switch returned this:

swi01\n\rswi01\rswi01\rswi01\nswi01\nsw i03  Command incorrect

WHAT? All the commands I tried clicking in HABPanel were stored somewhere but not sent before I opened the Putty session and tried sending something. Has this something to do with eg. flow control? Seems like OpenHAB knows that the COM port exists and sends stuff to it, but the commands are not sent forward from there.

It looks like the binding is not sending the escaped characters \n and \r
Have you tried to change the character set and indicated in the serial binding docs.

The solution is there:

There is an updated binding in the SNAPSHOT release that should work OR you can change the CHARSET as indicated in the thread.

You can update to snapshot or wait a bit for OH 2.3 stable which is not too far away I understand.

Thanks for all the great help so far!

I installed the snapshot and made ‘some’ progress. Now when I push the buttons and go back to Putty, I get

▒s▒s▒s▒ssw i03  Command incorrect

There is something going on with the charset, but no idea what. My .items looks like this:

String	HDMIswitch	"Source selection" { serial="COM6@19200,CHARSET(ISO-8859-1)" }

How exactly are you sending the commands? Can you post the rule that sends the command? And could you maybe try the BASE64 method and send all commands base64 encoded? That is what worked best for me.

I am sending the commands in HABPanel. There is no rule involved, because the command is sent directly from a button that points to the item stated above. I tried base64 as well and it did not help.

Is it possible to log the feedback coming back from the RS232 line? The device should echo either “Command ok” or “Command incorrect” when it receives a string, and logging this somewhere could be helpful. I tried to see the help file for logging, but didn’t get much out of it.

If the Karaf console
https://www.openhab.org/docs/administration/console.html

Set the logging of the serial binding to DEBUG:

https://www.openhab.org/docs/administration/logging.html#defining-what-to-log

Thanks!

When displaying the log, I see this:

11:22:24.095 [ERROR] [org.openhab.binding.serial           ] - FrameworkEvent ER
ROR - org.openhab.binding.serial
org.osgi.framework.BundleException: Could not resolve module: org.openhab.bindin
g.serial [202]
  Unresolved requirement: Import-Package: org.apache.commons.codec.binary

        at org.eclipse.osgi.container.Module.start(Module.java:444) [?:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incSta
rtLevel(ModuleContainer.java:1620) [?:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incSta
rtLevel(ModuleContainer.java:1599) [?:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doCont
ainerStartLevel(ModuleContainer.java:1571) [?:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispat
chEvent(ModuleContainer.java:1514) [?:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispat
chEvent(ModuleContainer.java:1) [?:?]
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventM
anager.java:230) [?:?]
        at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(Even
tManager.java:340) [?:?]

I’m 100% certain that the problem is me doing something terribly stupid. Please bear with me, I’m all new to OpenHAB and home automation in general.

Unresolved requirement: Import-Package: org.apache.commons.codec.binary

That’s the problem for that error.
I don’t know how to solve that yet. Sorry
I don’t know windows either… :frowning_face:

It seams that the commons.codec package was not installed on your system. On my system the jar file is in this directory: /usr/share/openhab2/runtime/system/commons-codec/commons-codec/1.6

I can also see this in the karaf console when entering bundles:list
197 │ Active │ 80 │ 1.6.0 │ Commons Codec

But I didn’t find out which command does install this package. This one didn’t work:
bundle:install org.apache.commons.codec

Does anyone know how to install this package in the karaf console?

I updated to 2.3.0 stable, but apparently the new binding is not implemented in it. At least when I include CHARSET(ISO-8859-1) in the item, log displays that it is not recognized.

I installed 2.4.0 snapshot and the same thing happens. Then I tried to install the serial binding snapshot on 2.4.0 and get this

14:40:49.296 [WARN ] [org.apache.felix.fileinstall         ] - Error while start
ing bundle: file:/C:/openhab/addons/org.openhab.binding.serial-1.12.0-SNAPSHOT.j
ar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.bindin
g.serial [208]
  Unresolved requirement: Import-Package: gnu.io

        at org.eclipse.osgi.container.Module.start(Module.java:444) [?:?]
        at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle
.java:383) [?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(Di
rectoryWatcher.java:1260) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(D
irectoryWatcher.java:1233) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundle
s(DirectoryWatcher.java:1221) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(Dire
ctoryWatcher.java:515) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(Direct
oryWatcher.java:365) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryW
atcher.java:316) [9:org.apache.felix.fileinstall:3.6.4]
14:40:50.058 [WARN ] [org.apache.felix.fileinstall         ] - Error while start
ing bundle: file:/C:/openhab/addons/org.openhab.binding.serial-1.12.0-SNAPSHOT.j
ar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.bindin
g.serial [208]
  Unresolved requirement: Import-Package: gnu.io

        at org.eclipse.osgi.container.Module.start(Module.java:444) [?:?]
        at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle
.java:383) [?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(Di
rectoryWatcher.java:1260) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(D
irectoryWatcher.java:1233) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(Dire
ctoryWatcher.java:520) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(Direct
oryWatcher.java:365) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryW
atcher.java:316) [9:org.apache.felix.fileinstall:3.6.4]

Once I remove the snapshot jar and try to install the serial binding from Paper UI again, I keep getting the same errors.

I can find the commons.codec package in the directory stated by @TheNetStriker.

I haven’t yet merged my code changes into the official repository. You can download the modified plugin here.

The error regarding gnu.io can be resolved my executing this line in karaf:
feature:install openhab-transport-serial

How is this even possible? I simply can not make anything work. Others seem to have been able to use serial ports just fine, but every time I fix something, a new thing gets broken. I ran feature:install openhab-transport-serial, which fixed the error with the gnu.io package, but after that I get new errors:

Launching the openHAB runtime...

                          __  _____    ____
  ____  ____  ___  ____  / / / /   |  / __ )
 / __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __  |
/ /_/ / /_/ /  __/ / / / __  / ___ |/ /_/ /
\____/ .___/\___/_/ /_/_/ /_/_/  |_/_____/
    /_/                        2.3.0
                               Release Build

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown openHAB.

openhab> log:tail
11:39:08.640 [ERROR] [org.openhab.binding.serial           ] - FrameworkEvent ER
ROR - org.openhab.binding.serial
org.osgi.framework.BundleException: Could not resolve module: org.openhab.bindin
g.serial [189]
  Unresolved requirement: Import-Package: org.apache.commons.codec.binary

        at org.eclipse.osgi.container.Module.start(Module.java:444) [?:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incSta
rtLevel(ModuleContainer.java:1634) [?:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incSta
rtLevel(ModuleContainer.java:1613) [?:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doCont
ainerStartLevel(ModuleContainer.java:1585) [?:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispat
chEvent(ModuleContainer.java:1528) [?:?]
        at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispat
chEvent(ModuleContainer.java:1) [?:?]
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventM
anager.java:230) [?:?]
        at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(Even
tManager.java:340) [?:?]
11:39:08.916 [INFO ] [der.internal.HomeBuilderDashboardTile] - Started Home Buil
der at /homebuilder
11:39:08.996 [INFO ] [e.core.internal.i18n.I18nProviderImpl] - Location set to '
CENSORED'.
11:39:10.064 [INFO ] [i.dashboard.internal.DashboardService] - Started Dashboard
 at http://192.168.111.46:8080
11:39:10.065 [INFO ] [i.dashboard.internal.DashboardService] - Started Dashboard
 at https://192.168.111.46:8443
11:39:12.376 [INFO ] [del.core.internal.ModelRepositoryImpl] - Loading model 'se
rial.items'
11:39:13.193 [INFO ] [rthome.model.lsp.internal.ModelServer] - Started Language
Server Protocol (LSP) service on port 5007
11:39:13.749 [INFO ] [.basic.internal.servlet.WebAppServlet] - Started Basic UI
at /basicui/app
11:39:13.928 [INFO ] [marthome.ui.paper.internal.PaperUIApp] - Started Paper UI
at /paperui
11:39:13.946 [INFO ] [bpanel.internal.HABPanelDashboardTile] - Started HABPanel
at /habpanel
11:39:13.958 [INFO ] [xsysfs.internal.SysfsUsbSerialScanner] - Cannot perform sc
ans with this configuration: sysfsTtyDevicesDirectory: /sys/class/tty, devDirect
ory: /dev
11:39:13.963 [INFO ] [xsysfs.internal.SysfsUsbSerialScanner] - Cannot perform sc
ans with this configuration: sysfsTtyDevicesDirectory: /sys/class/tty, devDirect
ory: /dev
11:39:13.966 [INFO ] [ysfs.internal.PollingUsbSerialScanner] - Do not start back
ground scanning, as the configured USB-Serial scanner cannot perform scans on th
is system
11:39:13.968 [INFO ] [ysfs.internal.PollingUsbSerialScanner] - Do not start back
ground scanning, as the configured USB-Serial scanner cannot perform scans on th
is system
11:39:17.749 [WARN ] [org.apache.felix.fileinstall         ] - Error while start
ing bundle: file:/C:/openhab/addons/org.openhab.binding.serial-1.12.0-SNAPSHOT.j
ar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.bindin
g.serial [189]
  Unresolved requirement: Import-Package: org.apache.commons.codec.binary

        at org.eclipse.osgi.container.Module.start(Module.java:444) [?:?]
        at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle
.java:383) [?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(Di
rectoryWatcher.java:1260) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(D
irectoryWatcher.java:1233) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundle
s(DirectoryWatcher.java:1221) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(Dire
ctoryWatcher.java:515) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(Direct
oryWatcher.java:365) [9:org.apache.felix.fileinstall:3.6.4]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryW
atcher.java:316) [9:org.apache.felix.fileinstall:3.6.4]

I’m starting to doubt if OpenHAB is my thing at all.

I am curious did you get this to work?

Hello, I’m trying to use the serial1 bind to control a HDMI switch that uses the serial port to process commands. I’m using HabPanel as a UI to send commands to the HDMI matrix. I created an items file with this line in it:
String HDMIswitch “Input-Source” { serial=“COM1@115200” }
I tested sending commands with a terminal prog and the commands work
i.e. @T 00 01 # sets output port 0 to input port 1.
I get this error when I try to do a command on habPanel.
2019-07-13 14:43:28.322 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type ‘serial’ of item ‘HDMIswitch’ could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: Could not open serial port COM1: gnu.io.PortInUseException: Unknown Application
at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:55) ~[?:?]
at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:397) [129:org.eclipse.smarthome.model.item:0.11.0.oh250M1]
at org.eclipse.smarthome.model.item.internal.GenericItemProvider.dispatchBindingsPerType(GenericItemProvider.java:350) [129:org.eclipse.smarthome.model.item:0.11.0.oh250M1]
at org.eclipse.smarthome.model.item.internal.GenericItemProvider.addBindingConfigReader(GenericItemProvider.java:164) [129:org.eclipse.smarthome.model.item:0.11.0.oh250M1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
at org.apache.felix.scr.impl.inject.methods.BaseMethod.invokeMethod(BaseMethod.java:228) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.inject.methods.BaseMethod.access$500(BaseMethod.java:41) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.inject.methods.BaseMethod$Resolved.invoke(BaseMethod.java:664) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.inject.methods.BaseMethod.invoke(BaseMethod.java:510) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.inject.methods.BindMethod.invoke(BindMethod.java:42) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.manager.DependencyManager.doInvokeBindMethod(DependencyManager.java:1813) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.manager.DependencyManager.invokeBindMethod(DependencyManager.java:1788) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.manager.SingleComponentManager.invokeBindMethod(SingleComponentManager.java:436) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.manager.DependencyManager$MultipleDynamicCustomizer.addedService(DependencyManager.java:333) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.manager.DependencyManager$MultipleDynamicCustomizer.addedService(DependencyManager.java:302) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1216) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1137) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.trackAdding(ServiceTracker.java:944) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.track(ServiceTracker.java:880) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:1168) [39:org.apache.felix.scr:2.1.14]
at org.apache.felix.scr.impl.BundleComponentActivator$ListenerInfo.serviceChanged(BundleComponentActivator.java:125) [39:org.apache.felix.scr:2.1.14]
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109) [?:?]
at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920) [?:?]
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) [?:?]
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) [?:?]
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862) [?:?]
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801) [?:?]
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127) [?:?]
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225) [?:?]
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469) [?:?]
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:487) [?:?]
at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:1004) [?:?]
at org.openhab.core.binding.internal.BindingConfigReaderFactory.registerDelegateService(BindingConfigReaderFactory.java:84) [222:org.openhab.core.compat1x:2.5.0.M1]
at org.openhab.core.binding.internal.BindingConfigReaderFactory.activate(BindingConfigReaderFactory.java:50) [222:org.openhab.core.compat1x:2.5.0.M1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]

Has your other terminal prog still got hold of the port?