dede@i5:~>
dmesg | tail [ 1234.828764] usbserial: USB Serial support registered for generic [ 1234.830391] usbcore: registered new interface driver ftdi_sio [ 1234.830413] usbserial: USB Serial support registered for FTDI USB Serial Device [ 1234.830523] ftdi_sio 1-1.4:1.0: FTDI USB Serial Device converter detected [ 1234.830616] usb 1-1.4: Detected FT232RL [ 1234.830618] usb 1-1.4: Number of endpoints 2 [ 1234.830620] usb 1-1.4: Endpoint 1 MaxPacketSize 64 [ 1234.830622] usb 1-1.4: Endpoint 2 MaxPacketSize 64 [ 1234.830624] usb 1-1.4: Setting MaxPacketSize 64 [ 1234.830913] usb 1-1.4: FTDI USB Serial Device converter now attached to ttyUSB0 |
\0xa5(\0x10\0x00\0x05\0x01\0x08\0x00\0x04\0x00\0x00\0x00\0xfb\0x00\0xa5(\0x10\0x00\0x05\0x01\0x08\0x00\0x04\0x00\0x00\0x00\0xfb\0x00\0xa5(\0x10\0x00\0x05\0x01\0x08\0x00\0x04\0x00\0x00\0x00\0xfb\0x00\0xa5(\0x10\0x00\0x05\0x01\0x08\0x00\0x04\0x00\0x00\0x00\0xfb\0x00\0xa5(\0x10\0x00\0x05\0x01\0x08\0x00\0x04\0x00\0x00\0x00\0xfb\0x00\0xa5(\0x10\0x00\0x05\0x01\0x08\0x00\0x04\0x00\0x00\0x00\0xfb\0x00\0xa5(\0x10\0x00\0x05\0x01\0x08\0x00\0x04\0x00\0x00\0x00\0xfb\0x00\0xa5(\0x10\0x00\0x05\0x01\0x08\0x00\0x04\0x00\0x00\0x00\0xfb\0x00\0xa5(\0x10\0x00\0x05\0x01\0x08\0x00\0x04\0x00\0x00\0x00\0xfb\0x00\0xa5(\0x10\0x00\0x05\0x01\0x08\0x00\0x04\0x00\0x00\0x00\0xfb\0x00\0xa5(\0x10\0x00\0x05\0x01\0x08\0x00\0x04\0x00\0x00\0x00\0xfb\0x00 |
#!/usr/bin/env python # -*- coding: utf-8 -*- import serial ser=serial.Serial('/dev/ttyUSB0', 2400, parity=serial.PARITY_EVEN) while True: s=ser.read(14) for c in s: print hex(ord(c)), |
0xa5 0x28 0x10 0x0 0x5 0x1 0x8 0x0 0x4 0x0 0x0 0x0 0xfb 0x0 |
0xa3 0x8 0x10 0x0 0x0 0x9 0x8 0x5 0x2 0x0 0x0 0x0 0xfb 0x0 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ###########################################################
# Ein Script zur Anzeige der Messwerte eines PeakTech 4000.
#
#
# Detlev Ahlgrimm, 11.01.2018
#
import serial
# Stellen, Bereich
byte0bit3210= { 0 : ["x.xxxx V", "xx.xxx V", "xxx.xx V", "xxx.x V", "-", "-", "-" ],
1 : ["x.xxxx V", "xx.xxx V", "xxx.xx V", "xxx.x V", "-", "-", "-" ],
2 : ["x.xxxx V", "xx.xxx V", "xxx.xx V", "xxx.x V", "-", "-", "-" ],
3 : ["xx.xxx mV", "xxx.xx mV", "-", "-", "-", "-", "-" ],
4 : ["xx.xxx mV", "xxx.xx mV", "-", "-", "-", "-", "-" ],
5 : ["xx.xxx mV", "xxx.xx mV", "-", "-", "-", "-", "-" ],
6 : ["xx.xxx Hz", "xxx.xx Hz", "x.xxxx kHz", "xx.xxx kHz", "xxx.xx kHz", "x.xxxx MHz", "xx.xxx MHz" ],
7 : ["x.xxxx V", "-", "-", "-", "-", "-", "-" ],
8 : ["xxx.xx Ω", "x.xxxx kΩ", "xx.xxx kΩ", "xxx.xx kΩ", "x.xxxx MΩ", "xx.xxx MΩ", "-" ],
9 : ["xxx.xx Ω", "-", "-", "-", "-", "-", "-" ],
10 : ["xx.xx nF", "xxx.x nF", "x.xxx μF", "xx.xx μF", "xxx.x μF", "xxxx μF", "-" ],
11 : ["xxx.xx μA", "xxxx.x μA", "-", "-", "-", "-", "-" ],
12 : ["xxx.xx μA", "xxxx.x μA", "-", "-", "-", "-", "-" ],
13 : ["xxx.xx μA", "xxxx.x μA", "-", "-", "-", "-", "-" ],
14 : ["xx.xxx mA", "xxx.xx mA", "-", "-", "-", "-", "-" ],
15 : ["xx.xxx mA", "xxx.xx mA", "-", "-", "-", "-", "-" ],
16 : ["xx.xxx mA", "xxx.xx mA", "-", "-", "-", "-", "-" ],
17 : ["x.xxxx A", "xx.xxx A", "-", "-", "-", "-", "-" ],
18 : ["x.xxxx A", "xx.xxx A", "-", "-", "-", "-", "-" ],
19 : ["x.xxxx A", "xx.xxx A", "-", "-", "-", "-", "-" ] }
# Einheit
byte1bit43210=[ "Volt AC (V)", # 00
"Volt DC (V)", # 01
"Volt DC+AC (V)", # 02
"Millivolt DC (mV)", # 03
"Millivolt AC (mV)", # 04
"Millivolt DC+AC (mV)", # 05
"Frequency (Hz)", # 06
"Diode Volt (V)", # 07
"Resistance (Ω)", # 08
"Continuity (Ω)", # 09 (Durchgangsprüfung)
"Capacitance (F)", # 10 0x0a
"Microampere DC (μA)", # 11 0x0b
"Microampere AC (μA)", # 12 0x0c
"Microampere DC+AC (μA)", # 13 0x0d
"Milliampere DC (mA)", # 14 0x0e
"Milliampere AC (mA)", # 15 0x0f
"Milliampere DC+AC (mA)", # 16 0x10
"Ampere DC (A)", # 17 0x11
"Ampere AC (A)", # 18 0x12
"Ampere DC+AC (A)" ] # 19 0x13
# Quelle: http://peaktech.de/detalle-del-producto/kategorie/software/produkt/dmm-tool-basic.1034.html?file=tl_files/downloads/Diverse/PeakTech%20Multimeter-device%20communication%20protocols%202015-12-23.pdf
acdc=[ "AC", "DC", "DC+AC", "DC", "AC", "DC+AC", "", "", "", "", "",
"DC", "AC", "DC+AC", "DC", "AC", "DC+AC", "DC", "AC", "DC+AC"]
# ###########################################################
# Liefert "val" mit Komma gemäß "fmt" als String.
# val="00001", fmt="xx.xxx" -> "00.001"
# val="09850", fmt="xxx.xx" -> "098.50"
# val="00006", fmt="xx.xx" -> "00.06"
def formatValue(val, fmt):
valr=val[::-1]
fmtr=fmt[::-1]
res=""
vc=0
for i in range(len(fmtr)):
if fmtr[i]=="x":
res+=valr[vc]
vc+=1
elif fmtr[i]==".":
res+="."
return(res[::-1])
# ###########################################################
# Liefert den aufbereiteten Inhalt des 14 Byte langen "block"
# als Tupel im Format:
# (Vorzeichen, Wert, Einheit(kurz), Einheit(voll), Flags)
# Also z.B.:
# ('+', '098.50', 'kΩ', 'Resistance (Ω)', '')
# ('+', '0.0001', 'V', 'Volt DC (V)', 'DC')
# ('+', '00.005', 'mV', 'Millivolt DC (mV)', 'DC,HOLD')
def parseBlock(block):
msr=block[1]&0x1f # Einheit (Index in byte1bit43210[])
rng=block[0]&0x0f # Stellen, Bereich (Key in byte0bit3210[])
rng_f=byte0bit3210[msr][rng].split()
if (block[2]&0x20)==0: sgn="+" # Vorzeichen
else: sgn="-"
ovl=(block[1]&0x20)>0 # Überlauf
hld=(block[1]&0x40)>0 # Hold
val=""
for d in block[4:9]: # Primäranzeige
if 0<=(d&0x0f)<=9:
val+=str(d&0x0f)
else:
val+="?"
flgs=""
if acdc[msr]!="": flgs=acdc[msr]
if ovl: flgs+=",OL"
if hld: flgs+=",HOLD"
if flgs.startswith(","): flgs=flgs[1:] # erstes Komma weg
fval=formatValue(val, rng_f[0])
if ovl: fval="---"
return((sgn, fval, rng_f[1], byte1bit43210[msr], flgs))
# ###########################################################
# main()
if __name__=='__main__':
debug=False
ser=serial.Serial('/dev/ttyUSB0', 2400, parity=serial.PARITY_EVEN)
while True:
s=ser.read(1)
if (ord(s)&0xf0)==0xa0:
s+=ser.read(13)
data=parseBlock(s)
if debug:
for c in s:
print(("0"+hex(c)[2:])[-2:], end=' ')
print(" - ", data, " - ", end=' ')
print(data[0] + data[1], data[2], end=' ')
if len(data[4])>0:
print(" (" + data[4] + ")", end='')
print(flush=True)
dede@i5:~> ./pt4000_tst.py | tee -a log.txt [...] [...] |