Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
sdk:scripts:modbus-tcp-rtu-gateway [2022/07/11 08:02]
klueppel
sdk:scripts:modbus-tcp-rtu-gateway [2022/09/05 12:07]
schmitt
Line 2: Line 2:
 <code c modbus-tcp-rtu-gateway.are>​ <code c modbus-tcp-rtu-gateway.are>​
 /* DESC: This script implements a Modbus TCP RTU gateway /* DESC: This script implements a Modbus TCP RTU gateway
- * Copyright (C) 2015-2022 NetModule AG, Switzerland+ * Copyright (C) 2015-2016 NetModule AG, Switzerland
  */  */
 DEVIDX ​     = 0; DEVIDX ​     = 0;
 DEV         = sprintf("​SERIAL%d",​ (DEVIDX + 1)); DEV         = sprintf("​SERIAL%d",​ (DEVIDX + 1));
 TCP_PORT ​   = 1502; TCP_PORT ​   = 1502;
-DEBUG       = 0; 
- 
- 
  
 /* check serial port config */ /* check serial port config */
Line 19: Line 16:
  
 /* set attributes */ /* set attributes */
-ret = nb_serial_setattr(DEV, ​115200, 8, 1, 0, 0);+ret = nb_serial_setattr(DEV, ​19200, 8, 1, 0, 0);
 if (ret != 0) { if (ret != 0) {
     nb_syslog("​Could not set serial attributes: %d", ret);     nb_syslog("​Could not set serial attributes: %d", ret);
Line 61: Line 58:
     exit(1);     exit(1);
 } }
-if (DEBUG == 1) { +
-    nb_modbus_set_debug(serial_fd,​ true);  +
-}    ​+
 printf("​Listening for connections on port %d\n", TCP_PORT); printf("​Listening for connections on port %d\n", TCP_PORT);
- 
  
 tcp_client = -1; tcp_client = -1;
 registered = 0; registered = 0;
- 
  
 while (1) { while (1) {
Line 78: Line 71:
             sleep(1);             sleep(1);
             continue;             continue;
-        ​} else { +        } 
-            if (DEBUG == 1) { +
-                nb_modbus_set_debug(tcp_client,​ true); +
-            } +
-        ​}+
     }     }
  
Line 111: Line 100:
             nb_syslog("​Unable to extract payload (%s)", nb_modbus_last_error());​             nb_syslog("​Unable to extract payload (%s)", nb_modbus_last_error());​
         } else {         } else {
-            /* Modbus TCP - RTU must set the slave id */    ​ 
-       ​  ​   ret = nb_modbus_set_slave (serial_fd, payload[0]);​ 
-            if (ret > 0) { 
-                nb_syslog("​Unable to set modbus slave id"); 
-                break; 
-            } 
- 
             response = nb_modbus_send_raw(serial_fd,​ payload);             response = nb_modbus_send_raw(serial_fd,​ payload);
             if (is_void(response)) {             if (is_void(response)) {