Commit cb692215fa200012e571595ba65a4e95b357ce21

Authored by Stéphane Raimbault
1 parent cef86fc2

Split POSIX and Windows RTU connect functions

Easier to read
Showing 1 changed file with 21 additions and 7 deletions
src/modbus-rtu.c
@@ -386,14 +386,10 @@ static int _modbus_rtu_check_integrity(modbus_t *ctx, uint8_t *msg, const int ms @@ -386,14 +386,10 @@ static int _modbus_rtu_check_integrity(modbus_t *ctx, uint8_t *msg, const int ms
386 } 386 }
387 387
388 /* Sets up a serial port for RTU communications */ 388 /* Sets up a serial port for RTU communications */
  389 +#if defined(_WIN32)
389 static int _modbus_rtu_connect(modbus_t *ctx) 390 static int _modbus_rtu_connect(modbus_t *ctx)
390 { 391 {
391 -#if defined(_WIN32)  
392 DCB dcb; 392 DCB dcb;
393 -#else  
394 - struct termios tios;  
395 - int flags;  
396 -#endif  
397 modbus_rtu_t *ctx_rtu = ctx->backend_data; 393 modbus_rtu_t *ctx_rtu = ctx->backend_data;
398 394
399 if (ctx->debug) { 395 if (ctx->debug) {
@@ -405,7 +401,6 @@ static int _modbus_rtu_connect(modbus_t *ctx) @@ -405,7 +401,6 @@ static int _modbus_rtu_connect(modbus_t *ctx)
405 ctx_rtu->stop_bit); 401 ctx_rtu->stop_bit);
406 } 402 }
407 403
408 -#if defined(_WIN32)  
409 /* Some references here: 404 /* Some references here:
410 * http://msdn.microsoft.com/en-us/library/aa450602.aspx 405 * http://msdn.microsoft.com/en-us/library/aa450602.aspx
411 */ 406 */
@@ -506,7 +501,26 @@ static int _modbus_rtu_connect(modbus_t *ctx) @@ -506,7 +501,26 @@ static int _modbus_rtu_connect(modbus_t *ctx)
506 ctx_rtu->w_ser.fd = INVALID_HANDLE_VALUE; 501 ctx_rtu->w_ser.fd = INVALID_HANDLE_VALUE;
507 return -1; 502 return -1;
508 } 503 }
  504 +
  505 + return 0;
  506 +}
509 #else 507 #else
  508 +/* POSIX */
  509 +static int _modbus_rtu_connect(modbus_t *ctx)
  510 +{
  511 + struct termios tios;
  512 + int flags;
  513 + modbus_rtu_t *ctx_rtu = ctx->backend_data;
  514 +
  515 + if (ctx->debug) {
  516 + printf("Opening %s at %d bauds (%c, %d, %d)\n",
  517 + ctx_rtu->device,
  518 + ctx_rtu->baud,
  519 + ctx_rtu->parity,
  520 + ctx_rtu->data_bit,
  521 + ctx_rtu->stop_bit);
  522 + }
  523 +
510 /* The O_NOCTTY flag tells UNIX that this program doesn't want 524 /* The O_NOCTTY flag tells UNIX that this program doesn't want
511 to be the "controlling terminal" for that port. If you 525 to be the "controlling terminal" for that port. If you
512 don't specify this then any input (such as keyboard abort 526 don't specify this then any input (such as keyboard abort
@@ -720,10 +734,10 @@ static int _modbus_rtu_connect(modbus_t *ctx) @@ -720,10 +734,10 @@ static int _modbus_rtu_connect(modbus_t *ctx)
720 ctx->s = -1; 734 ctx->s = -1;
721 return -1; 735 return -1;
722 } 736 }
723 -#endif  
724 737
725 return 0; 738 return 0;
726 } 739 }
  740 +#endif
727 741
728 // FIXME Temporary solution before rewriting Windows RTU backend 742 // FIXME Temporary solution before rewriting Windows RTU backend
729 static unsigned int _modbus_rtu_is_connected(modbus_t *ctx) 743 static unsigned int _modbus_rtu_is_connected(modbus_t *ctx)