Serial Binding and sending hex Codes.

2,114 views
Skip to first unread message

lord....@gmail.com

unread,
Dec 29, 2013, 8:39:24 PM12/29/13
to ope...@googlegroups.com
I am very new to OpenHAB so please let me know if I am way off track.

I have a HDMI Matrix switch that can be controlled via RS232. I have a usb to RS232 adapter plugged into the OpenHAB server.

I have my item configured as:

String HDMI_Matrix        "HDMI Matrix"        (All)    { serial="/dev/ttyUSB0" }

Sitemap:

Switch item=UP_GR_TV mappings=[1='BluRay', 2='Dune', 3='Wii']

And the rule that sends the hex command configured as:

rule "Great Room TV Source"
    when
        Item UP_GR_TV received command
    then
        switch(receivedCommand) {
            case 1 : sendCommand(HDMI_Matrix, "0x00,0xff,0xd5,0x7b")
            case 2 : sendCommand(HDMI_Matrix, "0x010xfe0xd50x7b")
            case 3 : sendCommand(HDMI_Matrix, "\x02\xfd\xd5\x7b")
        }
end


And the logs:

18:08:28.082 INFO  runtime.busevents[:42] - UP_GR_TV received command 1
18:08:28.180 INFO  runtime.busevents[:42] - HDMI_Matrix received command \x00\xff\xd5\x7b

18:26:47.603 INFO  runtime.busevents[:42] - UP_GR_TV received command 2
18:26:47.663 INFO  runtime.busevents[:42] - HDMI_Matrix received command 0x010xfe0xd50x7b


As you can see  I have tried several methods of sending the string to the serial binding. The problem is the switch is not changing like it should.

I have also tried running a executeCommandLine("echo -ne \ '\\x05\\xfa\\xd5\\x7b\' > /dev/ttyUSB0")

And the logs:

17:07:48.749 INFO  runtime.busevents[:42] - UP_GR_TV received command 2
17:07:48.773 INFO  o.openhab.io.net.exec.ExecUtil[:87] - executed commandLine 'echo -ne '\x05\xfa\xd5\x7b' > /dev/ttyUSB0'


Neither of these options are working.

Is there something I am missing or doing wrong? Is there a better way of doing this?

Thanks.

Daren


Karel Goderis

unread,
Dec 30, 2013, 4:24:08 AM12/30/13
to ope...@googlegroups.com
Daren

Which Matrix is it? I have an HDAnywhere installed that can be controlled through RS232 or TCP/IP. I hope to crank out a specific binding for that box shortly, and that could be a template for you to build a binding for your matrix. The HDAnywhere also works by sending out a series of HEX codes, e.g. one code for each Source/Destination combination. Since HDAnywhere does only provide the raw codes, there is no way to know how these are build, and therefore my binding would be very dumb one that sends out the raw codes. If your matrix is very similar to mine, I could try to generalize the binding.

Karel

--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/groups/opt_out.

Daren Lord

unread,
Dec 30, 2013, 11:31:23 AM12/30/13
to ope...@googlegroups.com
I am starting out with the Monoprice 4x4 Matrix. And it needs to have the raw codes as well. Unfortunately it does not support TCP/IP. A generic binding would be great.  Let me know how I can contribute.

Daren

Pauli Anttila

unread,
Dec 30, 2013, 11:59:58 AM12/30/13
to ope...@googlegroups.com
Strings in Java are encoded in UTF-16, so you should use unicode escape sequence '\uDDDD', where DDDD is in hex format. E.g. "\u0002\u00fd\u00d5\u007b".

Pali

Daren Lord

unread,
Dec 30, 2013, 12:25:33 PM12/30/13
to ope...@googlegroups.com
Thank you for the suggestion. I tried that but it did not work. It looks like it is sending the hex codes though. Maybe my approach is wrong.

I need to send the following bytes over a 9600 baud 8 bit parity. I was using hex codes because that was what I got working on the command line.
Here are the bytes I should be sending, according to the docs:

0x00,0xff,0xd5,0x7b

Am I going about this the right way?

Pauli Anttila

unread,
Dec 30, 2013, 1:49:45 PM12/30/13
to ope...@googlegroups.com
Am I going about this the right way?
I think you item config and rule should be ok if you use unicode escape sequence. Serial binding configure serial port to 9600,8,1,N, but does not set flow control. If I'm right, default is no flow control. Does you HDMI matrix need flow control?

Have you tried to run openhab in debug logging on, then you should see more info on the log.

Pali


2013/12/30 Daren Lord <lord....@gmail.com>
--

Daren Lord

unread,
Dec 30, 2013, 4:39:24 PM12/30/13
to ope...@googlegroups.com
I don't believe it needs flow control The only thing I see in the docs are:

Baud=9600. Data size=8. Parity=None. Handshake=Off. Mode=Free.

Between each byte there is supposed to be a 50ms delay. Also, is there a way to read the bytes from the serial port?

Thanks for the help.

Daren Lord

unread,
Dec 30, 2013, 10:36:32 PM12/30/13
to ope...@googlegroups.com
I have put OpenHAB into debug and it looks like everything is getting sent over correctly:

20:32:58.492 DEBUG o.o.i.r.i.r.ItemResource[:216] - Received HTTP POST request at 'items/UP_GR_TV' with value '1'.
20:32:58.497 DEBUG o.o.m.r.i.engine.RuleEngine[:305] - Executing rule 'Great Room TV Source'
20:32:58.499 INFO  runtime.busevents[:42] - UP_GR_TV received command 1
20:32:58.556 DEBUG o.o.b.s.internal.SerialDevice[:236] - Writing 'ÿÕ{' to serial port /dev/ttyUSB0
20:32:58.562 INFO  runtime.busevents[:42] - HDMI_Matrix received command ÿÕ{


The Rule:

case 1 : sendCommand(HDMI_Matrix, '\u0000\u00ff\u00d5\u007b')
case 2 : sendCommand(HDMI_Matrix, '\u0001\u00fe\u00d5\u007b')



But it is still not working. Again if I try these commands from the command line they work perfectly. Is there any delay in between each hex character that is sent? Is there a way to create a delay?
Any other thoughts?

Thanks,

Daren

Falk Sauer

unread,
Dec 31, 2013, 2:09:47 AM12/31/13
to Unname

Hi Daren,

You can split your rule to send each byte with a sleep timer between. Pls look into rule wiki for the correct syntax. A check of your send string is possible with an serial to  usb adaptor and a terminal program and a cross cable between.

Regards
  Falk

Karel Goderis

unread,
Dec 31, 2013, 2:53:47 AM12/31/13
to ope...@googlegroups.com
Daren

You send 4 Unicode chars but only 3 are in the string in the logs?

K

Sent from my iPhone

Pauli Anttila

unread,
Dec 31, 2013, 7:49:15 AM12/31/13
to ope...@googlegroups.com
You send 4 Unicode chars but only 3 are in the string in the logs?
First byte is a null character ('\u0000\u00ff\u00d5\u007b'), so it's probably not printed.


Between each byte there is supposed to be a 50ms delay
50ms delay between bytes sounds really weird to me, it makes it really hard to control. If you can control device from command line without any delay it should work without delay from OH as well. I could believe that 50ms delay should be between two frames not bytes.

I quickly googled your device and doc


specifies '9600,n,8,1,DTR=true'. So HW flow control should be enabled (DTR should be on).

If you can't get serial binding to work, easiest way is to introduce a shell script where you configure serial port and send bytes directly to the device. Then call script by exec binding. Commands should also work directly from exec binding, but you most probably should use @@ trick (see more details form exec binding wiki page).

Pali




2013/12/31 Karel Goderis <karel....@me.com>

Karel Goderis

unread,
Dec 31, 2013, 8:09:17 AM12/31/13
to ope...@googlegroups.com


On 31 Dec 2013, at 13:49, Pauli Anttila <pauli....@gmail.com> wrote:

You send 4 Unicode chars but only 3 are in the string in the logs?
First byte is a null character ('\u0000\u00ff\u00d5\u007b'), so it's probably not printed.



What default charset is used on the host running OH? Somewhere in the source there this: 


outputStream.write(msg.getBytes());

, whereby getBytes() does this:

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array. The behavior of this method when this string cannot be encoded in the default charset is unspecified. The CharsetEncoder class should be used when more control over the encoding process is required.

Just my 2 cents,
K

Daren Lord

unread,
Dec 31, 2013, 11:23:26 AM12/31/13
to ope...@googlegroups.com

On 31 Dec 2013, at 13:49, Pauli Anttila <pauli....@gmail.com> wrote:

What default charset is used on the host running OH? Somewhere in the source there this: 


This should be my default charset:

LANG=en_US.UTF-8

Should I be changing it to something else?

Daren Lord

unread,
Jan 1, 2014, 6:54:06 PM1/1/14
to ope...@googlegroups.com
I created a script and am using the exec binding succesfully. Thanks for the help.

Daren

Kevin Rasmussen

unread,
Jan 8, 2014, 8:13:21 AM1/8/14
to ope...@googlegroups.com
Hi Karel.

As mentioned elsewhere on this forum I to has an HDAnywhere matrix so a specifik binding for that would be nice.
However while I had a hard time getting the UDP control to work proppperly I had great success with reverse engeneering the web interface on the HDAnywhere box (The web based remote control).
It is a simple GET command so it actually just is an URL...Works surprisingly well! And you do not need to be authenticated (loggedin) to have it working.
When I gets home I will try to sent you an example of my code (I do it in rules even though a HTTP binding would b more than enough). The best thing is that with the HTTP approach you actually has a chance to be able to determine the live state of the switch even though there is no two-way integration opportunity. Just reverse engeneer the web based remote control which constantly updates the page to be able to determine the running state. With the UDP approach there is no way to tell the matrix where to return a value.

Karel Goderis

unread,
Jan 8, 2014, 10:56:39 AM1/8/14
to ope...@googlegroups.com
Hi Kevin

That's interesting, because the fact that there is no hexcommand to read out the state of the device was also bothering me big time. I asked the question to HDAnywhere, but never got a reply. Which version do you have? I have a 4x4 PoE V3. Can you also include your .sitemap? Just wondering how you integrate that in the UI. I am also curious to see what style of Item definitions you use, e.g how to do that in a binding, e.g. 1 Item per output port, and then send it Numbers corresponding to the source ports?

Maybe the cleanest thing to do is to extend the existing http binding with your work? Might maybe result in clean Rules, and we could incorporate polling frequencies and that sort of stuff

Regards
K

Kevin Rasmussen

unread,
Jan 9, 2014, 4:34:26 AM1/9/14
to ope...@googlegroups.com
Hi Karel.
 
Actually I have no really need of reading out the current state of the switch. At least not yet.
OH is the only way I controls the switch at the moment so there will never be a state that OH does not know about.
What I do at startup via my rules is that I forces the Switch to show the input 1 to all outputs anyway. But for a better control opportunity it would be nice to have a "read state" ability.
 
I very much would recommend a http based binding. However the http approach is not oficially supported by HDAnywhere so we have no guarantees that a firmware update will change the way that the built-in web service handles input (the GET commands).
But the fact that it is so easy and works so well and that it is only the switching mechanism you can control via http GET tells me that we might not have to be so worried after all and while the UDP approach (and even the RS232 approach - according to the documemntation du to total lack of any mentioning or codes for this!) does not support any outbound notification possibilitis leaves the HTTP approch as a clear winner in my book.
 
I have attached my setup.
 
I have done it all in a rules file so it should be in the main.rules you can see what I do.
Because it is unsupported you has to do a little reverse engeneering yourself to clarify the precise I/O matching URL from your own Switch. I used google chrome with the developer console activited where I clicked the buttons in the web interface and then just copied the URLs from the "network" tab.
 
/Kevin


2014/1/8 Karel Goderis <karel....@me.com>

--
You received this message because you are subscribed to a topic in the Google Groups "openhab" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openhab/QXEDY3DbJSA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openhab+u...@googlegroups.com.
Openhab Conf.zip

Kevin Rasmussen

unread,
Jan 14, 2014, 7:27:52 AM1/14/14
to ope...@googlegroups.com
Please notice that the attached file is a working progress file and hence full of errors. However the MATRIX part of the files is working fine.
I was changing some other features in the configuration and was not done yet.

Den torsdag den 9. januar 2014 10.34.26 UTC+1 skrev Kevin Rasmussen:
Hi Karel.
 
Actually I have no really need of reading out the current state of the switch. At least not yet.
OH is the only way I controls the switch at the moment so there will never be a state that OH does not know about.
What I do at startup via my rules is that I forces the Switch to show the input 1 to all outputs anyway. But for a better control opportunity it would be nice to have a "read state" ability.
 
I very much would recommend a http based binding. However the http approach is not oficially supported by HDAnywhere so we have no guarantees that a firmware update will change the way that the built-in web service handles input (the GET commands).
But the fact that it is so easy and works so well and that it is only the switching mechanism you can control via http GET tells me that we might not have to be so worried after all and while the UDP approach (and even the RS232 approach - according to the documemntation du to total lack of any mentioning or codes for this!) does not support any outbound notification possibilitis leaves the HTTP approch as a clear winner in my book.
 
I have attached my setup.
 
I have done it all in a rules file so it should be in the main.rules you can see what I do.
Because it is unsupported you has to do a little reverse engeneering yourself to clarify the precise I/O matching URL from your own Switch. I used google chrome with the developer console activited where I clicked the buttons in the web interface and then just copied the URLs from the "network" tab.
 
/Kevin


2014/1/8 Karel Goderis <blank>
Hi Kevin

That's interesting, because the fact that there is no hexcommand to read out the state of the device was also bothering me big time. I asked the question to HDAnywhere, but never got a reply. Which version do you have? I have a 4x4 PoE V3. Can you also include your .sitemap? Just wondering how you integrate that in the UI. I am also curious to see what style of Item definitions you use, e.g how to do that in a binding, e.g. 1 Item per output port, and then send it Numbers corresponding to the source ports?

Maybe the cleanest thing to do is to extend the existing http binding with your work? Might maybe result in clean Rules, and we could incorporate polling frequencies and that sort of stuff

Regards
K


On 08 Jan 2014, at 14:13, Kevin Rasmussen <blank> wrote:

Hi Karel.

As mentioned elsewhere on this forum I to has an HDAnywhere matrix so a specifik binding for that would be nice.
However while I had a hard time getting the UDP control to work proppperly I had great success with reverse engeneering the web interface on the HDAnywhere box (The web based remote control).
It is a simple GET command so it actually just is an URL...Works surprisingly well! And you do not need to be authenticated (loggedin) to have it working.
When I gets home I will try to sent you an example of my code (I do it in rules even though a HTTP binding would b more than enough). The best thing is that with the HTTP approach you actually has a chance to be able to determine the live state of the switch even though there is no two-way integration opportunity. Just reverse engeneer the web based remote control which constantly updates the page to be able to determine the running state. With the UDP approach there is no way to tell the matrix where to return a value.

To unsubscribe from this group and stop receiving emails from it, send an email to openhab+unsubscribe@googlegroups.com.

To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to a topic in the Google Groups "openhab" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openhab/QXEDY3DbJSA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openhab+unsubscribe@googlegroups.com.

franz.em...@gmail.com

unread,
Apr 26, 2014, 5:28:38 AM4/26/14
to ope...@googlegroups.com
Hi Daren,
I'm having similar problems. Could you post your script?
Thanks, Franz

lewi...@gmail.com

unread,
Nov 15, 2014, 12:08:35 PM11/15/14
to ope...@googlegroups.com
I am having similar problems with a HDanywhere matrix that only has serial connection, openHAB seems to be sending the commands but the matrix is not responding at all...

Here is the rule, I am trying to send the command in a few different ways but all with no success:



rule "TV1"
    when
        Item TV1 received command
    then
        switch(receivedCommand) {
            case 1 : sendCommand(HDMI_Matrix, "\u00ba\u00ba\u00bf\u00c6\u0005\u0003\u0000\u00b0")
            case 2 : sendCommand(HDMI_Matrix, "BABABFC6050300B0")
            case 3 : sendCommand(HDMI_Matrix, "BA BA BF C6 05 03 00 B0")
        }
end


Here is the output from openHAB:


17:05:10.532 INFO  runtime.busevents[:22] - TV1 received command 1
17:05:10.563 INFO  runtime.busevents[:22] - HDMI_Matrix received command ║║┐ã♣♥░
17:05:11.345 INFO  runtime.busevents[:22] - TV1 received command 2
17:05:11.376 INFO  runtime.busevents[:22] - HDMI_Matrix received command BABABFC6050300B0
17:05:12.595 INFO  runtime.busevents[:22] - TV1 received command 3
17:05:12.610 INFO  runtime.busevents[:22] - HDMI_Matrix received command BA BA BF C6 05 03 00 B0



Does anyone have any ideas or a working example of sending serial codes to a matrix?
Reply all
Reply to author
Forward
0 new messages