Before commenting read Forum rules
Don't comment the topic if you have a new question.
You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.
Before commenting read Forum rules
Don't comment the topic if you have a new question.
You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.
Hi everyone,
I want to read a smart meter over tcp/ip(IPV4) with python.
I can read it over serial.
But i need to read over tcp protocol.But i don't know how?
Can you share a script or sample code please?
Can you help to me please?
Thanks.
import serial,time,re,os
serialport = 'COM5'
init_seq = bytes('/?!\r\n', 'ascii')
request = bytearray('\x06000\r\n', 'ascii') #Acknowledge char 06 30 35 30 0D 0A --> 050
serial = serial.Serial(
serialport, 300,
bytesize=serial.SEVENBITS,
parity=serial.PARITY_EVEN,
timeout=5,
interCharTimeout=2)
serial.flushInput()
serial.write(init_seq)
print("Sayaca Oturum Acma Istegi Gonder:\n> {}".format((init_seq.decode('iso-8859-9')))[:-2])
response = bytes()
newlines = 0
try:
while newlines < 1:
response += serial.read()
length = len(response)
if (0x0a or 0x0d) in response:
newlines += 1
meter_id = response
print ("Sayac ID sini Al:\n< {}".format((meter_id.decode('iso-8859-9'))[:-2]))
except Exception as e:
print ("Sayac ID Yok")
if (len(response) >= 5):
if (meter_id[4] - 0x30) in range(6):
new_ascii_baudrate = 300 * (1 << (response[4] - 0x30))
print ("Desteklenen Baudrate ASCII :{}".format(new_ascii_baudrate))
request[2] = meter_id[4]
print ("Oturum Ac:")
try:
wait = 1.0
time.sleep(wait)
print("ACK gonder:\n> {}".format((request.decode('iso-8859-9'))[:-2]))
new = 'false'
while new == 'false':
response2 = bytes()
time.sleep(0.5)
serial.baudrate = 300
print ("Baudrate 300 ile basla")
serial.write(request)
time.sleep(0.5)
#time.sleep(2.0)
print ("send hex:{}".format(request))
#print (os.popen('stty -F COM1').read())
serial.baudrate = new_ascii_baudrate
serial.timeout = 1
print ("Yeni Baudrate = {} ".format(new_ascii_baudrate))
#print (os.popen('stty -F COM1').read())
response2 += serial.read()
#print (response2.decode('iso-8859-9'))
if len(response2) > 0:
if 0x02 in response2:
print ("STX al (Frame start character )") #x\02
end = 'false'
while end == 'false':
response2 += serial.read()
#print ("RESPONSE:{0}".format(response2.decode('iso-8859-9')))
if (0x03 in response2) and (0x3a in response2):
print ("ETX al (Frame end character )") #x\03
end = 'true'
print ("Okunan Sayac Modeli: {}".format((meter_id.decode('iso-8859-9'))[:-2]))
print ("Sayac Verileri:")
print ("---------------\n{0}".format(response2.decode('iso-8859-9')))
new = 'true'
print ("------------------------")
except Exception as e:
print("ERROR: {0}".format(e))
Hi,
Hi,
You can read your meter usually in the same ways as you read your meter using the serial port connection.
Commands are the same with different communication channels.
BR,
Mikko
Dear Sir,
Dear Sir,
Thank you for your quick response.
I just started coding and I don't have a very detailed knowledge of the dlms-cosem standard.
But i am continue read and search.
I don't know exactly which library to use for this stuation.
When i try to read with Gurux.Net.Python i am getting this error.
I need your valuable advice and guidance.
Best Regards.
Property 'port' has hanged.
trace:12:20:45 TraceTypes.INFO MediaState.OPENING
Media state changed. MediaState.OPENING
trace:12:20:45 TraceTypes.INFO MediaState.OPEN
Media state changed. MediaState.OPEN
trace:12:20:45 TraceTypes.SENT /?!
trace:12:20:45 TraceTypes.SENT /?!
Failed to receive reply from the server.
trace:12:20:47 TraceTypes.INFO MediaState.CLOSING
Media state changed. MediaState.CLOSING
trace:12:20:47 TraceTypes.INFO MediaState.CLOSED
Media state changed. MediaState.CLOSED
Hi,
Hi,
Your example is using IEC 62056-21, not DLMS/COSEM
http://www.gurux.fi/DLMSCOSEMFAQ
You need to ask from meter vendor is your meter supporting IEC 62056-21 with TCP/IP or do you need to use DLMS?
BR,
Mikko