1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
import serial
import wx
unit={'\x80':'V', '\x40' : 'A', '\x20' : 'R', '\x08' : 'Hz', '\x04' : 'F'}
prefix={'\x80' : 'u', '\x40' : 'm', '\x20' : 'k', '\x10' : 'M', '\x00' : '' }
virgule={'1' : 1000, '2' :100, '4' : 10, '0' : 1}
class frame(wx.Frame):
def __init__(self, aff) :
wx.Frame.__init__(self, None, -1, title="DMM9405", size = (200,100))
conteneur = wx.Panel(self, -1, size = self.GetClientSize())
etiquette = wx.StaticText(conteneur, -1, aff, style = wx.ALIGN_CENTRE)
etiquette.CentreOnParent()
class MonApp(wx.App) :
def OnInit(self) :
#Lecture sur le port série
ser = serial.Serial('/dev/ttyS0',2400) ; s = ser.read(11)
ser.close()
if s[1:5]==';0:;' :
affich = "OL"
else :
if s[8]=='\n' :
affich=s[0]+" "+str(float(s[1:5])/virgule[s[6]])+" n"+unit[s[10]]
else :
affich=s[0]+" "+str(float(s[1:5])/virgule[s[6]])+" "+prefix[s[9]]+unit[s[10]]
#Chaine à afficher -> affich
fen=frame(affich)
fen.Show(True)
return True
app= MonApp()
app.MainLoop() |
Partager