Skip to main content
Topic: IR Toy2 - Raspi - COM port comminication using perl (Read 1360 times) previous topic - next topic

IR Toy2 - Raspi - COM port comminication using perl

LS,

I'd like to use my IR-toy v2 to read my kamstrump 66C water heating meter.

I've found in the documentation that you can talk to this device using IR using serial communication. The cool part is that they even included a little VB example;

Code: [Select]

MSComm1.Settings = “300,E,7,2”
MSComm1.Output = “/#1”
Delay (10) “Wait to clear output buffer”
MSComm1.Settings = “1200,E,7,2”
Temp = MSComm1.Input


Because I use FHEM on a Pi for home automation, I'd like to use PERL to talk to the IR Toy.

I've made an attempt to translate the VB to perl;

Code: [Select]
#!/usr/bin/perl


use strict;
use warnings;
use Device::SerialPort qw( :PARAM :STAT 0.07 );

my $PORT = "/dev/ttyACM1";
my $ob = Device::SerialPort->new($PORT);
$ob->baudrate(300);
$ob->parity("even");
$ob->databits(7);
$ob->stopbits(2);
$ob->write_settings;
$ob->write("U/u");
$ob->write("/#1");

select(undef,undef,undef,0.01);
$ob->baudrate(1200);
$ob->parity("even");
$ob->databits(7);
$ob->stopbits(2);
$ob->write_settings;

while(1) {
    my $byte=$ob->read(1);
    print "$byte";

}

But this is not working, so has anyone a clear example on how to use the IR to in Perl to communicate over the serial port?

Thanks!

:)

Re: IR Toy2 - Raspi - COM port comminication using perl

Reply #1
A bit of an old thread but here is some input if you are still struggling.

Firstly you should verify there isn't an error opening the port
die "Couldn't access $PORT: $!n" unless $ob;
Next you are altering the port settings, the IRToy firmware I do not think handles this. So only use the END settings you want (eg 1200 ...)
Next you only need to send an upper case or lowercase "U" (eg U or u, not "U/u")
And finally you will probably want to delay between sending the command to enter USB to Serial mode and the "/#1" command to the kamstrump device.

The quick look I had at a PDF from this device indicates it has a built in IR port that is used. If this is how you are intending to monitor the data, I am not sure how to proceed since none of the protocol was documented in the data I was looking at..