| 1 | /* |
| 2 | * Copyright © Stéphane Raimbault <[email protected]> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef MODBUS_RTU_PRIVATE_H |
| 8 | #define MODBUS_RTU_PRIVATE_H |
| 9 | |
| 10 | #ifndef _MSC_VER |
| 11 | #include <stdint.h> |
| 12 | #else |
| 13 | #include "stdint.h" |
| 14 | #endif |
| 15 | |
| 16 | #if defined(_WIN32) |
| 17 | #include <windows.h> |
| 18 | #else |
| 19 | #if defined(HAVE_STRUCT_TERMIOS2) |
| 20 | /* Prevent duplicate definitions of "struct termios" |
| 21 | * when including <asm/termbits.h> and <termios.h>. */ |
| 22 | #define termios |
| 23 | #include <asm/termbits.h> |
| 24 | #undef termios |
| 25 | #endif |
| 26 | #include <termios.h> |
| 27 | #endif |
| 28 | |
| 29 | #define _MODBUS_RTU_HEADER_LENGTH 1 |
| 30 | #define _MODBUS_RTU_PRESET_REQ_LENGTH 6 |
| 31 | #define _MODBUS_RTU_PRESET_RSP_LENGTH 2 |
| 32 | |
| 33 | #define _MODBUS_RTU_CHECKSUM_LENGTH 2 |
| 34 | |
| 35 | #if defined(_WIN32) |
| 36 | #if !defined(ENOTSUP) |
| 37 | #define ENOTSUP WSAEOPNOTSUPP |
| 38 | #endif |
| 39 | |
| 40 | /* WIN32: struct containing serial handle and a receive buffer */ |
| 41 | #define PY_BUF_SIZE 512 |
| 42 | |
| 43 | struct win32_ser { |
| 44 | /* File handle */ |
| 45 | HANDLE fd; |
| 46 | /* Receive buffer */ |
| 47 | uint8_t buf[PY_BUF_SIZE]; |
| 48 | /* Received chars */ |
| 49 | DWORD n_bytes; |
| 50 | }; |
| 51 | #endif /* _WIN32 */ |
| 52 | |
| 53 | typedef struct _modbus_rtu { |
| 54 | /* Device: "/dev/ttyS0", "/dev/ttyUSB0" or "/dev/tty.USA19*" on Mac OS X. */ |
| 55 | char *device; |
| 56 | /* Bauds: 9600, 19200, 57600, 115200, etc */ |
| 57 | int baud; |
| 58 | /* Data bit */ |
| 59 | uint8_t data_bit; |
| 60 | /* Stop bit */ |
| 61 | uint8_t stop_bit; |
| 62 | /* Parity: 'N', 'O', 'E' */ |
| 63 | char parity; |
| 64 | #if defined(_WIN32) |
| 65 | struct win32_ser w_ser; |
| 66 | DCB old_dcb; |
| 67 | #elif defined(HAVE_STRUCT_TERMIOS2) |
| 68 | /* Save old termios settings */ |
| 69 | struct termios2 old_tios; |
| 70 | #else |
| 71 | /* Save old termios settings */ |
| 72 | struct termios old_tios; |
| 73 | #endif |
| 74 | #if HAVE_DECL_TIOCSRS485 |
| 75 | int serial_mode; |
| 76 | #endif |
| 77 | #if HAVE_DECL_TIOCM_RTS |
| 78 | int rts; |
| 79 | int rts_delay; |
| 80 | int onebyte_time; |
| 81 | void (*set_rts)(modbus_t *ctx, int on); |
| 82 | #endif |
| 83 | /* To handle many slaves on the same link */ |
| 84 | int confirmation_to_ignore; |
| 85 | } modbus_rtu_t; |
| 86 | |
| 87 | #endif /* MODBUS_RTU_PRIVATE_H */ |