-
-
Save akshaybaweja/ae87f2d5932ca77a5df907845d268046 to your computer and use it in GitHub Desktop.
Revisions
-
dotmat created this gist
Jan 15, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ #!/usr/bin/env python3 import minimalmodbus import serial powerMeter = minimalmodbus.Instrument('/dev/ttyUSB0', 1) powerMeter.serial.baudrate = 9600 powerMeter.serial.bytesize = 8 powerMeter.serial.parity = serial.PARITY_NONE powerMeter.serial.stopbits = 1 powerMeter.mode = minimalmodbus.MODE_RTU # Print the details of the power meter here, these also include the config needed to talk to the unit. print('Details of the power meter are:') print(powerMeter) def readPowerMeter(): print("Attempting to read power meter") try: voltageReading = powerMeter.read_register(0, 0, 4) ampsReading = powerMeter.read_register(1, 0, 4) wattsReading = powerMeter.read_register(3, 0, 4) frequencyReading = powerMeter.read_register(7, 0, 4) print("Voltage", voltageReading/10) print("Amps", ampsReading/10) print("Watts", wattsReading/10) print("Frequency", frequencyReading/10) except IOError: print("Failed to read from instrument") # Run the function to read the power meter. readPowerMeter()