perl script
Hi,
I wrote a very small perl script to illustrate the functionality of the communication with a D&W.
Hope this helps.
Hi,
I wrote a very small perl script to illustrate the functionality of the communication with a D&W.
Hope this helps.
Code:
#!/usr/bin/perl -w # Reads a number of registers from the virtual serial port connect to a D&W # Connect the D&W with a USB cable to the computer (eg: raspberry PI) where this script will be running # Find out which port is added in the /dev/ folder. # Mod the variable $PORT in order to match what you have found. # # This script is tested on a raspberry Pi type B connected with a D&W primus. # The opperating system running on the Pi is "Raspbian GNU/Linux 7 (wheezy)" # # In order to read a reg first a write through the serial bus should be done. # The ID and the Reg number incremented with 1 should be written. # eg: "130 201\n" will instantiate the read of register 200 # D&W will respond with a string which contains the value of the reguster # eg: "130 201 21235" This means register 200 contains the value 21235 # For this reg a temp of 21.235 C use strict; use Device::SerialPort qw( :PARAM :STAT 0.07 ); my $PORT = "/dev/ttyUSB0"; my $Id = "130"; my @Regs2Read = qw(230 5002 1066 202 200 1184 1186 216 1092 1094 5060); my $ob = Device::SerialPort->new($PORT); $ob->baudrate(115200); $ob->parity("none"); $ob->databits(8); $ob->stopbits(1); $ob->handshake("xoff"); $ob->read_const_time(1000); $ob->write_settings; open(SERIAL, "+>$PORT"); foreach my $Reg (@Regs2Read) { my $RegRead = $Reg+1; my $String = $Id." ".($Reg+1)."\xd"; $ob->lookclear ; $ob->write($String) or die ("Could not write to port: $!"); Wait4SERIAL: while (my $line = <SERIAL>) { if ( ${line} =~ /${Id}\s${RegRead}\s(\d+)/ ) { print "${line}"; last(Wait4SERIAL); } } } close(SERIAL);
Kommentar