Commit 7e505538 authored by root's avatar root
Browse files

update examples

parent 75f58d22
import polling
import struct
import time
import sys
import os
module_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, module_path)
import modbus
#def poll():
# print "funtion",time.time()
def get_tr(tx):
tx = tx + m.get_crc(tx)
rx = m.raw(tx)
if len(rx)>5
print'Test de resistencia a cero'
rx=True
else
print'Test de resistencia ejecutandose'
rx=False
return rx
def get_r(tx):
tx = tx + m.get_crc(tx)
rx = m.raw(tx)
r = struct.unpack('>H',rx[3:5])[0]
if len(r)== 0
print"Cell Resistance: 0 miliOhms"
rx=True
else
print "Cell Resistance:"+str(r)+" miliOhms"
rx=False
def poll():
print "funtion",time.time()
return rx
def init_tr():
tx
tx = tx + m.get_crc(tx)
rx = m.raw(tx)
r = struct.unpack('>H',rx[3:5])[0]
if len(r)== 0
print"Cell Resistance: 0 miliOhms"
rx=True
else
print "Cell Resistance:"+str(r)+" miliOhms"
rx=False
return rx
if __name__ == '__main__':
print "init"
polling.poll(
poll,
ignore_exceptions=(IOError,),
timeout=2,
step=0.5)
m=modbus.Modbus()
tx1='\x02\x03\x00\x0C\x00\x01'
# print "init"
# polling.poll(
# poll,
# ignore_exceptions=(IOError,),
# timeout=2,
# step=0.5)
......@@ -50,9 +50,9 @@ if __name__ == '__main__':
m=modbus.Modbus()
tx='\x01\x03\x00\x03\x00\x03'
rx=m.raw(tx + m.get_crc(tx))
tx += m.get_crc(tx)
while True:
rx=m.raw(tx)
i = None # Current
t1 = None # Temperature 1
......
......@@ -14,33 +14,34 @@ Device:
Converts UART bus to RS485 bus
Model: HUASU CTB-485
TX_SLAVE_TA
Addres of slave 1: 02h
TX_SLAVE_TC
Addres of slave 1: 01h
Function code: 03h
Addres of the first register: 0001h
Addres of the first register: 0003h
Quanty of registers: 0003h
RX_SLAVE_TA
RX_SLAVE_TC
Addres of slave: 1 Byte
Function code: 1 Byte
Byte count: 1 Byte
Value 6 Bytes
CRC: 2 Bytes
TX_SLAVE_TC
Addres of slave 1: 01h
TX_SLAVE_TA
Addres of slave 2: 02h
Function code: 03h
Addres of the first register: 0003h
Addres of the first register: 0001h
Quanty of registers: 0003h
RX_SLAVE_TC
RX_SLAVE_TA
Addres of slave: 1 Byte
Function code: 1 Byte
Byte count: 1 Byte
Value 6 Bytes
CRC: 2 Bytes
"""
__author__ = 'Manuel Navarrete'
......
......@@ -86,7 +86,14 @@ if __name__ == '__main__':
tx_slave1='\x01\x03\x00\x10\x00\x06'
tx_slave2='\x02\x03\x00\x10\x00\x06'
txs=[tx1, ...]
while True:
for tx in txs:
rx = get_values(tx)
if (len )
print_values(rx)
print 'Sensor 1'
print_values(get_values(tx_slave1))
print '------'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment