Commit 032db7f774b17ced69d3fc87acc8eef725cfe204

Authored by Stéphane Raimbault
1 parent 46ecda7e

Minor changes about baud rate setting

modbus/modbus.c
... ... @@ -1243,18 +1243,18 @@ int report_slave_id(modbus_param_t *mb_param, int slave,
1243 1243  
1244 1244 /* Initializes the modbus_param_t structure for RTU
1245 1245 - device: "/dev/ttyS0"
1246   - - baud: 19200
  1246 + - baud: 9600, 19200, 57600, 115200, etc
1247 1247 - parity: "even", "odd" or "none"
1248 1248 - data_bits: 5, 6, 7, 8
1249 1249 - stop_bits: 1, 2
1250 1250 */
1251 1251 void modbus_init_rtu(modbus_param_t *mb_param, char *device,
1252   - int baud_i, char *parity, int data_bit,
  1252 + int baud, char *parity, int data_bit,
1253 1253 int stop_bit)
1254 1254 {
1255 1255 memset(mb_param, 0, sizeof(modbus_param_t));
1256 1256 strcpy(mb_param->device, device);
1257   - mb_param->baud_i = baud_i;
  1257 + mb_param->baud = baud;
1258 1258 strcpy(mb_param->parity, parity);
1259 1259 mb_param->debug = FALSE;
1260 1260 mb_param->data_bit = data_bit;
... ... @@ -1309,11 +1309,11 @@ void modbus_set_error_handling(modbus_param_t *mb_param, error_handling_t error_
1309 1309 static int modbus_connect_rtu(modbus_param_t *mb_param)
1310 1310 {
1311 1311 struct termios tios;
1312   - speed_t baud_rate;
  1312 + speed_t speed;
1313 1313  
1314 1314 if (mb_param->debug) {
1315 1315 printf("Opening %s at %d bauds (%s)\n",
1316   - mb_param->device, mb_param->baud_i, mb_param->parity);
  1316 + mb_param->device, mb_param->baud, mb_param->parity);
1317 1317 }
1318 1318  
1319 1319 /* The O_NOCTTY flag tells UNIX that this program doesn't want
... ... @@ -1326,7 +1326,7 @@ static int modbus_connect_rtu(modbus_param_t *mb_param)
1326 1326 mb_param->fd = open(mb_param->device, O_RDWR | O_NOCTTY | O_NDELAY);
1327 1327 if (mb_param->fd < 0) {
1328 1328 perror("open");
1329   - printf("ERROR Opening device %s (no : %d)\n",
  1329 + printf("ERROR Can't open the device %s (errno %d)\n",
1330 1330 mb_param->device, errno);
1331 1331 return -1;
1332 1332 }
... ... @@ -1339,49 +1339,49 @@ static int modbus_connect_rtu(modbus_param_t *mb_param)
1339 1339 /* C_ISPEED Input baud (new interface)
1340 1340 C_OSPEED Output baud (new interface)
1341 1341 */
1342   - switch (mb_param->baud_i) {
  1342 + switch (mb_param->baud) {
1343 1343 case 110:
1344   - baud_rate = B110;
  1344 + speed = B110;
1345 1345 break;
1346 1346 case 300:
1347   - baud_rate = B300;
  1347 + speed = B300;
1348 1348 break;
1349 1349 case 600:
1350   - baud_rate = B600;
  1350 + speed = B600;
1351 1351 break;
1352 1352 case 1200:
1353   - baud_rate = B1200;
  1353 + speed = B1200;
1354 1354 break;
1355 1355 case 2400:
1356   - baud_rate = B2400;
  1356 + speed = B2400;
1357 1357 break;
1358 1358 case 4800:
1359   - baud_rate = B4800;
  1359 + speed = B4800;
1360 1360 break;
1361 1361 case 9600:
1362   - baud_rate = B9600;
  1362 + speed = B9600;
1363 1363 break;
1364 1364 case 19200:
1365   - baud_rate = B19200;
  1365 + speed = B19200;
1366 1366 break;
1367 1367 case 38400:
1368   - baud_rate = B38400;
  1368 + speed = B38400;
1369 1369 break;
1370 1370 case 57600:
1371   - baud_rate = B57600;
  1371 + speed = B57600;
1372 1372 break;
1373 1373 case 115200:
1374   - baud_rate = B115200;
  1374 + speed = B115200;
1375 1375 break;
1376 1376 default:
1377   - baud_rate = B9600;
  1377 + speed = B9600;
1378 1378 printf("WARNING Unknown baud rate %d for %s (B9600 used)\n",
1379   - mb_param->baud_i, mb_param->device);
  1379 + mb_param->baud, mb_param->device);
1380 1380 }
1381 1381  
1382 1382 /* Set the baud rate */
1383   - if ((cfsetispeed(&tios, baud_rate) < 0) ||
1384   - (cfsetospeed(&tios, baud_rate) < 0)) {
  1383 + if ((cfsetispeed(&tios, speed) < 0) ||
  1384 + (cfsetospeed(&tios, speed) < 0)) {
1385 1385 perror("cfsetispeed/cfsetospeed\n");
1386 1386 return -1;
1387 1387 }
... ...
modbus/modbus.h
... ... @@ -130,8 +130,8 @@ typedef struct {
130 130  
131 131 /* Parity: "even", "odd", "none" */
132 132 char parity[5];
133   - /* Bauds: 19200 */
134   - int baud_i;
  133 + /* Bauds: 9600, 19200, 57600, 115200, etc */
  134 + int baud;
135 135 /* Data bit */
136 136 int data_bit;
137 137 /* Stop bit */
... ... @@ -211,7 +211,7 @@ int report_slave_id(modbus_param_t *mb_param, int slave, uint8_t *dest);
211 211  
212 212 /* Initializes the modbus_param_t structure for RTU.
213 213 - device: "/dev/ttyS0"
214   - - baud: 19200
  214 + - baud: 9600, 19200, 57600, 115200, etc
215 215 - parity: "even", "odd" or "none"
216 216 - data_bits: 5, 6, 7, 8
217 217 - stop_bits: 1, 2
... ...