0
This is my code:
import conector_modbus as conector_modbus
import leitor_csv as leitor_csv
address_file = 'address.csv'
dados = leitor_csv.leitor(address_file,"dicionario")
def coletar_dados():
for dado in dados:
if dado['var'] == "int":
dado['valor'] = conector_modbus.ler_dado(int(dado['reg']),"int")
yield dado
if dado['var'] == "float":
dado['valor'] = conector_modbus.ler_dado(int(dado['reg']),"float")
yield dado
def preparar_dados(dados_modbus,maquina,num):
registradores = {}
for dado in dados_modbus:
if dado['maquina'] == maquina and dado['num'] == num:
registradores.update({dado['nome']:dado['valor']})
return registradores
if conector_modbus.status_modbus("10.123.1.5",502) == True:
dados_modbus = coletar_dados()
dados_br1 = preparar_dados(dados_modbus,"br","1")
print(dados_br1)
dados_br1 = preparar_dados(dados_modbus,"br","1")
print(dados_br1)
And this is the result:
root@jonatas-A530:/media/jonatas/Documentos/Projetos/orange_modbus# python3 teste.py
{'producao_ton': 1056.0025634765625, 'fluxo_ton_h': 0, 'corrente_amp': 32767, 'horimetro_h': 1064.68994140625, 'tempo_sob_carga_h': 4.1541666984558105, 'tempo_ocioso_h': 0.466552734375}
{}
The function was called 2 times, but in the second it does not return value. I would like to understand why this occurs.
Hello Fernando, I called again the function collectar_data() according to your tip, but I keep getting the same result, I may be missing something else?
– JonP
Probably his
leitor_csv
is also a Generator and needs to be started again. As I do not know the code of this module I can not be sure, but it is most likely.– fernandosavio
There is no way to "reset" Generator?
– JonP
Just call
leitor_csv.leitor(address_file,"dicionario")
again.– fernandosavio