author | mjsousa <msousa@fe.up.pt> |
Wed, 02 Jun 2021 11:09:57 +0100 | |
changeset 14 | 5b6407edfe8e |
parent 1 | 59783e8ee3d2 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (c) 2001-2003,2016 Mario de Sousa (msousa@fe.up.pt) |
|
3 |
* |
|
4 |
* This file is part of the Modbus library for Beremiz and matiec. |
|
5 |
* |
|
6 |
* This Modbus library is free software: you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU Lesser General Public License as published by |
|
8 |
* the Free Software Foundation, either version 3 of the License, or |
|
9 |
* (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but |
|
12 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
|
14 |
* General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU Lesser General Public License |
|
17 |
* along with this Modbus library. If not, see <http://www.gnu.org/licenses/>. |
|
18 |
* |
|
19 |
* This code is made available on the understanding that it will not be |
|
20 |
* used in safety-critical situations without a full and competent review. |
|
21 |
*/ |
|
22 |
||
23 |
||
24 |
/* mb_master.h */ |
|
25 |
||
26 |
||
27 |
#ifndef MODBUS_MASTER_H |
|
28 |
#define MODBUS_MASTER_H |
|
29 |
||
30 |
#include <time.h> /* struct timespec data structure */ |
|
31 |
||
32 |
#include "mb_types.h" /* get the data types */ |
|
33 |
#include "mb_addr.h" /* get definition of common variable types and error codes */ |
|
34 |
||
35 |
||
36 |
||
37 |
/*********************************************************************** |
|
38 |
||
39 |
Note: All functions used for sending or receiving data via |
|
40 |
modbus return these return values. |
|
41 |
||
42 |
||
43 |
Returns: string_length if OK |
|
44 |
-1 on internal error or port failure |
|
45 |
-2 on timeout |
|
46 |
-3 if a valid yet un-expected frame is received! |
|
47 |
-4 for modbus exception errors |
|
48 |
(in this case exception code is returned in *error_code) |
|
49 |
||
50 |
***********************************************************************/ |
|
51 |
||
52 |
||
53 |
/* FUNCTION 0x01 - Read Coils |
|
54 |
* Bits are stored on an int array, one bit per int. |
|
55 |
*/ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
56 |
int read_output_bits(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
57 |
u16 start_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
58 |
u16 count, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
59 |
u16 *dest, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
60 |
int dest_size, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
61 |
int fd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
62 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
63 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
64 |
const struct timespec *response_timeout, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
65 |
pthread_mutex_t *data_access_mutex); |
0 | 66 |
#define read_coils(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) \ |
67 |
read_output_bits(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) |
|
68 |
||
69 |
||
70 |
/* FUNCTION 0x01 - Read Coils |
|
71 |
* Bits are stored on an u32 array, 32 bits per u32. |
|
72 |
* Unused bits in last u32 are set to 0. |
|
73 |
*/ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
74 |
int read_output_bits_u32(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
75 |
u16 start_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
76 |
u16 count, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
77 |
u32 *dest, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
78 |
int fd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
79 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
80 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
81 |
const struct timespec *response_timeout); |
0 | 82 |
#define read_coils_u32(p1,p2,p3,p4,p5,p6,p7,p8) \ |
83 |
read_output_bits_u32(p1,p2,p3,p4,p5,p6,p7,p8) |
|
84 |
||
85 |
||
86 |
||
87 |
||
88 |
/* FUNCTION 0x02 - Read Discrete Inputs |
|
89 |
* Bits are stored on an int array, one bit per int. |
|
90 |
*/ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
91 |
int read_input_bits(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
92 |
u16 start_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
93 |
u16 count, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
94 |
u16 *dest, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
95 |
int dest_size, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
96 |
int fd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
97 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
98 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
99 |
const struct timespec *response_timeout, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
100 |
pthread_mutex_t *data_access_mutex); |
0 | 101 |
#define read_discrete_inputs(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) \ |
102 |
read_input_bits (p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) |
|
103 |
||
104 |
||
105 |
/* FUNCTION 0x02 - Read Discrete Inputs |
|
106 |
* Bits are stored on an u32 array, 32 bits per u32. |
|
107 |
* Unused bits in last u32 are set to 0. |
|
108 |
*/ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
109 |
int read_input_bits_u32(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
110 |
u16 start_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
111 |
u16 count, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
112 |
u32 *dest, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
113 |
int fd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
114 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
115 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
116 |
const struct timespec *response_timeout); |
0 | 117 |
#define read_discrete_inputs_u32(p1,p2,p3,p4,p5,p6,p7,p8) \ |
118 |
read_input_bits_u32 (p1,p2,p3,p4,p5,p6,p7,p8) |
|
119 |
||
120 |
||
121 |
||
122 |
||
123 |
/* FUNCTION 0x03 - Read Holding Registers */ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
124 |
int read_output_words(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
125 |
u16 start_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
126 |
u16 count, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
127 |
u16 *dest, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
128 |
int dest_size, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
129 |
int fd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
130 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
131 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
132 |
const struct timespec *response_timeout, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
133 |
pthread_mutex_t *data_access_mutex); |
0 | 134 |
#define read_holding_registers(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) \ |
135 |
read_output_words (p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) |
|
136 |
||
137 |
||
138 |
/* FUNCTION 0x03 - Read Holding Registers |
|
139 |
* u16 registers are stored in array of u32, two registers per u32. |
|
140 |
* Unused bits of last u32 element are set to 0. |
|
141 |
*/ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
142 |
int read_output_words_u32(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
143 |
u16 start_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
144 |
u16 count, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
145 |
u32 *dest, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
146 |
int fd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
147 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
148 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
149 |
const struct timespec *response_timeout); |
0 | 150 |
#define read_holding_registers_u32(p1,p2,p3,p4,p5,p6,p7,p8) \ |
151 |
read_output_words_u32 (p1,p2,p3,p4,p5,p6,p7,p8) |
|
152 |
||
153 |
||
154 |
/* FUNCTION 0x03 - Read Holding Registers |
|
155 |
* return the array with the data to the calling function |
|
156 |
*/ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
157 |
int read_output_words_u16_ref(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
158 |
u16 start_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
159 |
u16 count, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
160 |
u16 **dest, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
161 |
int ttyfd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
162 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
163 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
164 |
const struct timespec *response_timeout); |
0 | 165 |
#define read_holding_registers_u16_ref(p1,p2,p3,p4,p5,p6,p7,p8) \ |
166 |
read_output_words_u16_ref (p1,p2,p3,p4,p5,p6,p7,p8) |
|
167 |
||
168 |
||
169 |
||
170 |
/* FUNCTION 0x04 - Read Input Registers */ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
171 |
int read_input_words(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
172 |
u16 start_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
173 |
u16 count, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
174 |
u16 *dest, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
175 |
int dest_size, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
176 |
int fd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
177 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
178 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
179 |
const struct timespec *response_timeout, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
180 |
pthread_mutex_t *data_access_mutex); |
0 | 181 |
#define read_input_registers(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) \ |
182 |
read_input_words (p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) |
|
183 |
||
184 |
||
185 |
||
186 |
/* FUNCTION 0x04 - Read Input Registers |
|
187 |
* u16 registers are stored in array of u32, two registers per u32. |
|
188 |
* Unused bits of last u32 element are set to 0. |
|
189 |
*/ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
190 |
int read_input_words_u32(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
191 |
u16 start_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
192 |
u16 count, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
193 |
u32 *dest, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
194 |
int fd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
195 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
196 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
197 |
const struct timespec *response_timeout); |
0 | 198 |
#define read_input_registers_u32(p1,p2,p3,p4,p5,p6,p7,p8) \ |
199 |
read_input_words_u32 (p1,p2,p3,p4,p5,p6,p7,p8) |
|
200 |
||
201 |
||
202 |
||
203 |
/* FUNCTION 0x04 - Read Input Registers |
|
204 |
* return the array with the data to the calling function |
|
205 |
*/ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
206 |
int read_input_words_u16_ref(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
207 |
u16 start_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
208 |
u16 count, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
209 |
u16 **dest, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
210 |
int ttyfd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
211 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
212 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
213 |
const struct timespec *response_timeout); |
0 | 214 |
#define read_input_registers_u16_ref(p1,p2,p3,p4,p5,p6,p7,p8) \ |
215 |
read_input_words_u16_ref (p1,p2,p3,p4,p5,p6,p7,p8) |
|
216 |
||
217 |
||
218 |
||
219 |
||
220 |
/* FUNCTION 0x05 - Force Single Coil */ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
221 |
int write_output_bit(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
222 |
u16 coil_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
223 |
u16 state, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
224 |
int fd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
225 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
226 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
227 |
const struct timespec *response_timeout, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
228 |
pthread_mutex_t *data_access_mutex); |
0 | 229 |
#define force_single_coil(p1,p2,p3,p4,p5,p6,p7,p8) \ |
230 |
write_output_bit (p1,p2,p3,p4,p5,p6,p7,p8) |
|
231 |
||
232 |
||
233 |
||
234 |
||
235 |
||
236 |
||
237 |
/* FUNCTION 0x06 - Write Single Register */ |
|
1
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
238 |
int write_output_word(u8 slave, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
239 |
u16 reg_addr, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
240 |
u16 value, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
241 |
int fd, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
242 |
int send_retries, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
243 |
u8 *error_code, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
244 |
const struct timespec *response_timeout, |
59783e8ee3d2
Remove incorrect inlines
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
0
diff
changeset
|
245 |
pthread_mutex_t *data_access_mutex); |
0 | 246 |
#define write_single_register(p1,p2,p3,p4,p5,p6,p7,p8) \ |
247 |
write_output_word (p1,p2,p3,p4,p5,p6,p7,p8) |
|
248 |
||
249 |
||
250 |
||
251 |
||
252 |
||
253 |
/* FUNCTION 0x0F - Force Multiple Coils */ |
|
254 |
int write_output_bits(u8 slave, |
|
255 |
u16 start_addr, |
|
256 |
u16 coil_count, |
|
257 |
u16 *data, |
|
258 |
int fd, |
|
259 |
int send_retries, |
|
260 |
u8 *error_code, |
|
261 |
const struct timespec *response_timeout, |
|
262 |
pthread_mutex_t *data_access_mutex); |
|
263 |
#define force_multiple_coils(p1,p2,p3,p4,p5,p6,p7,p8,p9) \ |
|
264 |
write_output_bits (p1,p2,p3,p4,p5,p6,p7,p8,p9) |
|
265 |
||
266 |
||
267 |
/* FUNCTION 0x0F - Force Multiple Coils |
|
268 |
* Bits should be stored on an u32 array, 32 bits per u32. |
|
269 |
* Unused bits in last u32 should be set to 0. |
|
270 |
*/ |
|
271 |
int write_output_bits_u32(u8 slave, |
|
272 |
u16 start_addr, |
|
273 |
u16 coil_count, |
|
274 |
u32 *data, |
|
275 |
int fd, |
|
276 |
int send_retries, |
|
277 |
u8 *error_code, |
|
278 |
const struct timespec *response_timeout); |
|
279 |
#define force_multiple_coils_u32(p1,p2,p3,p4,p5,p6,p7,p8) \ |
|
280 |
write_output_bits_u32 (p1,p2,p3,p4,p5,p6,p7,p8) |
|
281 |
||
282 |
||
283 |
||
284 |
/* FUNCTION 0x10 - Force Multiple Registers */ |
|
285 |
int write_output_words(u8 slave, |
|
286 |
u16 start_addr, |
|
287 |
u16 reg_count, |
|
288 |
u16 *data, |
|
289 |
int fd, |
|
290 |
int send_retries, |
|
291 |
u8 *error_code, |
|
292 |
const struct timespec *response_timeout, |
|
293 |
pthread_mutex_t *data_access_mutex); |
|
294 |
#define force_multiple_registers(p1,p2,p3,p4,p5,p6,p7,p8,p9) \ |
|
295 |
write_output_words (p1,p2,p3,p4,p5,p6,p7,p8,p9) |
|
296 |
||
297 |
||
298 |
||
299 |
/* FUNCTION 0x10 - Force Multiple Registers |
|
300 |
* u16 registers are stored in array of u32, two registers per u32. |
|
301 |
* Unused bits of last u32 element are set to 0. |
|
302 |
*/ |
|
303 |
int write_output_words_u32(u8 slave, |
|
304 |
u16 start_addr, |
|
305 |
u16 reg_count, |
|
306 |
u32 *data, |
|
307 |
int fd, |
|
308 |
int send_retries, |
|
309 |
u8 *error_code, |
|
310 |
const struct timespec *response_timeout); |
|
311 |
||
312 |
#define force_multiple_registers_u32(p1,p2,p3,p4,p5,p6,p7,p8) \ |
|
313 |
write_output_words_u32 (p1,p2,p3,p4,p5,p6,p7,p8) |
|
314 |
||
315 |
||
316 |
||
317 |
||
318 |
||
319 |
||
320 |
/* Initialise the Modbus Library to work as Master only */ |
|
321 |
int mb_master_init(int nd_count); |
|
322 |
/* Shut down the Modbus Library */ |
|
323 |
int mb_master_done(void); |
|
324 |
||
325 |
||
326 |
||
327 |
/* Establish a connection to a remote server/slave. |
|
328 |
* The address type (naf_tcp, naf_rtu, naf_ascii) specifies the lower |
|
329 |
* layer to use for the newly opened node. |
|
330 |
*/ |
|
331 |
int mb_master_connect(node_addr_t node_addr); |
|
332 |
/* Shut down a connection to a remote server/slave */ |
|
333 |
int mb_master_close(int nd); |
|
334 |
||
335 |
||
336 |
||
337 |
||
338 |
/* Tell the library that communications will be suspended for some time. */ |
|
339 |
/* RTU and ASCII versions ignore this function |
|
340 |
* TCP version closes all the open tcp connections (connections are automatically |
|
341 |
* re-established the next time an IO function to the slave is requested). |
|
342 |
* To be more precise, the TCP version makes an estimate of how long |
|
343 |
* the silence will be based on previous invocations to this exact same |
|
344 |
* function, and will only close the connections if this silence is |
|
345 |
* expected to be longer than 1 second! |
|
346 |
*/ |
|
347 |
int mb_master_tcp_silence_init(void); |
|
348 |
||
349 |
||
350 |
||
351 |
#endif /* MODBUS_MASTER_H */ |
|
352 |
||
353 |
||
354 |
||
355 |
||
356 |
||
357 |
||
358 |
||
359 |