Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19995
| From | Dietmar Schwertberger <news@schwertberger.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: convert perl-script for voltcraft voltmeter to python [newbie] |
| Date | 2012-02-08 01:26 +0100 |
| Organization | 1&1 Internet AG |
| Message-ID | <jgsfge$mgh$1@online.de> (permalink) |
| References | <d953c169-0656-46c1-a3ba-5387c9c06df8@t30g2000vbx.googlegroups.com> <8a475c9d-24ed-45a4-af9f-2ca826f9301d@m2g2000vbc.googlegroups.com> |
Am 03.02.2012 14:11, schrieb Jean Dupont:
> As my request might have been too much asked, I have started doing
> some coding myself.
> I'm in doubt about the readline statement -which doesn't show anything
> received- as the meter sends continuously streams of 11 bytes
> Is there a way to just monitor with python what is arriving at a
> serial port?
Some time ago I started working on reading data from a VC940.
I would assume that the protocol is the same.
Please find below the code that will return the raw values from
a VC940 (tested on a classical RS232 port, but probably
will work on USB-RS232 converters as well).
If you don't get anything, then you should check whether your
USB converter is supplying voltage on the DTR pin once you have called
self.serial.setDTR(1).
You have the description how to decode the values?
E.g. the string "0003:1401" translates to 0.3 Ohms.
I did not implement anything else, as I just wanted to be sure
that I could read the values, but I never needed to...
Regards,
Dietmar
import serial
import time
class VC940(object):
def __init__(self, port="COM3"):
self.port = port
self.serial=serial.Serial(port,2400, bytesize=7, parity="N",
stopbits=1, timeout=1.5, xonxoff=0, rtscts=0, dsrdtr=None)
self.serial.setRTS(0)
self.serial.setDTR(0)
def _read_raw_value(self):
timeout = True
for n in range(5):
self.serial.flushInput()
self.serial.setDTR(1)
data = self.serial.read(11)
self.serial.setDTR(0)
if data.endswith("\r\n") and len(data)==11:
return data
if not data:
raise ValueError, "communication timeout"
raise ValueError, "could not read data from port"
if __name__=="__main__":
vc = VC940()
while True:
print vc._read_raw_value()
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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