Git Product home page Git Product logo

sdm120c's Introduction

SDM120C

SDM120C ModBus RTU client to read EASTRON SDM smart mini power meter registers

It depends on libmodbus (http://libmodbus.org)

To compile make clean && make

To install make install

To uninstall make uninstall

# SDM120C
SDM120C ModBus RTU client to read EASTRON SDM120C smart mini power meter registers

It works with SDM120C and SDM220 models

It depends on libmodbus (http://libmodbus.org)

To compile and install
  make clean && make install

Usage: sdm120c [-a address] [-d] [-x] [-p] [-v] [-c] [-e] [-i] [-t] [-f] [-g] [-T] [[-m]|[-q]] [-b baud_rate] [-P parity] [-S bit] [-z num_retries] [-j seconds] [-w seconds] [-1 | -2] device
       sdm120c [-a address] [-d] [-b baud_rate] [-P parity] [-S bit] [-1 | -2] -s new_address device
       sdm120c [-a address] [-d] [-b baud_rate] [-P parity] [-S bit] [-1 | -2] -r baud_rate device 
       sdm120c [-a address] [-d] [-b baud_rate] [-P parity] [-S bit] [-1 | -2] -R new_time device

where
    -a address     Meter number (between 1 and 247). Default: 1
    -s new_address Set new meter number (between 1 and 247)
    -p             Get power (W)
    -v             Get voltage (V)
    -c             Get current (A)
    -f             Get frequency (Hz)
    -g             Get power factor
    -e             Get exported energy (Wh)
    -i             Get imported energy (Wh)
    -t             Get total energy (Wh)
    -T             Get Time for rotating display values (0 = no rotation) 
    -d             Debug
    -x             Trace (libmodbus debug on)
    -b baud_rate   Use baud_rate serial port speed (1200, 2400, 4800, 9600)
                   Default: 2400
    -P parity      Use parity (E, N, O)
    -S bit         Use stop bits (1, 2). Default: 1
    -r baud_rate   Set baud_rate meter speed (1200, 2400, 4800, 9600)
    -R new_time    Change rotation time for displaying values (0 - 30s) (0 = no totation)
    -m             Output values in IEC 62056 format ID(VALUE*UNIT)
    -q             Output values in compact mode
    -z num_retries Try to read max num_retries times on bus before exiting
                   with error. Default: 1 (no retry)
    -j 1/10 secs   Response timeout. Default: 2=0.2s
    -D 1/1000 secs Delay before sending commands (wait line set). Default: 30=0.03s
    -w seconds     Time to wait to lock serial port. (1-30s) Default: 0s
    -1             Model: SDM120C (default)
    -2             Model: SDM220
    device         Serial device, i.e. /dev/ttyUSB0

Serial device is required. When no parameter is passed, retrives all values

sdm120c's People

Contributors

gianfrdp avatar leenx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sdm120c's Issues

Support for SDM630M and SDM530M

update to last version

Hello I have installaed v1.3.5.4, fount on /hom/pi/SDM120C how I can update to last version?

sdm120c 1.3.5.4

After a compleet new installation on Raspi 3B+ with Domoticz V4.97 there is no responds from the USB0 port.

This is my code:
SERVER="http://192.168.178.31:8080/json.htm?type=command" #server location
ID_01=121 #id of "Energie Solar"
IDT=122 #id of "Energie Woning totaal"
IDF=123 #id of "Energie Woning voor"
IDB=124 #id of "Energie Woning achter"

AESTRON SDM220C Solar Energy Production ..........

VALUES=NOK # if Not Oké
echo $VALUES #Debugging line
while [ "$VALUES" = "NOK" ]
do # reading from meter sdm220 modbus device nr 1 option -a 1
VALUES=/home/pi/SDM120C/sdm120c -a 1 -d 1 -b 9600 -P N -S 1 -p -t -q -2 -x /dev/ttyUSB0 #p=power / t=total / q=short output
echo "--------------------------------------------------"
echo $VALUES #Debugging line
echo "=================================================="
done
POWER=echo $VALUES | cut -d ' ' -f1
TOTAL=echo $VALUES | cut -d ' ' -f2

echo $POWER $TOTAL

update domoticz device with solar energy

curl -s $SERVER"&param=udevice&idx="$ID_01"&nvalue=0&svalue="$POWER";"$TOTAL  #send current to domoticz

This worked before 100%

sdm220.zip

output.txt

sdm120D support

Hi,
I dont know if sdm120D is supported but 120C is not available anywhere :(
This is the debug log from my raspberry
root@raspberrypi:/home/pi/SDM120C# sdm120c /dev/ttyUSB0 -d 1 -j 500
20190116-14:28:05.524938: sdm120c(20895) debug_flag = 1
20190116-14:28:05.529160: sdm120c(20895) optind = 6, argc = 6, c = j, optarg = 500
20190116-14:28:05.536952: sdm120c(20895) resp_timeout = 500, count_param = 0
20190116-14:28:05.539022: sdm120c(20895) cmdline="sdm120c /dev/ttyUSB0 -d 1 -j 500"
20190116-14:28:05.541396: sdm120c(20895) szttyDevice: /dev/ttyUSB0
20190116-14:28:05.542654: sdm120c(20895) devLCKfile: </var/lock/LCK..ttyUSB0>
20190116-14:28:05.543008: sdm120c(20895) devLCKfileNew: </var/lock/LCK..ttyUSB0.20895>
20190116-14:28:05.544290: sdm120c(20895) PID: 20895
20190116-14:28:05.545681: sdm120c(20895) Attempting to get lock on Serial Port /dev/ttyUSB0...
20190116-14:28:05.546192: sdm120c(20895) Acquiring shared lock on /var/lock/LCK..ttyUSB0...
20190116-14:28:05.550263: sdm120c(20895) Shared lock on /var/lock/LCK..ttyUSB0 acquired...
20190116-14:28:05.551869: sdm120c(20895) Checking for lock
20190116-14:28:05.553679: sdm120c(20895) errno=0, bRead=2 PID=20895 LckPID=20895
20190116-14:28:05.555865: sdm120c(20895) Checking process 20895 (sdm120c) for lock
20190116-14:28:05.556422: sdm120c(20895) PID: 20895 COMMAND: "sdm120c" LckPID: 20895 LckCOMMAND: "sdm120c" LckPIDcommand "sdm120c" = me
20190116-14:28:05.559713: sdm120c(20895) Appears we got the lock.
20190116-14:28:05.564560: sdm120c(20895) resp_timeout=50000000us
20190116-14:28:05.565931: sdm120c(20895) Libmodbus context open (2400E1)
20190116-14:28:05.567201: sdm120c(20895) Byte timeout disabled.
20190116-14:28:05.567618: sdm120c(20895) New response timeout: 0s, 50000000us
20190116-14:28:05.573172: sdm120c(20895) 1/1. Register Address 30001 [0000]
20190116-14:28:55.626041: sdm120c(20895) ERROR (110) Connection timed out, 1/1, Address 30001 [0000]
20190116-14:28:55.626406: sdm120c(20895) Response timeout gave up after 50050776us
20190116-14:28:55.629282: sdm120c(20895) devLCKfile: </var/lock/LCK..ttyUSB0>
20190116-14:28:55.631655: sdm120c(20895) devLCKfileNew: </var/lock/LCK..ttyUSB0.20895>
20190116-14:28:55.632706: sdm120c(20895) Clearing Serial Port Lock (20895)...
20190116-14:28:55.633129: sdm120c(20895) Acquiring exclusive lock on /var/lock/LCK..ttyUSB0...
20190116-14:28:55.634936: sdm120c(20895) Exclusive lock on /var/lock/LCK..ttyUSB0 acquired (0) Success...
20190116-14:28:55.635587: sdm120c(20895) cmdLen=7
20190116-14:28:55.635930: sdm120c(20895) cmdLen=7 COMMAND is not null
20190116-14:28:55.637315: sdm120c(20895) errno=0, bRead=2 LckPID=20895 PID=20895 COMMAND='sdm120c'
20190116-14:28:55.638663: sdm120c(20895) errno=0, bRead=-1 LckPID=20895 PID=0 COMMAND=''
20190116-14:28:55.639235: sdm120c(20895) Clearing Serial Port Lock done
NOK
20190116-14:28:55.641725: sdm120c(20895) NOK

How to check if the device (sdm120D) is valid?

Logging to syslog even if disabled

Hi,
I saw that sdm120c continues to log stuff into syslog, despite any value is given to the parameter -d.

For example, with this successfull call:

bash-4.4# sdm120c -a 1 -b 9600 -z 10 -i -p -v -c -f -g -P N -w 10 -j 10 -d 2 -q /dev/ttyUSB0
231.80 1.91 397.90 0.90 50.00 4142535 OK
bash-4.4#

This is what I found in syslog

Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: sdm120c v1.3.5.4
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: parent: bash(5035)
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: sdm120c -a 1 -b 9600 -z 10 -i -p -v -c -f -g -P N -w 10 -j 10 -d 2 -q /dev/ttyUSB0
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 3, argc = 23, c = a, optarg = 1
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: device_address = 1
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 5, argc = 23, c = b, optarg = 9600
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: speed = 9600, count_param = 0
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 7, argc = 23, c = z, optarg = 10
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: num_retries = 10, count_param = 0
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 8, argc = 23, c = i, optarg = 10
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: import_flag = 1, count_param = 0
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 9, argc = 23, c = p, optarg = 10
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: power_flag = 1, count_param = 2
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 10, argc = 23, c = v, optarg = 10
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: volt_flag = 1, count_param = 3
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 11, argc = 23, c = c, optarg = 10
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: current_flag = 1, count_param = 4
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 12, argc = 23, c = f, optarg = 10
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: freq_flag = 1, count_param = 5
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 13, argc = 23, c = g, optarg = 10
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: pf_flag = 1, count_param = 6
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 15, argc = 23, c = P, optarg = N
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: c_parity = N, count_param = 6
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 17, argc = 23, c = w, optarg = 10
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: yLockWait = 10, count_param = 6
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 19, argc = 23, c = j, optarg = 10
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: resp_timeout = 10, count_param = 6
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 21, argc = 23, c = d, optarg = 2
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: debug_flag = 0
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: optind = 22, argc = 23, c = q, optarg = 2
Mar 28 19:27:29 2cd5e925f69d sdm120c[17870]: compact_flag = 1, count_param = 6

Same behavior with -d 0

error when compiled

hello on ubuntu server after send command make clean && make
I get this error:

rm -f *.o sdm120c
gcc -c -o sdm120c.o sdm120c.c -O2 -Wall -g `pkg-config --cflags libmodbus`
sdm120c.c: In function ‘log_message’:
sdm120c.c:264:24: warning: format not a string literal and no format arguments [-Wformat-security]
        fprintf(stderr, buffer);
                        ^~~~~~
sdm120c.c:273:30: warning: format not a string literal and no format arguments [-Wformat-security]
             syslog(LOG_INFO, versionbuffer);
                              ^~~~~~~~~~~~~
sdm120c.c:276:30: warning: format not a string literal and no format arguments [-Wformat-security]
             syslog(LOG_INFO, parent);
                              ^~~~~~
sdm120c.c:277:30: warning: format not a string literal and no format arguments [-Wformat-security]
             syslog(LOG_INFO, cmdline);
                              ^~~~~~~
sdm120c.c:280:26: warning: format not a string literal and no format arguments [-Wformat-security]
         syslog(LOG_INFO, buffer);
                          ^~~~~~
gcc -o sdm120c sdm120c.o -O2 -Wall -g `pkg-config --libs libmodbus`
chmod 4711 sdm120c

what can I do?

-m output with different ID

Hello,

Is it possible to have different IDs for import/export/total meters with the -m output ? (like IMP, EXP, TOT)
The data could eventually mess-up since each meters should have a unique ID.

Thanks

specified bound depends on the length of the source argument [-Wstringop-overflow=]

By compiling the current master code with -O2 I get:

In file included from /usr/include/string.h:519,
                 from sdm120c.c:39:
In function 'strncpy',
    inlined from 'getPIDcmd' at sdm120c.c:822:9:
/usr/include/bits/string_fortified.h:95:10: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
   95 |   return __builtin___strncpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   96 |       __glibc_objsize (__dest));
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~
sdm120c.c: In function 'getPIDcmd':
sdm120c.c:820:12: note: length computed here
  820 |     cmdLen=strlen(buffer)+1;
      |            ^~~~~~~~~~~~~~

ERROR (110) Connection timed out

hello i'm a newbee and have a problem with the usb-serial connection with the SDM220.

i use a usb serial adapter (black stick with 2 connections for the modbus)

my loggings are:
pi@raspberrypi:~/SDM120C $ sudo sdm120c -a 1 -b9600 -PN -d1 -j500 -w30 /dev/ttyUSB0
20200525-23:47:32.569877: sdm120c(3746) debug_flag = 1
20200525-23:47:32.569970: sdm120c(3746) optind = 7, argc = 9, c = j, optarg = 500
20200525-23:47:32.570010: sdm120c(3746) resp_timeout = 500, count_param = 0
20200525-23:47:32.570050: sdm120c(3746) optind = 8, argc = 9, c = w, optarg = 30
20200525-23:47:32.570091: sdm120c(3746) yLockWait = 30, count_param = 0
20200525-23:47:32.570130: sdm120c(3746) cmdline="sdm120c -a 1 -b9600 -PN -d1 -j500 -w30 /dev/ttyUSB0"
20200525-23:47:32.570196: sdm120c(3746) szttyDevice: /dev/ttyUSB0
20200525-23:47:32.570230: sdm120c(3746) devLCKfile: </var/lock/LCK..ttyUSB0>
20200525-23:47:32.570264: sdm120c(3746) devLCKfileNew: </var/lock/LCK..ttyUSB0.3746>
20200525-23:47:32.570296: sdm120c(3746) PID: 3746
20200525-23:47:32.570471: sdm120c(3746) Attempting to get lock on Serial Port /dev/ttyUSB0...
20200525-23:47:32.570534: sdm120c(3746) Acquiring shared lock on /var/lock/LCK..ttyUSB0...
20200525-23:47:32.570585: sdm120c(3746) Shared lock on /var/lock/LCK..ttyUSB0 acquired...
20200525-23:47:32.570684: sdm120c(3746) Checking for lock
20200525-23:47:32.570852: sdm120c(3746) errno=0, bRead=2 PID=3746 LckPID=3746
20200525-23:47:32.570891: sdm120c(3746) Checking process 3746 (sdm120c) for lock
20200525-23:47:32.570967: sdm120c(3746) PID: 3746 COMMAND: "sdm120c" LckPID: 3746 LckCOMMAND: "sdm120c" LckPIDcommand "sdm120c" = me
20200525-23:47:32.571002: sdm120c(3746) Appears we got the lock.
20200525-23:47:32.571035: sdm120c(3746) resp_timeout=50000000us
20200525-23:47:32.571137: sdm120c(3746) Libmodbus context open (9600N2)
20200525-23:47:32.571179: sdm120c(3746) Byte timeout disabled.
20200525-23:47:32.571215: sdm120c(3746) New response timeout: 0s, 50000000us
20200525-23:47:32.575878: sdm120c(3746) 1/1. Register Address 30001 [0000]
20200525-23:47:33.076550: sdm120c(3746) ERROR (110) Connection timed out, 1/1, Address 30001 [0000]
20200525-23:47:33.076810: sdm120c(3746) Response timeout gave up after 500592us
20200525-23:47:33.080419: sdm120c(3746) devLCKfile: </var/lock/LCK..ttyUSB0>
20200525-23:47:33.080612: sdm120c(3746) devLCKfileNew: </var/lock/LCK..ttyUSB0.3746>
20200525-23:47:33.080797: sdm120c(3746) Clearing Serial Port Lock (3746)...
20200525-23:47:33.080994: sdm120c(3746) Acquiring exclusive lock on /var/lock/LCK..ttyUSB0...
20200525-23:47:33.081186: sdm120c(3746) Exclusive lock on /var/lock/LCK..ttyUSB0 acquired (0) Success...
20200525-23:47:33.081410: sdm120c(3746) cmdLen=7
20200525-23:47:33.081595: sdm120c(3746) cmdLen=7 COMMAND is not null
20200525-23:47:33.081708: sdm120c(3746) errno=0, bRead=2 LckPID=3746 PID=3746 COMMAND='sdm120c'
20200525-23:47:33.081812: sdm120c(3746) errno=0, bRead=-1 LckPID=3746 PID=0 COMMAND=''
20200525-23:47:33.081965: sdm120c(3746) Clearing Serial Port Lock done
NOK
20200525-23:47:33.082140: sdm120c(3746) NOK

can anyone give some help or tips please.

Connection timed out

I am trying to communicate with my SDM120-modbus. I am pretty sure I have wired everything correctly (B to 9 and A to 10), but somehow I cannot talk to the SDM120. This is the output I am getting:

ubuntu@ubuntu:~/smartmeter$ SDM120C/sdm120c -a 1 -b 9600 -e -p -q -z 3 -j 20 -d 1 /dev/ttyUSB2 
20210123-20:23:38.858984: SDM120C/sdm120c(32257) debug_flag = 1
20210123-20:23:38.859152: SDM120C/sdm120c(32257) cmdline="SDM120C/sdm120c -a 1 -b 9600 -e -p -q -z 3 -j 20 -d 1 /dev/ttyUSB2"
20210123-20:23:38.859270: SDM120C/sdm120c(32257) szttyDevice: /dev/ttyUSB2
20210123-20:23:38.859373: SDM120C/sdm120c(32257) devLCKfile: </var/lock/LCK..ttyUSB2>
20210123-20:23:38.859472: SDM120C/sdm120c(32257) devLCKfileNew: </var/lock/LCK..ttyUSB2.32257>
20210123-20:23:38.859572: SDM120C/sdm120c(32257) PID: 32257
20210123-20:23:38.859781: SDM120C/sdm120c(32257) Attempting to get lock on Serial Port /dev/ttyUSB2...
20210123-20:23:38.859944: SDM120C/sdm120c(32257) Acquiring shared lock on /var/lock/LCK..ttyUSB2...
20210123-20:23:38.860058: SDM120C/sdm120c(32257) Shared lock on /var/lock/LCK..ttyUSB2 acquired...
20210123-20:23:38.860308: SDM120C/sdm120c(32257) Checking for lock
20210123-20:23:38.860536: SDM120C/sdm120c(32257) errno=0, bRead=2 PID=32257 LckPID=32257
20210123-20:23:38.860704: SDM120C/sdm120c(32257) Checking process 32257 (SDM120C/sdm120c) for lock
20210123-20:23:38.860906: SDM120C/sdm120c(32257) PID: 32257 COMMAND: "SDM120C/sdm120c" LckPID: 32257 LckCOMMAND: "SDM120C/sdm120c" LckPIDcommand "SDM120C/sdm120c" = me
20210123-20:23:38.861006: SDM120C/sdm120c(32257) Appears we got the lock.
20210123-20:23:38.861103: SDM120C/sdm120c(32257) resp_timeout=2000000us
20210123-20:23:38.861209: SDM120C/sdm120c(32257) Libmodbus context open (9600E1)
20210123-20:23:38.861311: SDM120C/sdm120c(32257) Byte timeout disabled.
20210123-20:23:38.861413: SDM120C/sdm120c(32257) New response timeout: 0s, 2000000us
20210123-20:23:38.865284: SDM120C/sdm120c(32257) 1/3. Register Address 30013 [000C]
20210123-20:23:39.366133: SDM120C/sdm120c(32257) ERROR (110) Connection timed out, 1/3, Address 30013 [000C]
20210123-20:23:39.366340: SDM120C/sdm120c(32257) Response timeout gave up after 500634us
20210123-20:23:39.366485: SDM120C/sdm120c(32257) 2/3. Register Address 30013 [000C]
20210123-20:23:39.867357: SDM120C/sdm120c(32257) ERROR (110) Connection timed out, 2/3, Address 30013 [000C]
20210123-20:23:39.867538: SDM120C/sdm120c(32257) Response timeout gave up after 500668us
20210123-20:23:39.867682: SDM120C/sdm120c(32257) 3/3. Register Address 30013 [000C]
20210123-20:23:40.368541: SDM120C/sdm120c(32257) ERROR (110) Connection timed out, 3/3, Address 30013 [000C]
20210123-20:23:40.368763: SDM120C/sdm120c(32257) Response timeout gave up after 500658us
20210123-20:23:40.370568: SDM120C/sdm120c(32257) devLCKfile: </var/lock/LCK..ttyUSB2>
20210123-20:23:40.370722: SDM120C/sdm120c(32257) devLCKfileNew: </var/lock/LCK..ttyUSB2.32257> 
20210123-20:23:40.370848: SDM120C/sdm120c(32257) Clearing Serial Port Lock (32257)...
20210123-20:23:40.371056: SDM120C/sdm120c(32257) Acquiring exclusive lock on /var/lock/LCK..ttyUSB2...
20210123-20:23:40.371282: SDM120C/sdm120c(32257) Exclusive lock on /var/lock/LCK..ttyUSB2 acquired (0) Success...
20210123-20:23:40.371573: SDM120C/sdm120c(32257) cmdLen=15
20210123-20:23:40.371711: SDM120C/sdm120c(32257) cmdLen=15 COMMAND is not null
20210123-20:23:40.371940: SDM120C/sdm120c(32257) errno=0, bRead=2 LckPID=32257 PID=32257 COMMAND='SDM120C/sdm120c'
20210123-20:23:40.372080: SDM120C/sdm120c(32257) errno=0, bRead=-1 LckPID=32257 PID=0 COMMAND=''
20210123-20:23:40.372391: SDM120C/sdm120c(32257) Clearing Serial Port Lock done
NOK
20210123-20:23:40.372705: SDM120C/sdm120c(32257) NOK

The USB-modbus-RS485 device is located on /dev/ttyUSB2 (I checked this with dmesg). Any help would be appreciated!

Libmodbus 3.1.4 & SDM 120c on ARM

Hello,

I 've got trouble while installing SDM on my Odroid (ARMv7).
Installation of libmodbus 3.1.4 seems ok but SDM gives some errors.
See the history below...
What do you think about it ?
Thanks by advance for your answer.

root@odroid:/home/libmodbus/libmodbus-3.1.4# make install
Making install in src
/bin/mkdir -p '/usr/local/lib'
/bin/bash ../libtool --mode=install /usr/bin/install -c libmodbus.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libmodbus.so.5.1.0 /usr/local/lib/libmodbus.so.5.1.0
libtool: install: (cd /usr/local/lib && { ln -s -f libmodbus.so.5.1.0 libmodbus.so.5 || { rm -f libmodbus.so.5 && ln -s libmodbus.so.5.1.0 libmodbus.so.5; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libmodbus.so.5.1.0 libmodbus.so || { rm -f libmodbus.so && ln -s libmodbus.so.5.1.0 libm odbus.so; }; })
libtool: install: /usr/bin/install -c .libs/libmodbus.lai /usr/local/lib/libmodbus.la

libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/sbin" ldconfig -n /usr/loc al/lib

Libraries have been installed in:
/usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:

  • add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
    during execution
  • add LIBDIR to the 'LD_RUN_PATH' environment variable
    during linking
  • use the '-Wl,-rpath -Wl,LIBDIR' linker flag
  • have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

/bin/mkdir -p '/usr/local/include/modbus'
/usr/bin/install -c -m 644 modbus.h modbus-version.h modbus-rtu.h modbus-tcp.h '/usr/local/include/modbus'
Making install in doc
make[2]: Nothing to be done for install-exec-am'. Making install in tests make[2]: Nothing to be done forinstall-exec-am'.
make[2]: Nothing to be done for install-data-am'. make[2]: Nothing to be done forinstall-exec-am'.
/bin/mkdir -p '/usr/local/share/doc/libmodbus'
/usr/bin/install -c -m 644 MIGRATION README.md '/usr/local/share/doc/libmodbus'
/bin/mkdir -p '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 libmodbus.pc '/usr/local/lib/pkgconfig'
root@odroid:/home/libmodbus/libmodbus-3.1.4# cd ..
root@odroid:/home/libmodbus# cd ../SDM
root@odroid:/home/SDM# export LD_RUN_PATH=/usr/local/lib
root@odroid:/home/SDM# make clean
rm -f .o sdm120c
root@odroid:/home/SDM# make
gcc -c -o sdm120c.o sdm120c.c -O2 -Wall -g pkg-config --cflags libmodbus
gcc -c -o RS485_lock.o RS485_lock.c -O2 -Wall -g pkg-config --cflags libmodbus
gcc -c -o log.o log.c -O2 -Wall -g pkg-config --cflags libmodbus
log.c: In function ‘log_message’:
log.c:59:8: warning: format not a string literal and no format arguments [-Wformat-security]
fprintf(stderr, buffer);
^
log.c:68:13: warning: format not a string literal and no format arguments [-Wformat-security]
syslog(LOG_INFO, versionbuffer);
^
log.c:71:13: warning: format not a string literal and no format arguments [-Wformat-security]
syslog(LOG_INFO, parent);
^
log.c:72:13: warning: format not a string literal and no format arguments [-Wformat-security]
syslog(LOG_INFO, cmdline);
^
log.c:75:9: warning: format not a string literal and no format arguments [-Wformat-security]
syslog(LOG_INFO, buffer);
^
gcc -O2 -Wall -g pkg-config --libs libmodbus -o sdm120c sdm120c.o RS485_lock.o log.o
sdm120c.o: In function exit_error': /home/SDM/sdm120c.c:228: undefined reference tomodbus_close'
/home/SDM/sdm120c.c:229: undefined reference to modbus_free' sdm120c.o: In functiongetMeasureFloat':
/home/SDM/sdm120c.c:358: undefined reference to modbus_read_input_registers' /home/SDM/sdm120c.c:364: undefined reference tomodbus_strerror'
/home/SDM/sdm120c.c:363: undefined reference to modbus_strerror' /home/SDM/sdm120c.c:364: undefined reference tomodbus_strerror'
sdm120c.o: In function readRegisters': /home/SDM/sdm120c.c:452: undefined reference tomodbus_read_input_registers'
/home/SDM/sdm120c.c:458: undefined reference to modbus_strerror' /home/SDM/sdm120c.c:457: undefined reference tomodbus_strerror'
/home/SDM/sdm120c.c:458: undefined reference to modbus_strerror' sdm120c.o: In functiongetConfigBCD':
/home/SDM/sdm120c.c:509: undefined reference to modbus_read_registers' /home/SDM/sdm120c.c:512: undefined reference tomodbus_strerror'
sdm120c.o: In function changeConfigHex': /home/SDM/sdm120c.c:552: undefined reference tomodbus_write_registers'
/home/SDM/sdm120c.c:557: undefined reference to modbus_strerror' sdm120c.o: In functionchangeConfigFloat':
/home/SDM/sdm120c.c:568: undefined reference to modbus_set_float' /home/SDM/sdm120c.c:580: undefined reference tomodbus_write_registers'
/home/SDM/sdm120c.c:585: undefined reference to modbus_strerror' sdm120c.o: In functionchangeConfigBCD':
/home/SDM/sdm120c.c:603: undefined reference to modbus_write_registers' /home/SDM/sdm120c.c:608: undefined reference tomodbus_strerror'
sdm120c.o: In function main': /home/SDM/sdm120c.c:1044: undefined reference tomodbus_new_rtu'
/home/SDM/sdm120c.c:1065: undefined reference to modbus_set_byte_timeout' /home/SDM/sdm120c.c:1068: undefined reference tomodbus_set_response_timeout'
/home/SDM/sdm120c.c:1096: undefined reference to modbus_set_error_recovery' /home/SDM/sdm120c.c:1102: undefined reference tomodbus_connect'
/home/SDM/sdm120c.c:1118: undefined reference to modbus_set_slave' /home/SDM/sdm120c.c:1460: undefined reference tomodbus_close'
/home/SDM/sdm120c.c:1461: undefined reference to modbus_free' /home/SDM/sdm120c.c:1062: undefined reference tomodbus_set_byte_timeout'
/home/SDM/sdm120c.c:1227: undefined reference to modbus_close' /home/SDM/sdm120c.c:1228: undefined reference tomodbus_free'
/home/SDM/sdm120c.c:1210: undefined reference to modbus_close' /home/SDM/sdm120c.c:1211: undefined reference tomodbus_free'
/home/SDM/sdm120c.c:1099: undefined reference to modbus_set_debug' /home/SDM/sdm120c.c:1220: undefined reference tomodbus_close'
/home/SDM/sdm120c.c:1221: undefined reference to modbus_free' /home/SDM/sdm120c.c:1103: undefined reference tomodbus_strerror'
collect2: error: ld returned 1 exit status
make: *
* [sdm120c] Error 1
root@odroid:/home/SDM# sdm120c -a2 -b9600 -z3 -2 -qpievfg /dev/ttyUSB1
NOK

function declaration isn’t a prototype [-Wstrict-prototypes]

When compiled with -Wstrict-prototypes (that will be the default of the newer versions of compilers) we have:

sdm120c.c:214:7: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
  214 | char* getCurTime()
      |       ^~~~~~~~~~
sdm120c.c:234:6: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
  234 | void getCmdLine()
      |      ^~~~~~~~~~

Compiled at commit: f36fb38

sdm stuck /var/lock/LCK

Hello,
I use a script that infinitely call sdm120c (1.3.5.3) but it happen after several hours running that the application is stuck and leave the LCK file.
Is it possible to have a max time execution that properly shutdown sdm ?
thanks

undefined reference to `rnd_usleep' / `tv_diff'

I got compilation failure (maybe a because of a recent compiler):

$ cc -I/usr/include/modbus sdm120c.c -lmodbus
sdm120c.c: In function 'log_message':
sdm120c.c:264:24: warning: format not a string literal and no format arguments [-Wformat-security]
        fprintf(stderr, buffer);
                        ^~~~~~
sdm120c.c:273:30: warning: format not a string literal and no format arguments [-Wformat-security]
             syslog(LOG_INFO, versionbuffer);
                              ^~~~~~~~~~~~~
sdm120c.c:276:30: warning: format not a string literal and no format arguments [-Wformat-security]
             syslog(LOG_INFO, parent);
                              ^~~~~~
sdm120c.c:277:30: warning: format not a string literal and no format arguments [-Wformat-security]
             syslog(LOG_INFO, cmdline);
                              ^~~~~~~
sdm120c.c:280:26: warning: format not a string literal and no format arguments [-Wformat-security]
         syslog(LOG_INFO, buffer);
                          ^~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/cciVWOgy.o: in function `AddSerLock':
sdm120c.c:(.text+0xe00): undefined reference to `rnd_usleep'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/cciVWOgy.o: in function `getMeasureFloat':
sdm120c.c:(.text+0x12cb): undefined reference to `tv_diff'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: sdm120c.c:(.text+0x1348): undefined reference to `tv_diff'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/cciVWOgy.o: in function `lockSer':
sdm120c.c:(.text+0x20e0): undefined reference to `rnd_usleep'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: sdm120c.c:(.text+0x258f): undefined reference to `rnd_usleep'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: sdm120c.c:(.text+0x25ff): undefined reference to `tv_diff'
collect2: error: ld returned 1 exit status

$ cc -v
Using built-in specs.
COLLECT_GCC=cc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/8.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-8.3.0-r1/work/gcc-8.3.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/8.3.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/8.3.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/8.3.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/8.3.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include/g++-v8 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/8.3.0/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --disable-nls --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 8.3.0-r1 p1.1' --disable-esp --enable-libstdcxx-time --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-altivec --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libmudflap --disable-libssp --disable-libmpx --disable-systemtap --enable-vtable-verify --enable-lto --without-isl --disable-default-pie --disable-default-ssp
Thread model: posix
gcc version 8.3.0 (Gentoo 8.3.0-r1 p1.1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.