Instructions to build libmodbus in a VS project
[libmodbus.git] / src / modbus-rtu-private.h
blob01e6a9188e0e647a3240be757539b0954e56f277
1 /*
2 * Copyright © Stéphane Raimbault <stephane.raimbault@gmail.com>
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
7 #ifndef MODBUS_RTU_PRIVATE_H
8 #define MODBUS_RTU_PRIVATE_H
10 #ifndef _MSC_VER
11 #include <stdint.h>
12 #else
13 #include "stdint.h"
14 #endif
16 #if defined(_WIN32)
17 #include <windows.h>
18 #else
19 #include <termios.h>
20 #endif
22 #define _MODBUS_RTU_HEADER_LENGTH 1
23 #define _MODBUS_RTU_PRESET_REQ_LENGTH 6
24 #define _MODBUS_RTU_PRESET_RSP_LENGTH 2
26 #define _MODBUS_RTU_CHECKSUM_LENGTH 2
28 #if defined(_WIN32)
29 #if !defined(ENOTSUP)
30 #define ENOTSUP WSAEOPNOTSUPP
31 #endif
33 /* WIN32: struct containing serial handle and a receive buffer */
34 #define PY_BUF_SIZE 512
36 struct win32_ser {
37 /* File handle */
38 HANDLE fd;
39 /* Receive buffer */
40 uint8_t buf[PY_BUF_SIZE];
41 /* Received chars */
42 DWORD n_bytes;
44 #endif /* _WIN32 */
46 typedef struct _modbus_rtu {
47 /* Device: "/dev/ttyS0", "/dev/ttyUSB0" or "/dev/tty.USA19*" on Mac OS X. */
48 char *device;
49 /* Bauds: 9600, 19200, 57600, 115200, etc */
50 int baud;
51 /* Data bit */
52 uint8_t data_bit;
53 /* Stop bit */
54 uint8_t stop_bit;
55 /* Parity: 'N', 'O', 'E' */
56 char parity;
57 #if defined(_WIN32)
58 struct win32_ser w_ser;
59 DCB old_dcb;
60 #else
61 /* Save old termios settings */
62 struct termios old_tios;
63 #endif
64 #if HAVE_DECL_TIOCSRS485
65 int serial_mode;
66 #endif
67 #if HAVE_DECL_TIOCM_RTS
68 int rts;
69 int rts_delay;
70 int onebyte_time;
71 void (*set_rts)(modbus_t *ctx, int on);
72 #endif
73 /* To handle many slaves on the same link */
74 int confirmation_to_ignore;
75 } modbus_rtu_t;
77 #endif /* MODBUS_RTU_PRIVATE_H */