Newbie Basic RS232 Plugin

If you can’t get the Pi to work, you could consider these alternatives:

An Ethernet to RS232 interface. The low-cost option is a module like this one.

A WiFi to RS232 interface. My favourite is the USR module and the simple solution is an evaluation board like this. I used one of these for a project and it works really well. Easy configuration using the built-in web server.

Many thanks to you all for helping me with this.

I can see there’s still lots to look at and to try out.

Regarding connectivity I was seeing the following reported back to me when I tried to send commands directly via telnet session. Since I updated the ser2net.conf I seem to have lost it again.

**Invalid Input. Refer to Install Guide or FAQ (www.octavainc.com)for serial control protocol.

To try and get the Pi to talk directly to the HDMI Matrix switcher, I’ve tried the following

For info, to ensure I had configure the required speed/setting for the USB to RS232 cable - I did this

stty -F /dev/ttyUSB0 9600 cs8 -parenb

Then to select Input port 3 which is = 0x02 0x32 0x31 0x33 0x03 - I did this at the command line

echo -e -n '\x02\x32\x31\x33\x03' > /dev/ttyUSB0

But sadly that did not work either.

It is beginning to look like you have a dud serial adapter, a dud Raspberry Pi or a dud serial port on your switcher.

Rule out the Pi by connecting the serial adapter to a real computer and running the same (or comparable) commands.

Go back and read what I said about the amount of power that serial adapters need. Try a powered hub, one that can supply at least 500 mA to each port.

Rule out the Pi by connecting the serial adapter to a real computer and running the same (or comparable) commands.

There are lots of free programs that can send hex commands through a USB/Serial adaptor. A simple example is Termite.

Do you have any real computers, Chris?

Hi @futzle

[quote=“futzle, post:24, topic:169704”]It is beginning to look like you have a dud serial adapter, a dud Raspberry Pi or a dud serial port on your switcher.

Rule out the Pi by connecting the serial adapter to a real computer and running the same (or comparable) commands.

Go back and read what I said about the amount of power that serial adapters need. Try a powered hub, one that can supply at least 500 mA to each port.[/quote]

Its very strange, as I was getting the following responses in the terminal window before (via telnet) which was suggesting that some communication was occurring.

However - I think you’re right, there’s no point flogging this proverbial dead horse anymore…


Hi @Rex

LOL ;D

My work PC is locked down tighter than a mermaids - well you know. So it won’t allow anything to be installed or connected to the USB. I do have an old laptop which has XP on I think - so I’ll dig that out again…

I do have an old laptop which has XP on I think - so I'll dig that out again..

You don’t need much to support a USB/Serial adapter and run a simple terminal-emulator program. XP should be fine.

Its very strange, as I was getting the following responses in the terminal window before (via telnet) which was suggesting that some communication was occurring.[/quote]

Once in my early home automation days I had a USB-to-serial adapter connected to a Linksys NSLU2. It was recognized by the NSLU2 and appeared as a serial port in /dev and I could send it bytes using a terminal program. But nothing ever came out the RS232 end. (Edit: or, if it did, only the first byte or two, after which the adapter gave up from the effort.)

USB serial adapters have two pieces of circuitry inside them: a UART for talking to the USB end, and a level-converter for talking to the DB9 end. It’s possible for the UART to happily communicate with the computer and be totally unaware that the data is not actually going out the RS232 port. It’s impossible to debug this from the computer end because from the perspective of the computer everything is working fine.

This would be exactly what you’re seeing with your Raspberry Pi.

I inserted a four-port powered USB hub in between and everything magically came good.

The reason why USB-to-RS232 adapters need decent power is that they have to convert 0V/5V USB into -12V/+12V RS-232 signals. Inverting voltage typically requires a good supply of current. My NSLU2 simply couldn’t supply it. Raspberry Pis are renowned for having iffy USB current.

parkerc, you haven’t got anything between the USB-to-serial adapter and the HDMI switcher, have you? Like, a cable or a gender changer or something?

lol no cable inbetween wouldn’t work to good ;D
good point about the power… could also be that it uses straight cable instead of null-modem cable. or vera doesn’t accept hex but only ascii or binary ?
maybe the rs-232 usb device is not supported ?

Hi All

Just to confirm the original set up …

i) I was not using a powered USB hub
ii) I was using a (gender change cable 1.5m long) to help connect the Pi’s USB to serial cable → to the HDMi matrix.

I’ve now taken the USB cable out and put it into a PC (@Rex get me !! I’m using a PC !!) and I’m now running a serial program called Hercules (www.HW-group.com)

At first it did not work at all, but after I recycled the power on the Matrix it started to work !! - allowing me to use commands like this

0230303303

So the USB serial cable works, the extension (gender change) cable works and the matrix works (although it must need to be recycled at times as it seems like it can lock up and not accept commands)

@Rex get me !! I'm using a PC !!

Be careful, Chris. Are you sure you can handle that much flexibility and openness? ;D

So the USB serial cable works, the extension cable works and the matrix work.

That’s a good leap forward. Now you need to figure-out why it didn’t work on the Pi. Did you follow-up on @futzle’s suggestion to try a powered-hub? Try it on the PC first so that you know it doesn’t introduce other problems.

[quote=“RexBeckett, post:32, topic:169704”]

@Rex get me !! I’m using a PC !!

Be careful, Chris. Are you sure you can handle that much flexibility and openness? ;D

So the USB serial cable works, the extension cable works and the matrix work.

That’s a good leap forward. Now you need to figure-out why it didn’t work on the Pi. Did you follow-up on @futzle’s suggestion to try a powered-hub?[/quote]

:slight_smile: I have to admit - I do feel a little light headed on a PC, this is what it must feel like to live on the wild side !!

@futzle’s powered hub route is the next step - i’ll need to get one, but the good thing is that all the other components seem to work.

For future reference: this is important information. Such a cable is called a “null modem cable” and isn’t just a straight pin-1-to-pin1, pin-2-to-pin-2, … thing. Its wires cross over some pins so that the “transmit” pin at one end is connected to the “receive” pin of the other end. You have to perform this crossover once; otherwise each device can’t hear what the other end is sending. The little compact gender-changer adapters that you might’ve seen don’t do this crossover and so aren’t equivalent to the null modem cable that you have (correctly) used. A warning: it is, unfortunately, possible to buy cables that don’t have the crossover built into them. They should not exist, but they do.

Very pleased that the matrix switcher, cable and USB adapter are all good. It’s definitely implicating the Pi as the source of the problem.

Thanks @futzle - I’m learning a lot and with a 4 port powered hub just bought on eBay - roll on testing the PI with added USB power :slight_smile:

Based on what the Matrix was accepting via that Hercules programme - I have a good idea now what it’s looking for - so hopefully the code I’ve been using wil work now.

What’s also interesting is that the switch returns a confirmation string which might be helpful for a more dynamic plugin.

Thanks again for all the help I’m getting.

I like the way you think.

i like the way all people work together here to find a solution that works. the basic plugin could also be used as a guideline for a lot of other rs232 devices like amps,tv’s,switches,av-racks,plc’s etc.

Hi @Da_JoJo

It’s what makes this forum so great, and many (those specifically who have contributed to me on this thread) have the patients of a saint to deal with some of the things Ive asked :wink:

I looked at the SimpleSerial1.xml which is posted here and I must admit, I don’t understand it at all (and it has the word ‘simple’ in it’s name !!) - I have an idea of what I want to send to the Matrix, it would be great if I could get to work as a plugin…

Looking around, the pioneer amp plugin on this forum looks a good candidate for learning from as it seems to be set up with an RS232 connection in mind.

Right, in preparations for more tests with the Pi (Via a powered HuB) I’m scrolling through the forum to create a plugin. I’ll still need to test it with simple commands via LuaTest to see if it works - but my mind is wandering to the potential end state.

So I’ve started to look at creating a I_HDMIMatrix1.xml…

I’m assuming the protocol would be raw, compared to the others listed - but to quote the wiki - the explanation below does not sound too positive ?

raw - makes no modifications to outgoing data, and calls your incoming data callback for each byte received. This adds more overhead since the engine needs to call your Luup function for every character, and makes your code complex. So, generally avoid using ‘raw’ and let us add support for your protocol if you have a new one we don’t yet support.

<implementation> <settings> <protocol>raw</protocol> </settings>

Next is the mapping table for the commands

local ipAddress local mappingTable = { ["InputSelection1"] = { ["InputA1"] = "0232313103", -- Input A1 ["InputA2"] = "0232313203", -- Input A2 ["InputA3"] = "0232313303", -- Input A3 ["InputA4"] = "0232313403", -- Input A4 ["InputB1"] = "0232323103", -- Input B1 ["InputB2"] = "0232323203", -- Input B2 ["InputB3"] = "0232323303", -- Input B3 ["InputB4"] = "0232323403", -- Input B4 }, ["DiscretePower1"] = { ["Off"] = "0230303603", -- POWER OFF ["On"] = "0230303503", -- POWER ON }, ["MenuNavigation1"] = { ["LEDOn"] = "02303103303", -- LED ON ["LEDOff"] = "02303103403", -- LED OFF ["PortStatus"] = "02303103103", -- Port Status }, }

Then the start up.

function doStartup(lul_device)
            local PORT = 4001
            ipAddress = luup.devices[lul_device].ip

            if (ipAddress ~= "") then
                luup.log("Running HDMI Matrix via a RaspBerry Pi plugin on " .. ipAddress)
                luup.io.open(lul_device, ipAddress, PORT)
            else
                luup.log("Running Serial Attached to HDMI Matrix - THIS IS UNTESTED")
            end
        end[/code]

Then huge thanks to the Pioneer receiver plugin for helping me piece this. Sending the codes

[code]function sendCode(code)
            local CR = string.char(13)           
            -- Wake up the HDMI if it is in standby mode.                  
            luup.io.write(CR)

            -- Send the code to the TV
            if( false == luup.io.write(code .. CR)) then
                luup.log("io.write error in action: " .. " code:" .. code, 1)
                luup.set_failure(true)
                return false
            end
            return true
        end

function doAction(deviceType, actionName)
            local code = mappingTable[deviceType][actionName];
            
            -- Do we have a code?
            if( code ~= "") then
                sendCode(code)
            else
                luup.log("Unimplemented action: " .. deviceType .. "-" .. actionName, 1)
                luup.set_failure(true)
                return false
            end
            return true;            
        end

I’m not sure about this bit of code local CR = string.char(13) as the manual says it "Converts ASCII codes into their equivalent characters" but hopefully I’ll find more through testing the Luup.io.write commands for my switch

Next would be the Actions, one for each in the mapping table…

    <actionList>
       <action>
            <serviceId>urn:micasaverde-com:serviceId:InputSelection1</serviceId>
		    <name>Input1</name>
            <run>
                doAction("InputSelection1", "InputA1")
            </run>
        </action>
    </actionList>

im confused with this plugin making too… its way too complex for the normal coder and there is little to none usable docs on it :-/
to make things worse the new UI6/7 uses a new sort template system so it could be that ur buttons don’t show up there without the proper code.
did you ask mcv to make a protocol for this ?
im a very patient saint-like man but this stuff really gets on my nerves sometimes man.
this local CR thingy just sends a raw carriage return to the hdmi device to wake it up… not sure if this hdmi actually uses this to wake up but it could work.