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 386 }
387 387  
388 388 /* Sets up a serial port for RTU communications */
  389 +#if defined(_WIN32)
389 390 static int _modbus_rtu_connect(modbus_t *ctx)
390 391 {
391   -#if defined(_WIN32)
392 392 DCB dcb;
393   -#else
394   - struct termios tios;
395   - int flags;
396   -#endif
397 393 modbus_rtu_t *ctx_rtu = ctx->backend_data;
398 394  
399 395 if (ctx->debug) {
... ... @@ -405,7 +401,6 @@ static int _modbus_rtu_connect(modbus_t *ctx)
405 401 ctx_rtu->stop_bit);
406 402 }
407 403  
408   -#if defined(_WIN32)
409 404 /* Some references here:
410 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 501 ctx_rtu->w_ser.fd = INVALID_HANDLE_VALUE;
507 502 return -1;
508 503 }
  504 +
  505 + return 0;
  506 +}
509 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 524 /* The O_NOCTTY flag tells UNIX that this program doesn't want
511 525 to be the "controlling terminal" for that port. If you
512 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 734 ctx->s = -1;
721 735 return -1;
722 736 }
723   -#endif
724 737  
725 738 return 0;
726 739 }
  740 +#endif
727 741  
728 742 // FIXME Temporary solution before rewriting Windows RTU backend
729 743 static unsigned int _modbus_rtu_is_connected(modbus_t *ctx)
... ...