Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19924

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

From Terry Reedy <tjreedy@udel.edu>
Subject Re: convert perl-script for voltcraft voltmeter to python [newbie]
Date 2012-02-06 23:21 -0500
References <d953c169-0656-46c1-a3ba-5387c9c06df8@t30g2000vbx.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.5487.1328588509.27778.python-list@python.org> (permalink)

Show all headers | View raw


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.

> 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.

There are also python usb modules.
http://sourceforge.net/projects/mysql-python/?source=directory

> #!/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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

convert perl-script for voltcraft voltmeter to python [newbie] Jean Dupont <jeandupont115@gmail.com> - 2012-02-02 12:57 -0800
  Re: convert perl-script for voltcraft voltmeter to python [newbie] Jean Dupont <jeandupont115@gmail.com> - 2012-02-03 05:11 -0800
    Re: convert perl-script for voltcraft voltmeter to python [newbie] Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-02-07 12:44 -0500
      Re: convert perl-script for voltcraft voltmeter to python [newbie] Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-07 11:47 -0800
    Re: convert perl-script for voltcraft voltmeter to python [newbie] Dietmar Schwertberger <news@schwertberger.de> - 2012-02-08 01:26 +0100
      Re: convert perl-script for voltcraft voltmeter to python [newbie] Jean Dupont <jeandupont115@gmail.com> - 2012-02-08 04:24 -0800
  Re: convert perl-script for voltcraft voltmeter to python [newbie] Terry Reedy <tjreedy@udel.edu> - 2012-02-06 23:21 -0500
    Re: convert perl-script for voltcraft voltmeter to python [newbie] Jean Dupont <jeandupont115@gmail.com> - 2012-02-07 11:44 -0800
      Re: convert perl-script for voltcraft voltmeter to python [newbie] Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-02-07 17:57 -0500

csiph-web