Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Reading serial port and controlling TV

If you have a question or need help, this is the place to be.
Post Reply
perkos
Posts: 3
Joined: Wed Oct 29, 2008 11:09 am

Reading serial port and controlling TV

Post by perkos »

Hello

I am trying to get make a program that reads the serial port and depending on what it reads, it changes between channel 1 and 2. But I can not get the reading of the serial port to work. The "change channel" macros work, I use them in another version where I change the channel with timer and this works. This i what I have done:

Code: Select all

<EventGhost Name="Configuration Tree" Expanded="True" Version="1483" Guid="{A727B266-A0CD-4400-A4A0-13C7950C52B8}" Time="1225278614.25">
   <Autostart Name="Autostart" Expanded="True">
     <Plugin File="Serial" Identifier="Serial"> gAIoSwFNsARLA0sASwBLAIlYAgAAAFxycQBYBgAAAFNlcmlhbHEBdHECLg== </Plugin>
     <Plugin File="USB-UIRT" Identifier="USB_UIRT"> gAKJiImHcQAu </Plugin>
     <Action Name="Read Serial port"> EventGhost.PythonScript(u'Serial = eg.plugins.Serial\n\ntransponder = Serial.Read(None, 0.0) \nif transponder == "C042039004023004005006007008009010011012013014015":\n eg.TriggerEvent("Change to channel 2")\nif transponder == "C035028005003004005006007008009010011012013014015":\n eg.TriggerEvent("Change to channel 1")') </Action>
   </Autostart>
   <Macro Name="Aland -> Sweden" Expanded="True">
    <Event Name="Change to channel 2"/>
    <Action> USB_UIRT.TransmitIR(u'0000 0071 0000 0012 0061 0020 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0021 0020 0011 0010 0021 0011 0010 0011 0010 0020 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0021 0020 0010 0BE1', 1, 0) </Action>
   </Macro>
   <Macro Name="Sweden -> Aland" Expanded="True">
     <Event Name="Change to channel 1"/>
     <Action> USB_UIRT.TransmitIR(u'0000 0071 0000 0013 0061 0021 0010 0020 0010 0011 0010 0011 0010 0020 0020 0010 0011 0010 0021 0021 0011 0010 0021 0011 0011 0010 0010 0021 0010 0010 0010 0010 0010 0010 0011 0010 0010 0010 0010 0011 0021 0BE3', 1, 0) </Action>
 </Macro>
 </EventGhost>
I have done the serial port reading with a Python script. Maybe ther is some smarter way to do this. Help needed, thanks.

Regards perkos
perkos
Posts: 3
Joined: Wed Oct 29, 2008 11:09 am

Re: Reading serial port and controlling TV

Post by perkos »

Now I have got a working version:

Code: Select all

<EventGhost Name="Configuration Tree" Expanded="True" Version="1483" Guid="{8C442C2B-D8BB-4861-BAD0-C2067E09B594}" Time="1225386201.47">
<Autostart Name="Autostart" Expanded="True">
 <Plugin File="USB-UIRT" Identifier="USB_UIRT"> gAKJiImHcQAu </Plugin>
 <Plugin File="Timer" Identifier="Timer"> gAIpLg== </Plugin>
 <Plugin File="Serial" Identifier="Serial"> gAIoSwFNsARLA0sASwBLAIlYAgAAAFxycQBYBgAAAFNlcmlhbHEBSwB0cQIu </Plugin>
 <Action> Timer.TimerAction(u'Read serial port', 0, 0, 10.0, u'Read serial port', False, True, 1, u'00:00:00') </Action>
 </Autostart>
<Macro Name="Read serial port" Expanded="True">
 <Event Name="Read serial port"/>
 <Action> Serial.Read(None, 0.0) </Action>
 <Action> EventGhost.PythonScript(u'station = eg.result\n\nif station == "C042039004023004005006007008009010011012013014015\\r":\n print "Station: Stockholm"\n eg.plugins.USB_UIRT.TransmitIR(u\'0000 0071 0000 0012 0061 0020 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0021 0020 0011 0010 0021 0011 0010 0011 0010 0020 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0021 0020 0010 0BE1\', 1, 0)\nif station == "C035028005003004005006007008009010011012013014015\\r":\n print "Station: Aland"\n eg.plugins.USB_UIRT.TransmitIR(u\'0000 0071 0000 0013 0061 0021 0010 0020 0010 0011 0010 0011 0010 0020 0020 0010 0011 0010 0021 0021 0011 0010 0021 0011 0011 0010 0010 0021 0010 0010 0010 0010 0010 0010 0011 0010 0010 0010 0010 0011 0021 0BE3\', 1, 0)') </Action>
 </Macro>
<Macro Name="Aland -> Sweden">
 <Event Name="Change to channel 2"/>
 <Action> USB_UIRT.TransmitIR(u'0000 0071 0000 0012 0061 0020 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0021 0020 0011 0010 0021 0011 0010 0011 0010 0020 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0021 0020 0010 0BE1', 1, 0) </Action>
 </Macro>
<Macro Name="Sweden -> Aland">
 <Event Name="Change to channel 1"/>
 <Action> USB_UIRT.TransmitIR(u'0000 0071 0000 0013 0061 0021 0010 0020 0010 0011 0010 0011 0010 0020 0020 0010 0011 0010 0021 0021 0011 0010 0021 0011 0011 0010 0010 0021 0010 0010 0010 0010 0010 0010 0011 0010 0010 0010 0010 0011 0021 0BE3', 1, 0) </Action>
 </Macro>
 </EventGhost>
I transmit the ir in the pyhon script:

Code: Select all

station = eg.result

if station == "C042039004023004005006007008009010011012013014015\r":
    print "Station: Stockholm"
    eg.plugins.USB_UIRT.TransmitIR(u'0000 0071 0000 0012 0061 0020 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0021 0020 0011 0010 0021 0011 0010 0011 0010 0020 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0021 0020 0010 0BE1', 1, 0)
if station == "C035028005003004005006007008009010011012013014015\r":
    print "Station: Aland"
    eg.plugins.USB_UIRT.TransmitIR(u'0000 0071 0000 0013 0061 0021 0010 0020 0010 0011 0010 0011 0010 0020 0020 0010 0011 0010 0021 0021 0011 0010 0021 0011 0011 0010 0010 0021 0010 0010 0010 0010 0010 0010 0011 0010 0010 0010 0010 0011 0021 0BE3', 1, 0)
But I would like to have it so the script starts the macros "Sweden -> Aland" or "Aland -> Sweden" instead. Can anybody tell what command I should use for this?

Also now I am checking the serial port every 10s to see if there is anything. Is there some other way to check the port so it activates the program as soon there is any activity on the port?

If anybody wonders what this program is for, it is reading a TV antenna control unit on a ship that changes stations to the one closest to the ship. When this changes it shoud change the channel on a DVB-T receiver to the right one.
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: Reading serial port and controlling TV

Post by Bitmonster »

It looks like the device is sending return-terminated strings, so you should be able to use the "event generation" of the plugin to get an event everytime the device is sending something. And then you can build two macros for the IR transmission and assign the events to them.
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!
perkos
Posts: 3
Joined: Wed Oct 29, 2008 11:09 am

Re: Reading serial port and controlling TV

Post by perkos »

Thanks! That is a much better way to do it. Here's the result:

Code: Select all

<EventGhost Name="Configuration Tree" Expanded="True" Version="1483" Guid="{64ACB924-283E-470F-9BF4-4E7B6066C8C0}" Time="1225395875.1">
<Autostart Name="Autostart" Expanded="True">
 <Plugin File="USB-UIRT" Identifier="USB_UIRT"> gAKJiImHcQAu </Plugin>
 <Plugin File="Serial" Identifier="Serial"> gAIoSwFNsARLA0sASwBLAIhYAgAAAFxycQBYCgAAAEFDVSBzdHJpbmdxAUsAdHECLg== </Plugin>
 <Action> Serial.Read(None, 0.0) </Action>
 </Autostart>
<Macro Name="Aland -> Sweden" Expanded="True">
 <Event Name="ACU string.C042039004023004005006007008009010011012013014015"/>
 <Action> USB_UIRT.TransmitIR(u'0000 0071 0000 0012 0061 0020 0010 0020 0010 0010 0010 0010 0030 0030 0010 0010 0021 0020 0011 0010 0021 0011 0010 0011 0010 0020 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0021 0020 0010 0BE1', 1, 0) </Action>
 </Macro>
<Macro Name="Sweden -> Aland" Expanded="True">
 <Event Name="ACU string.C035028005003004005006007008009010011012013014015"/>
 <Action> USB_UIRT.TransmitIR(u'0000 0071 0000 0013 0061 0021 0010 0020 0010 0011 0010 0011 0010 0020 0020 0010 0011 0010 0021 0021 0011 0010 0021 0011 0011 0010 0010 0021 0010 0010 0010 0010 0010 0010 0011 0010 0010 0010 0010 0011 0021 0BE3', 1, 0) </Action>
 </Macro>
 </EventGhost>
Post Reply