Hello RuiP, first of all you should test if the program works correctly.
For example I tested this from the Terminal in the raspberry pi :
sdm120c -a 1 -p -q -b 9600 -P N -S 1 -2 /dev/ttyUSB0
sdm120c -a 1 -b 9600 -P N -S 1 -2 /dev/ttyUSB0
sdm120c -a 1 -d 1 -x -p -q -b 9600 -P N -S 1 -2 /dev/ttyUSB0
Then I used this script:
#!/usr/bin/python
import threading, time, subprocess, logging, minimalmodbus
from apscheduler.schedulers.background import BackgroundScheduler
from time import sleep
SDM220 = minimalmodbus.Instrument('/dev/ttyUSB0', 1)
SDM220.serial.baudrate = 9600
SDM220.serial.bytesize = 8
SDM220.serial.parity = minimalmodbus.serial.PARITY_NONE
SDM220.serial.stopbits = 1
SDM220.serial.timeout = 1
SDM220.debug = False
SDM220.mode = minimalmodbus.MODE_RTU
print SDM220
def read_SDM220_meter():
Volts = rs485.read_float(0, functioncode=4, numberOfRegisters=2)
Current = rs485.read_float(6, functioncode=4, numberOfRegisters=2)
Active_Power = rs485.read_float(12, functioncode=4, numberOfRegisters=2)
Apparent_Power = rs485.read_float(18, functioncode=4, numberOfRegisters=2)
Reactive_Power = rs485.read_float(24, functioncode=4, numberOfRegisters=2)
Power_Factor = rs485.read_float(30, functioncode=4, numberOfRegisters=2)
Phase_Angle = rs485.read_float(36, functioncode=4, numberOfRegisters=2)
Frequency = rs485.read_float(70, functioncode=4, numberOfRegisters=2)
Import_Active_Energy = rs485.read_float(72, functioncode=4, numberOfRegisters=2)
Export_Active_Energy = rs485.read_float(74, functioncode=4, numberOfRegisters=2)
Import_Reactive_Energy = rs485.read_float(76, functioncode=4, numberOfRegisters=2)
Export_Reactive_Energy = rs485.read_float(78, functioncode=4, numberOfRegisters=2)
Total_Active_Energy = rs485.read_float(342, functioncode=4, numberOfRegisters=2)
Total_Reactive_Energy = rs485.read_float(344, functioncode=4, numberOfRegisters=2)
file = open('/tmp/meter_data.txt', 'w+')
file.write(time.strftime('%Y%m%d %X '))
file.write('{} {} {} {} {} {} {} {} {} {} {} {} {} {}\n'.format(Volts, Current, Active_Power, Apparent_Power, Reactive_Power, Power_Factor, Phase_Angle, Frequency, Import_Active_Energy, Export_Active_Energy, Import_Reactive_Energy, Export_Reactive_Energy, Total_Active_Energy, Total_Reactive_Energy))
file.close()
#subprocess.call('/opt/send-to-eorg.sh') # call the bash file to transmit the data
I hope this helps!
Regards,