Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with serial read in python modbus with EM6400 #6

Open
manasdas17 opened this issue Mar 15, 2016 · 5 comments
Open

Issue with serial read in python modbus with EM6400 #6

manasdas17 opened this issue Mar 15, 2016 · 5 comments

Comments

@manasdas17
Copy link

Hi,
I am trying to implement python modbus with EM6400 . The aim is to read the volatage,current etc value on python console.But i am able to read the data properly from EM6400.Please have a look at the code.

import os
import sys
cwd=os.getcwd()
(setpath,Examples)=os.path.split(cwd)
print setpath
sys.path.append(setpath)

from PyArduino import *

import struct


port=locateport()
ser = serial.Serial(port, 9600)

ser.write("\x01\x03\x15\x86\x00\x02\x39\x15")
buf=ser.read(11)

b1=b2=b3=b4=0

a1=buf[3]

if (a1<16):
    b1=1
    a1=int(a1,16)
if (b1):
    a1='0'+str(a1)


a2=buf[4]
if (a2<16):
    b2=1
    a2=int(a2,16)
if (b2):
    a2='0'+str(a2)



a3=buf[5]
if (a3<16):
    b3=1
    a3=int(a3,16)
if (b3):
    a3='0'+str(a3)

a4=buf[6]
if (a4<16):
    b4=1
    a4=int(a4,16)
if (b4):
    a4='0'+str(a4)


a5=[a3,a4,a1,a2];
a6=''.join(a5)


print struct.unpack('!f', a6.decode('hex'))[0]

@nipunbatra
Copy link
Member

I'm sorry I don't get you. Please explain.

@manasdas17
Copy link
Author

I want to implement the below :

**Request ( by ser.write() )
01 03 0F56 0002 270F
01: Slave address
03: Function code for read holding registers
0F56: Data Address of the first requested register (address for voltage phase1 to neutral)
(0F56 hex = 3927, +40001 offset = 43928)
0002: Total number of registers requested
270F: CRC (Cyclic Redundancy Check) for error checking (LSB first)

Response: ( by ser.read() )
01 03 04 2921 4373 D2B0
01: Slave address
03: Function code for read holding registers
04: Total number of bytes read
2921: Data in 1st requested register
4373: Data in 2st requested register
D2B0: CRC for error checking (LSB first)

Values in required register are 43732921 in hex (since obtained values are being read in little endian format) which is 243.16 when converted to floating point using IEEE 754 norms. Obtained value is a voltage (phase1 to neutral) which is 243.16 Volts.
**

The issue is that, i am able to write the data to the EM6400 but the the ser.read is n't working properly.So,need to where i am going wrong with the ser.read function.

My whole idea is to display the EM6400 reading ( voltage,current,power ) on the python console .

@nipunbatra
Copy link
Member

I'm afraid I won't be able to look into this any time soon. I used Pymodbus/MinimalModbus to handle the modbus communication properly. pyserial might have sufficed, but I let the modbus libraries handle the communication part.

@manasdas17
Copy link
Author

fine....Then how did you do the modbus commuication by using Pymodbus, Is it possible to get a sample code for my implementation.

@nipunbatra
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants