ndir example and added pp.skip()

doublebuf
Ondřej Hruška 7 years ago
parent 1a6d45cc1c
commit 2554c4245b
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 4
      gex/PayloadParser.py
  2. 7
      gexync.py
  3. 26
      ndir_test.py

@ -113,3 +113,7 @@ class PayloadParser:
def blob(self, length) -> bytearray:
""" Read a blob of given length """
return self._slice(length)
def skip(self, nbytes:int):
""" Skip some bytes """
self.blob(nbytes)

@ -1,4 +1,5 @@
#!/bin/env python3
import gex
import sys
@ -39,7 +40,7 @@ class GexIniEditor(QtGui.QMainWindow):
syncAction.triggered.connect(self.gexSync)
icon = self.style().standardIcon(QtGui.QStyle.SP_DialogOkButton)
persAction = QtGui.QAction(icon, 'Persist, Close', self)
persAction = QtGui.QAction(icon, 'Persist', self)
persAction.setShortcut('Ctrl+P')
persAction.triggered.connect(self.gexPersist)
@ -86,6 +87,7 @@ class GexIniEditor(QtGui.QMainWindow):
self.editor.setPlainText(read_ini)
self.highlight.rehighlight()
self.setWindowTitle('GEX config file editor')
def gexSync(self):
new_txt = self.editor.toPlainText()
@ -99,12 +101,13 @@ class GexIniEditor(QtGui.QMainWindow):
self.editor.setPlainText(read_ini)
self.highlight.rehighlight()
self.setWindowTitle('*GEX config file editor')
def gexPersist(self):
client = gex.Client(gex.TrxRawUSB(), load_units=False)
client.ini_persist()
client.close()
self.close()
self.setWindowTitle('GEX config file editor')
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)

@ -0,0 +1,26 @@
import time
import gex
with gex.Client(gex.TrxRawUSB()) as client:
ser = gex.USART(client, 'ser')
buf = bytearray()
def decode(data, ts):
global buf
buf.extend(data)
if len(buf) == 9:
pp = gex.PayloadParser(buf, endian="big")
pp.skip(2)
print("%d ppm CO₂" % pp.u16())
buf = bytearray()
if len(buf) > 9:
# something went wrong, clear
buf = bytearray()
ser.listen(decode, decode=None)
while True:
ser.write([0xFF, 0x01, 0x86, 0, 0, 0, 0, 0, 0x79])
time.sleep(1)
Loading…
Cancel
Save