Use python read meter but the return data length not equal to 255
Posted: Mon Nov 30, 2015 5:40 am
I have an EKM-OmniMeter (I v.3 Universal Smart Meter, Single Phase or 3-phase, 120 to 480V, 50/60Hz up to 5000 amps) installed.
I write python code that run on Raspberry pi for read data from the meter but the output from them but the return data length not equal to 255 bytes, the result that I've received is only 246 bytes. Please advice me what is wrong that I do.
The following is my code
And the result is
I write python code that run on Raspberry pi for read data from the meter but the output from them but the return data length not equal to 255 bytes, the result that I've received is only 246 bytes. Please advice me what is wrong that I do.
The following is my code
Code: Select all
import serial, time
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.SEVENBITS,
timeout=0.5
)
if ser.isOpen():
try:
time.sleep(0.5) #give the serial port sometime to receive the data
numOfLines = 0
REQUEST = "x2f\x3f\x30\x30\x30\x30\x30\x30\x30\x31\x37\x36\x36\x31\x21\x0d\x0a"
while True:
print("send data: " + REQUEST)
ser.write(REQUEST)
time.sleep(3)
response = ser.readline()
print("read data: " + response)
numOfLines = numOfLines + 1
if (numOfLines >= 5):
break
ser.close()
except Exception, e1:
print "error communicating...: " + str(e1)
else:
print "cannot open serial port "
Code: Select all
pi@raspberrypi ~/solard/src $ sudo python ekm.py
send data: x2f?000000017661!
read data: 000000017661000000000000000000000000000000000000000000000000000000000000000000000000000000002243000000000000000000000000000000000000000000000000000C000C000C0000000000011511300220201702000000000000000000000000000000000000000000000000000000000000!
send data: x2f?000000017661!
read data: 000000017661000000000000000000000000000000000000000000000000000000000000000000000000000000002252000000000000000000000000000000000000000000000000000C000C000C0000000000011511300220202102000000000000000000000000000000000000000000000000000000000000!
send data: x2f?000000017661!
read data: 000000017661000000000000000000000000000000000000000000000000000000000000000000000000000000002252000000000000000000000000000000000000000000000000000C000C000C0000000000011511300220202402000000000000000000000000000000000000000000000000000000000000!
send data: x2f?000000017661!
read data: 000000017661000000000000000000000000000000000000000000000000000000000000000000000000000000002256000000000000000000000000000000000000000000000000000C000C000C0000000000011511300220202702000000000000000000000000000000000000000000000000000000000000!
send data: x2f?000000017661!
read data: 000000017661000000000000000000000000000000000000000000000000000000000000000000000000000000002262000000000000000000000000000000000000000000000000000C000C000C0000000000011511300220203002000000000000000000000000000000000000000000000000000000000000!