Commit 6b9c962b authored by Manuel Navarrete's avatar Manuel Navarrete
Browse files

update test resistence

parent 4bb93e3b
......@@ -51,7 +51,7 @@ if __name__ == '__main__':
old_slave = 1
new_slave = 2
baudrate = 6
baudrate = 6 #9600bps
tx_change = struct.pack('B',old_slave)+'\x10\x00\x20\x00\x01\x02'+struct.pack('B',new_slave)+struct.pack('B',baudrate)
tx_change += m.get_crc(tx_change)
......
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
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__':
m=modbus.Modbus()
tx1='\x02\x03\x00\x0C\x00\x01'
# print "init"
# polling.poll(
# poll,
# ignore_exceptions=(IOError,),
# timeout=2,
# step=0.5)
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
if __name__ == '__main__':
m=modbus.Modbus()
#vemos el valor del modo del test de resistencia
tx_ir='\x02\x03\x00\x10\x00\x01'
tx_ir += m.get_crc(tx_ir)
rx_ir= m.raw(tx_ir)
print list (rx_ir)
#vemos el valor del registro
tx_ct='\x02\x03\x00\x0C\x00\x01'
tx_ct += m.get_crc(tx_ct)
rx_ct= m.raw(tx_ct)
print list (rx_ct)
#escribimos en el registro
tx_tr= '\x02\x10\x00\x0C\x00\x01\x02\xF0\xF0'
tx_tr += m.get_crc(tx_tr)
rx_tc= m.raw(tx_tr)
print list (rx_tc)
tx_r='\x02\x03\x00\x03\x00\x01'
tx_r += m.get_crc(tx_r)
while True:
#vemos el valor de la resistencia
rx_r= m.raw(tx_r)
print list (rx_r)
#vemos el valor del test
rx_ct= m.raw(tx_ct)
print list (rx_ct)
'''
direccion del valor del test 0003
registro del inicio del test 000C
valor a escribir para iniciar el test F0F0
modo de test 0010 valor 1 30s valor 0 10s
shelve
'''
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 get_tr(tx):
rx_tr = m.raw(tx)
if len(rx_tr)==7:
value=struct.unpack('>H',rx_tr[3:5])[0]
if value == 0:
print'Test de resistencia a cero'
rx = True
else:
print'Trama del test de resistencia erronea'
rx = False
elif len(rx)>0
print'Trama del test de resistencia erronea'
print list (rx_tr)
rx = False
else:
print'Test de resistencia ejecutandose o sin respuesta'
rx = False
return rx
def get_r(tx):
r = -1
rx = m.raw(tx)
if len(rx)== 7
r = struct.unpack('>H',rx[3:5])[0]
if r>0:
print "Cell Resistance:"+str(r)+" miliOhms"
r /=1000.0
else
print 'Cell Resistance: 0 miliOhms''
elif len(rx)>0
print'Trama del test de resistencia erronea'
else:
print'Test de resistencia ejecutandose'
return r
def save_data(tx):
rx = m.raw(tx)
time.sleep(30)
resistance = struct.unpack('>H',rx[3:5])[0]
time_data = time.time()
#funcion save_data(resistenace,time_data)
if __name__ == '__main__':
m = modbus.Modbus()
tr = False
timexp = 1000000
time_r = 9999999 #real_time - time_save
r_save = 24.3
tx_tr ='\x02\x03\x00\x0C\x00\x01'
tx_tr += m.get_crc(tx_tr)
tx_r = '\x02\x03\x00\x03\x00\x01'
tx_r +=m.get_crc(tx_r)
tx_test= '\x02\x10\x00\x0C\x00\x01\x02\xF0\xF0'
tx_test += m.get_crc(tx_test)
while True:
tr = get_tr(tx_tr)
if tr == True
r = get_r(tr_r)
if r==0:
m.raw(tx_test)
time_r =time.time()
elif r>0:
if time_r>timexp:
m.raw(tx_test)
time_r =time.time()
#elif r/r_save<0.8
# test(tx_test)
print 'Valor de la resistencia',r
print 'Tiempo de guardado', time_r
#def poll():
# print "funtion",time.time()
# print "init"
# polling.poll(
# poll,
# ignore_exceptions=(IOError,),
# timeout=2,
# step=0.5)
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