Skip to content

Instantly share code, notes, and snippets.

@yogiblue
Last active July 12, 2019 08:23
Show Gist options
  • Save yogiblue/6eacd410373ca855b75b7f4d13b01e03 to your computer and use it in GitHub Desktop.
Save yogiblue/6eacd410373ca855b75b7f4d13b01e03 to your computer and use it in GitHub Desktop.
import serial
import time
import pyperclip
import pyautogui
print ("")
print (" 0Haus Pioneer PX224/E data reciever program")
print (" Press print on the scales and this software will paste it")
print (" wherever your cursor has focus")
print ("")
s = serial.Serial()
foundPort = False
s.port ='COM3'
try:
s.open()
foundPort = True
except:
print("!! Could not open serial port on COM3")
foundPort = False
if foundPort == False:
s.port ='COM4'
try:
s.open()
foundPort = True
except:
print("!! Could not open serial port on COM4")
foundPort = False
if foundPort == False:
s.port ='COM1'
try:
s.open()
foundPort = True
except:
print("!! Could not open serial port on COM1")
foundPort = False
if foundPort == False:
s.port ='COM2'
try:
s.open()
foundPort = True
except:
print("!! Could not open serial port on COM2")
foundPort = False
if foundPort == False:
print("!! WARNING")
print("!! Could not open serial port on any COM, try plugging the scales in")
print("!! Aborting")
time.sleep(5)
quit()
if s.is_open == False:
print("Could not detect COM, try plugging the scales in")
time.sleep(10)
quit()
print("Waiting")
while True:
size = s.inWaiting()
bufferread = s.read(size)
buffer = bufferread.decode('ascii')
if size>0:
start = buffer.find('Net:')
end = buffer.find('g N')
if end>start+5:
number = buffer[start+5:end]
print ("Read Net Value " + number.strip())
pyperclip.copy(number.strip())
pyautogui.hotkey('ctrl','v')
else:
print("I read some data but I don't know what it is. Contact Chris")
time.sleep(1)
start=0
end=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment