@@ -323,15 +323,15 @@ static ssize_t _modbus_rtu_send(modbus_t *ctx, const uint8_t *req, int req_lengt
323
323
DWORD n_bytes = 0 ;
324
324
return (WriteFile (ctx_rtu->w_ser .fd , req, req_length, &n_bytes, NULL )) ? (ssize_t )n_bytes : -1 ;
325
325
#elif defined(ARDUINO)
326
- ( void )ctx;
326
+ modbus_rtu_t *ctx_rtu = ( modbus_rtu_t * )ctx-> backend_data ;
327
327
328
328
ssize_t size;
329
329
330
- RS485. noReceive ();
331
- RS485. beginTransmission ();
332
- size = RS485. write (req, req_length);
333
- RS485. endTransmission ();
334
- RS485. receive ();
330
+ ctx_rtu-> rs485 -> noReceive ();
331
+ ctx_rtu-> rs485 -> beginTransmission ();
332
+ size = ctx_rtu-> rs485 -> write (req, req_length);
333
+ ctx_rtu-> rs485 -> endTransmission ();
334
+ ctx_rtu-> rs485 -> receive ();
335
335
336
336
return size;
337
337
#else
@@ -394,9 +394,9 @@ static ssize_t _modbus_rtu_recv(modbus_t *ctx, uint8_t *rsp, int rsp_length)
394
394
#if defined(_WIN32)
395
395
return win32_ser_read (&((modbus_rtu_t *)ctx->backend_data )->w_ser , rsp, rsp_length);
396
396
#elif defined(ARDUINO)
397
- ( void )ctx;
397
+ modbus_rtu_t *ctx_rtu = ( modbus_rtu_t * )ctx-> backend_data ;
398
398
399
- return RS485. readBytes (rsp, rsp_length);
399
+ return ctx_rtu-> rs485 -> readBytes (rsp, rsp_length);
400
400
#else
401
401
return read (ctx->s , rsp, rsp_length);
402
402
#endif
@@ -654,8 +654,8 @@ static int _modbus_rtu_connect(modbus_t *ctx)
654
654
return -1 ;
655
655
}
656
656
#elif defined(ARDUINO)
657
- RS485. begin (ctx_rtu->baud , ctx_rtu->config );
658
- RS485. receive ();
657
+ ctx_rtu-> rs485 -> begin (ctx_rtu->baud , ctx_rtu->config );
658
+ ctx_rtu-> rs485 -> receive ();
659
659
#else
660
660
/* The O_NOCTTY flag tells UNIX that this program doesn't want
661
661
to be the "controlling terminal" for that port. If you
@@ -1210,8 +1210,8 @@ static void _modbus_rtu_close(modbus_t *ctx)
1210
1210
#elif defined(ARDUINO)
1211
1211
(void )ctx_rtu;
1212
1212
1213
- RS485. noReceive ();
1214
- RS485. end ();
1213
+ ctx_rtu-> rs485 -> noReceive ();
1214
+ ctx_rtu-> rs485 -> end ();
1215
1215
#else
1216
1216
if (ctx->s != -1 ) {
1217
1217
tcsetattr (ctx->s , TCSANOW, &ctx_rtu->old_tios );
@@ -1228,10 +1228,10 @@ static int _modbus_rtu_flush(modbus_t *ctx)
1228
1228
ctx_rtu->w_ser .n_bytes = 0 ;
1229
1229
return (PurgeComm (ctx_rtu->w_ser .fd , PURGE_RXCLEAR) == FALSE );
1230
1230
#elif defined(ARDUINO)
1231
- ( void )ctx;
1231
+ modbus_rtu_t *ctx_rtu = ( modbus_rtu_t * )ctx-> backend_data ;
1232
1232
1233
- while (RS485. available ()) {
1234
- RS485. read ();
1233
+ while (ctx_rtu-> rs485 -> available ()) {
1234
+ ctx_rtu-> rs485 -> read ();
1235
1235
}
1236
1236
1237
1237
return 0 ;
@@ -1256,14 +1256,14 @@ static int _modbus_rtu_select(modbus_t *ctx, fd_set *rset,
1256
1256
return -1 ;
1257
1257
}
1258
1258
#elif defined(ARDUINO)
1259
- ( void )ctx;
1259
+ modbus_rtu_t *ctx_rtu = ( modbus_rtu_t * )ctx-> backend_data ;
1260
1260
(void )rset;
1261
1261
1262
1262
unsigned long wait_time_millis = (tv == NULL ) ? 0 : (tv->tv_sec * 1000 ) + (tv->tv_usec / 1000 );
1263
1263
unsigned long start = millis ();
1264
1264
1265
1265
do {
1266
- s_rc = RS485. available ();
1266
+ s_rc = ctx_rtu-> rs485 -> available ();
1267
1267
1268
1268
if (s_rc >= length_to_read) {
1269
1269
break ;
@@ -1330,7 +1330,7 @@ const modbus_backend_t _modbus_rtu_backend = {
1330
1330
};
1331
1331
1332
1332
#ifdef ARDUINO
1333
- modbus_t * modbus_new_rtu (unsigned long baud, uint16_t config)
1333
+ modbus_t * modbus_new_rtu (RS485Class *rs485, unsigned long baud, uint16_t config)
1334
1334
#else
1335
1335
modbus_t * modbus_new_rtu (const char *device,
1336
1336
int baud, char parity, int data_bit,
@@ -1362,6 +1362,7 @@ modbus_t* modbus_new_rtu(const char *device,
1362
1362
ctx->backend_data = (modbus_rtu_t *)malloc (sizeof (modbus_rtu_t ));
1363
1363
ctx_rtu = (modbus_rtu_t *)ctx->backend_data ;
1364
1364
#ifdef ARDUINO
1365
+ ctx_rtu->rs485 = rs485;
1365
1366
ctx_rtu->baud = baud;
1366
1367
ctx_rtu->config = config;
1367
1368
#else
0 commit comments