Paul,
Many thanks.
I have now hit a blocker as I cannot seem to get any comms from the device. There is continuity on the wires at the terminals on the meter and usb connector block. I have tried reversing the wires I started with 23 TX+ to A and 24 TX- to B called my very simple program and as you can see no comms.
No idea how to test the usb adaptor. It seems to be recognised and configured as /dev/ttyUSB0. From the DDSD285 spec sheet it says that EVEN parity, 1 Stop Bit is required and 9600 baud. The print statement looks correct to open the port with the correct parameters (not sure if there would be an error if it could not open the port) then trying to talk to the meter using the instrument.read.float calls results in no comms, this device seems to use mode 4 for read and 6 for write.
pi@emonpi:~/DDSD285 $ lsusb
**Bus 001 Device 007: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light**
Bus 001 Device 005: ID 045e:07a5 Microsoft Corp. Wireless Receiver 1461C
Bus 001 Device 006: ID 0424:7800 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Result of running the very simple program.
pi@emonpi:~/DDSD285 $ python ddsd285-test.py
minimalmodbus.Instrument<id=0x76aae580, address=1, mode=rtu, close_port_after_each_call=False, precalculate_read_size=True, debug=False, serial=Serial<id=0x76acdef0, open=True>(port='/dev/ttyUSB0', baudrate=9600, bytesize=8, parity='E', stopbits=1, timeout=0.05, xonxoff=False, rtscts=False, dsrdtr=False)>
Traceback (most recent call last):
File "ddsd285-test.py", line 29, in <module>
main()
File "ddsd285-test.py", line 25, in main
get_data()
File "ddsd285-test.py", line 18, in get_data
TOTAMPS = round(instrument.read_float(31537), 4) # Total Amps AMPS
File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 392, in read_float
return self._genericCommand(functioncode, registeraddress, numberOfRegisters=numberOfRegisters, payloadformat='float')
File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 697, in _genericCommand
payloadFromSlave = self._performCommand(functioncode, payloadToSlave)
File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 795, in _performCommand
response = self._communicate(request, number_of_bytes_to_read)
File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 930, in _communicate
raise IOError('No communication with the instrument (no answer)')
IOError: No communication with the instrument (no answer)
The program:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import minimalmodbus
instrument = minimalmodbus.Instrument("/dev/ttyUSB0", 1)
instrument.serial.baudrate = 9600
#instrument.serial.bytesize = 8
instrument.serial.parity = minimalmodbus.serial.PARITY_EVEN
#instrument.serial.parity = 'E'
instrument.serial.stopbits = 1
instrument.serial.timeout = 0.05 # seconds
#instrument.address = 1 # this is the slave address number
#instrument.mode = minimalmodbus.MODE_RTU # rtu or ascii mode
print instrument
def get_data():
TOTAMPS = round(instrument.read_float(31537), 4) # Total Amps AMPS
TOTPWR = round(instrument.read_float(31539), 4) # Total Power WATTS
TOTAPPWR = round(instrument.read_float(31541), 4) # Total Apparent Power KVA
print('{} Amps {} Watts {} Kva\n'.format(TOTAMPS,TOTPWR,TOTAPPWR))
def main():
get_data()
if __name__ == '__main__':
main()
exit()
Any idea what I might be doing wrong or how to test of the USB device is actually working?
Hardware checks seem to look fine. If I unplug the USB device and replug it seems to be enumerated correctly.
Feb 4 21:55:14 emonpi kernel: [ 4023.118365] cp210x 1-1.2:1.0: device disconnected
Feb 4 21:55:20 emonpi kernel: [ 4029.298476] usb 1-1.2: new full-speed USB device number 9 using dwc_otg
Feb 4 21:55:20 emonpi kernel: [ 4029.433207] usb 1-1.2: New USB device found, idVendor=10c4, idProduct=ea60
Feb 4 21:55:20 emonpi kernel: [ 4029.433224] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Feb 4 21:55:20 emonpi kernel: [ 4029.433233] usb 1-1.2: Product: CP2104 USB to UART Bridge Controller
Feb 4 21:55:20 emonpi kernel: [ 4029.433241] usb 1-1.2: Manufacturer: Silicon Labs
Feb 4 21:55:20 emonpi kernel: [ 4029.433250] usb 1-1.2: SerialNumber: 018DF162
Feb 4 21:55:20 emonpi kernel: [ 4029.437095] cp210x 1-1.2:1.0: cp210x converter detected
Feb 4 21:55:21 emonpi kernel: [ 4029.440705] usb 1-1.2: cp210x converter now attached to ttyUSB0
There appears to be a valid kernel module for it:
pi@emonpi:~/DDSD285 $ lsmod | grep cp210
cp210x 24576 0
usbserial 40960 1 cp210x
Cheers
Tony