convert perl-script for voltcraft voltmeter to python [newbie]

Jean Dupont jeandupont115 at gmail.com
Tue Feb 7 20:44:40 CET 2012


On 7 feb, 05:21, Terry Reedy <tjre... at udel.edu> wrote:
> On 2/2/2012 3:57 PM, Jean Dupont wrote:
>
> > I'd like to read in the output of a voltcraft vc960 voltmeter
> > connected to a usb-port.
> > I found the perl-script below but I'd like to accomplish the same with
> > python:
>
> The script below is for an old-fashioned, slow, multiple-pin serial
> port, not usb. I don't know anything about interfacing through usb.
> Recheck what the voltmeter actually connects to.
The voltmeter uses an optical rs232-connection, that is "good enough
technology" for this purpose. But as I don't have a computer with real
rs232 ports I use a rs232toUSB adapter which presents itself to the
linux-computer as /dev/ttyUSBx.
>
> > I guess I have to use the module serial but I don't know how I should
> > set the serial parameters so they are the same as in the perl-script.
> > Could someone supply me the command for setting the serial-parameters
> > correctly in Python?
>
> Last I know, pyserial is also for old serial ports. Setting the
> properties should be pretty obvious from the manual or code.
>
It is not so obvious as you might think, one reason being the
handshake line(s?) are used in an unconvential way to supply power to
the rs232-optical interface
> There are also python usb modules.http://sourceforge.net/projects/mysql-python/?source=directory
I followed this link but all I found was something concerning
mysql...???
>
anyway, thanks for trying to help

Jean
>
>
>
>
>
>
> > #!/usr/bin/perl
>
> > use strict;
> > use warnings;
>
> > use Device::SerialPort;
>
> > die("Usage: $0 /dev/ttyS0\n") unless $#ARGV == 0;
>
> > my ($devicepath) = @ARGV;
>
> > my $port = new Device::SerialPort($devicepath);
> > die "Couldn't open serial port" if ! defined $port;
>
> > $port->baudrate(2400);
> > $port->databits(8);
> > $port->parity("none");
> > $port->stopbits(1);
> > $port->handshake("none");
> > $port->rts_active(0);
> > $port->dtr_active(1);
>
> > #$port->read_char_time(5);     # wait 5ms per character
> > $port->read_const_time(200);   # 0.2 second per unfulfilled "read"
> > call
> > $| = 1; # autoflush STDOUT
> > while(1) {
> >          my ($nin, $in) = $port->read(255);
> >          print $in;
> > }
>
> > $port->close;
>
> --
> Terry Jan Reedy




More information about the Python-list mailing list