Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
admin committed Sep 8, 2019
1 parent f63c696 commit 0b12538
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 124 deletions.
15 changes: 8 additions & 7 deletions examples/pftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"""
from ekmmeters import *

my_port_name = "COM3"
my_meter_address = "10001438"
my_port_name = "/dev/ttyO4"
my_meter_address = "000300001463"


ekm_set_log(ekm_no_log)
port = SerialPort(my_port_name)
Expand All @@ -13,17 +14,17 @@
my_meter = V4Meter(my_meter_address)
my_meter.attachPort(port)
else:
print "Cannot open port"
print( "Cannot open port")
exit()

for i in range(1000):
if my_meter.request():
my_read_buffer = my_meter.getReadBuffer()
# you can also traverse the buffer yourself,
#but this is the simplest way to get it all.
print "*------"
print my_meter.getField(Field.Power_Factor_Ln_1)
print my_meter.getField(Field.Cos_Theta_Ln_1)
print( "*------")
print( my_meter.getField(Field.Power_Factor_Ln_1))
print( my_meter.getField(Field.Cos_Theta_Ln_1))


port.closePort()
port.closePort()
8 changes: 4 additions & 4 deletions examples/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ekmmeters import *

my_port_name = "/dev/ttyO4"
my_meter_address = "52"
my_meter_address = "000300001463"

ekm_set_log(ekm_print_log)
port = SerialPort(my_port_name)
Expand All @@ -13,14 +13,14 @@
my_meter = V4Meter(my_meter_address)
my_meter.attachPort(port)
else:
print "Cannot open port"
print( "Cannot open port")
exit()

if my_meter.request():
my_read_buffer = my_meter.getReadBuffer()
# you can also traverse the buffer yourself,
#but this is the simplest way to get it all.
json_str = my_meter.jsonRender(my_read_buffer)
print json_str
print( json_str)

port.closePort()
port.closePort()
30 changes: 14 additions & 16 deletions examples/read_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from ekmmeters import *

#port and meter
my_port_name = "COM3"
my_meter_address = "300001162"

my_port_name = "/dev/ttyO4"
my_meter_address = "000300001463"
#logging to console
ekm_set_log(ekm_print_log)

Expand All @@ -17,22 +16,21 @@
my_meter.attachPort(port)
else:
# no port no meter
print "Cannot open port"
print ("Cannot open port")
exit()


# First readthedocs example, complete.

if my_meter.readSettings():

print "Schedule".ljust(15) + "Tariff".ljust(15) + "Date".ljust(10) + "Rate".ljust(15)
print ("Schedule".ljust(15) + "Tariff".ljust(15) + "Date".ljust(10))
for schedule in range(Extents.Schedules):
for tariff in range(Extents.Tariffs):
schedule_tariff = my_meter.extractSchedule(schedule, tariff)
print (("Schedule_" + schedule_tariff.Schedule).ljust(15) +
("kWh_Tariff_" + schedule_tariff.Tariff).ljust(15) +
(schedule_tariff.Hour+":"+schedule_tariff.Min).ljust(10) +
(schedule_tariff.Rate.ljust(15)))
("Tariff_" + schedule_tariff.Tariff).ljust(15) +
(schedule_tariff.Hour+":"+schedule_tariff.Min).ljust(10))

print("Month".ljust(7) + "kWh_Tariff_1".ljust(14) + "kWh_Tariff_2".ljust(14) +
"kWh_Tariff_3".ljust(14) + "kWh_Tariff_4".ljust(14) + "kWh_Tot".ljust(10) +
Expand All @@ -53,8 +51,8 @@
print(("Holiday_" + holidaydate.Holiday).ljust(12) +
(holidaydate.Month + "-" + holidaydate.Day).ljust(20))
holiday_weekend_schedules = my_meter.extractHolidayWeekendSchedules()
print "Holiday schedule = " + holiday_weekend_schedules.Holiday
print "Weekend schedule = " + holiday_weekend_schedules.Weekend
print ("Holiday schedule = " + holiday_weekend_schedules.Holiday)
print ("Weekend schedule = " + holiday_weekend_schedules.Weekend)

# readthedocs individual example, complete.
if my_meter.readSettings():
Expand All @@ -64,14 +62,14 @@
sched_blk_2 = my_meter.getSchedulesBuffer(ReadSchedules.Schedules_5_To_6)
holiday_blk = my_meter.getHolidayDatesBuffer()

print my_meter.jsonRender(months_fwd_blk)
print my_meter.jsonRender(months_rev_blk)
print my_meter.jsonRender(sched_blk_1)
print my_meter.jsonRender(sched_blk_2)
print my_meter.jsonRender(holiday_blk)
print (my_meter.jsonRender(months_fwd_blk))
print (my_meter.jsonRender(months_rev_blk))
print (my_meter.jsonRender(sched_blk_1))
print (my_meter.jsonRender(sched_blk_2))
print (my_meter.jsonRender(holiday_blk))





port.closePort()
port.closePort()
15 changes: 8 additions & 7 deletions examples/read_to_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from ekmmeters import *

# port and meter
my_port_name = "COM3"
my_meter_address = "300001162"

my_port_name = "/dev/ttyO4"
my_meter_address = "000300001463"
#log to console
ekm_set_log(ekm_print_log)

Expand All @@ -17,7 +16,7 @@
my_meter = V4Meter(my_meter_address)
my_meter.attachPort(port)
else:
print "Cannot open port"
print( "Cannot open port")
exit()

#always recreate for example, test in application
Expand All @@ -27,10 +26,12 @@



#do 20 inserts
arbitrary_run_iterations = 20
#do 5 inserts
arbitrary_run_iterations = 5
for i in range(arbitrary_run_iterations):
if my_meter.request():
my_meter.insert(my_db)
print(my_meter.getMeterAddress())
print(my_db.renderJsonReadsSince(0, str(my_meter.getMeterAddress())))

port.closePort()
port.closePort()
10 changes: 5 additions & 5 deletions examples/set_ctratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from ekmmeters import *

#setup port
my_port_name = "COM3"
my_meter_address = "300001162"
my_port_name = "/dev/ttyO4"
my_meter_address = "000300001463"

# log to console
ekm_set_log(ekm_print_log)
Expand All @@ -16,14 +16,14 @@
my_meter = V4Meter(my_meter_address)
my_meter.attachPort(port)
else:
print "Cannot open port"
print ("Cannot open port")
exit()

#call
if my_meter.setCTRatio(CTRatio.Amps_800):
if my_meter.request():
ct_str = my_meter.getField(Field.CT_Ratio)
print "CT is " + ct_str
print("CT is " + ct_str)


port.closePort()
port.closePort()
18 changes: 9 additions & 9 deletions examples/set_holidaydates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from ekmmeters import *

#port setup
my_port_name = "COM3"
my_meter_address = "300001162"
my_port_name = "/dev/ttyO4"
my_meter_address = "000300001463"

#log to console
ekm_set_log(ekm_print_log)
Expand All @@ -17,7 +17,7 @@
my_meter = V4Meter(my_meter_address)
my_meter.attachPort(port)
else:
print "Cannot open port"
print( "Cannot open port")
exit()

# input over range(Extents.Holidays)
Expand Down Expand Up @@ -65,12 +65,12 @@
param_buf["Holiday_17_Day"] = 0
param_buf["Holiday_18_Month"] = 0
param_buf["Holiday_18_Day"] = 0
param_buf["Holiday_19_Month"] = 0
param_buf["Holiday_19_Day"] = 0
param_buf["Holiday_20_Month"] = 1
param_buf["Holiday_20_Day"] = 9
param_buf["Holiday_19_Month"] = 12
param_buf["Holiday_19_Day"] = 19
param_buf["Holiday_20_Month"] = 12
param_buf["Holiday_20_Day"] = 20

if my_meter.setHolidayDates(param_buf):
print "Set holiday dates success."
print( "Set holiday dates success.")

port.closePort()
port.closePort()
13 changes: 6 additions & 7 deletions examples/set_lcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from ekmmeters import *

#set up port
my_port_name = "COM3"
my_meter_address = "300001162"

my_port_name = "/dev/ttyO4"
my_meter_address = "000300001463"
# log to console
ekm_set_log(ekm_print_log)

Expand All @@ -16,17 +15,17 @@
my_meter = V4Meter(my_meter_address)
my_meter.attachPort(port)
else:
print "Cannot open port"
print("Cannot open port")
exit()

# Method one: preferred
lcd_items = [LCDItems.RMS_Volts_Ln_1, LCDItems.Line_Freq]
if my_meter.setLCDCmd(lcd_items):
print "Meter should now show Line 1 Volts and Frequency."
print("Meter should now show Line 1 Volts and Frequency.")

# Method two: parsing strings (use append normally)
lcd_items = [my_meter.lcdString("RMS_Volts_Ln_1"), my_meter.lcdString("Line_Freq")]
if my_meter.setLCDCmd(lcd_items):
print "Meter should now show Line 1 Volts and Frequency."
print("Meter should now show Line 1 Volts and Frequency.")

port.closePort()
port.closePort()
23 changes: 23 additions & 0 deletions examples/set_maxdemandinterval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
""" Simple example set max demand interval
(c) 2016 EKM Metering.
"""
from ekmmeters import *

# port and meter to use
my_port_name = "/dev/ttyO4"
my_meter_address = "000300001463"
#log to console
ekm_set_log(ekm_print_log)


port = SerialPort(my_port_name)
if (port.initPort() == True):
my_meter = V4Meter(my_meter_address)
my_meter.attachPort(port)
else:
print("Cannot open port")
exit()

my_meter.setMaxDemandResetInterval(MaxDemandResetInterval.Daily)

port.closePort()
16 changes: 8 additions & 8 deletions examples/set_maxdemandperiod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from ekmmeters import *

# define port and meter
my_port_name = "COM3"
my_meter_address = "300001162"

my_port_name = "/dev/ttyO4"
my_meter_address = "000300001463"
# log is print to console
ekm_set_log(ekm_print_log)

Expand All @@ -16,16 +15,17 @@
my_meter = V4Meter(my_meter_address)
my_meter.attachPort(port)
else:
print "Cannot open port"
print("Cannot open port")
exit()


#set and check
if my_meter.setMaxDemandPeriod(MaxDemandPeriod.At_15_Minutes):
if my_meter.setMaxDemandPeriod(MaxDemandPeriod.At_30_Minutes):
if my_meter.request():
mdp_str = my_meter.getField(Field.Max_Demand_Period)
if mdp_str == str(MaxDemandPeriod.At_15_Minutes):
print "15 Minutes"
print("15 Minutes")
if mdp_str == str(MaxDemandPeriod.At_30_Minutes):
print "30 Minutes"
print("30 Minutes")
if mdp_str == str(MaxDemandPeriod.At_60_Minutes):
print "60 Minutes"
print("60 Minutes")
26 changes: 26 additions & 0 deletions examples/set_maxdemandresetnow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
""" Simple example set max demand interval
(c) 2016 EKM Metering.
"""
from ekmmeters import *

# port and meter to use
my_port_name = "/dev/ttyO4"
my_meter_address = "000300001463"

#log to console
ekm_set_log(ekm_print_log)


port = SerialPort(my_port_name)
if (port.initPort() == True):
my_meter = V4Meter(my_meter_address)
my_meter.attachPort(port)
else:
print("Cannot open port")
exit()


my_meter.setMaxDemandResetNow()


port.closePort()
Loading

0 comments on commit 0b12538

Please sign in to comment.