Files
HenryPump-Drivers/easttexas/easttexas.py
Nico Melone 632dcdb3e8 Added Folders
Add all the driver folders
2019-12-13 12:15:30 -06:00

50 lines
1.5 KiB
Python

#!/usr/bin/python
import traceback
import threading
import time
import os
from device_base import deviceBase
from datetime import datetime
import requests
import json
import calendar
import pickle
import minimalmodbus
import minimalmodbusM1
class start(threading.Thread, deviceBase):
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None, companyId=None, offset=None, mqtt=None, Nodes=None):
threading.Thread.__init__(self)
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes)
self.daemon = True
self.version = "1"
self.finished = threading.Event()
# Setup Modbus Connection
baud = 115200
mb_connected = False
while not mb_connected:
mb_connected = self.mcu.set232Baud(baud)
time.sleep(1)
ser232 = self.mcu.rs232
self.modbus_interface = minimalmodbusM1.Instrument(1, ser232)
self.modbus_interface.address = 1
threading.Thread.start(self)
# this is a required function for all drivers, its goal is to upload some piece of data
# about your device so it can be seen on the web
def register(self):
self.sendtodb("connected", "True", 0)
def run(self):
while True:
register = 31
test_coil = self.modbus_interface.read_bit(register, functionCode=1)
print("Here's the value from register {}: {}".format(register, test_coil))