Use python read meter but the return data length not equal to 255

For more advanced meter data users. Learn from others and ask questions about how to read meters, how to use the EKM Push Data, and how to display the meter data in useful ways.
Post Reply
dexterppp
Posts: 4
Joined: Mon Nov 30, 2015 5:07 am

Use python read meter but the return data length not equal to 255

Post by dexterppp »

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

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 "
And the result is

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!
Jameson
Posts: 860
Joined: Fri Nov 04, 2011 7:42 pm
Location: Santa Cruz, CA
Contact:

Re: Use python read meter but the return data length not equal to 255

Post by Jameson »

Hello dexterppp,

Welcome to the forum and thanks for posting your raspberry pi code!

Im not much of a coder myself, but all I would suggest is that you get the characters back as Hex, instead of ASCII. With Hex you can see each byte individually and know exactly what it is. With ASCII there are non-printable characters that will just fail to show up in the return string.

You are getting a full meter response, you just can't see it because the data you are looking at is in ASCII. Your return should look like this document:

http://documents.ekmmetering.com/Meter_ ... ter_v3.pdf

It should look like this:

02 10 17 13 30 30 30 30 30 30 30 31 30 30 31 35.......

02 10 17 and 13 are all non-printable characters in ASCII.

Hope this helps.
Jameson
EKM METERING
http://www.ekmmetering.com
831.425.7371
dexterppp
Posts: 4
Joined: Mon Nov 30, 2015 5:07 am

Re: Use python read meter but the return data length not equal to 255

Post by dexterppp »

Hi Jameson,

Thank you for your reply, I've understood your explain. Thank you very much.
But the exactly my problem is in this post http://forum.ekmmetering.com/viewtopic.php?f=4&t=3474.
My project would like to use C++ but Python is only for testing transferring data because the C++ code doesn't work.
Post Reply