0

上周我将单相表 sdm120 连接到树莓派。下面的代码可以找到。

但是,当我现在尝试连接到 DDS024MR 仪表时,它显示根本没有通信。我尝试更改端口等。我做错了什么?请帮我。

#!/usr/bin/env python3

import time
import minimalmodbus

rs485 = minimalmodbus.Instrument('/dev/ttyUSB0', 1)
rs485.serial.baudrate = 1800
rs485.serial.bytesize = 8
rs485.serial.parity = minimalmodbus.serial.PARITY_EVEN
rs485.serial.stopbits = 1
rs485.serial.timeout = 1
rs485.debug = False
rs485.mode = minimalmodbus.MODE_RTU
print (rs485)

Volts_A = rs485.read_float(0, functioncode=4, number_of_registers=4)
#Volts_B = rs485.read_float(2, functioncode=4, number_of_registers=2)
#Volts_C = rs485.read_float(4, `functioncode`=4, number_of_registers=2)
#Current_A = rs485.read_float(8, functioncode=4, number_of_registers=2)
#Current_B = rs485.read_float(0A, functioncode=10, number_of_registers=2)
#Current_C = rs485.read_float(0C, functioncode=10, number_of_registers=2)
#Active_PowerA = rs485.read_float(10, functioncode=10, number_of_registers=2)
#Reactive_PowerA = rs485.read_float(1A, functioncode=10, number_of_registers=2)
#Power_Factor = rs485.read_float(2A, functioncode=10, number_of_registers=2)
#Frequency = rs485.read_float(36, functioncode=4, number_of_registers=4)
#Total_Active_Energy = rs485.read_float(00, functioncode=10, number_of_registers=2)
#Total_Reactive_Energy = rs485.read_float(00, functioncode=10, number_of_registers=2)

print ('Voltage: {0:.1f} Volts'.format(Volts_A))
#print ('Voltage: {0:.1f} Volts'.format(Volts_B))
#print ('Voltage: {0:.1f} Volts'.format(Volts_C))
#print ('Current: {0:.1f} Amps'.format(Current_A))
#print ('Current: {0:.1f} Amps'.format(Current_B))
#print ('Current: {0:.1f} Amps'.format(Current_C))
#print ('Active power: {0:.1f} Watts'.format(Active_Power))
#print ('Reactive power: {0:.1f} VAr'.format(Reactive_Power))
#print ('Power factor: {0:.1f}'.format(Power_Factor))
#print ('Frequency: {0:.1f} Hz'.format(Frequency))
#print ('Total active energy: {0:.3f} kwh'.format(Total_Active_Energy))
#print ('Total reactive energy: {0:.3f} kvarh'.format(Total_Reactive_Energy))
#print ('Current Yield (V*A): {0:.1f} Watt'.format(Volts * Current))
4

0 回答 0