forked from cesanta/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodbus.h
More file actions
34 lines (29 loc) · 1.03 KB
/
Copy pathmodbus.h
File metadata and controls
34 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once
#include "net.h"
// Functions
#define MG_MODBUS_FUNC_READ_COILS 1
#define MG_MODBUS_FUNC_READ_DISCRETE_INPUTS 2
#define MG_MODBUS_FUNC_READ_HOLDING_REGISTERS 3
#define MG_MODBUS_FUNC_READ_INPUT_REGISTERS 4
#define MG_MODBUS_FUNC_WRITE_SINGLE_COIL 5
#define MG_MODBUS_FUNC_WRITE_SINGLE_REGISTER 6
#define MG_MODBUS_FUNC_WRITE_MULTIPLE_COILS 15
#define MG_MODBUS_FUNC_WRITE_MULTIPLE_REGISTERS 16
// Error codes
#define MG_MODBUS_ERR_NONE 0
#define MG_MODBUS_ERR_ILLEGAL_FUNCTION 1
#define MG_MODBUS_ERR_ILLEGAL_ADDRESS 2
#define MG_MODBUS_ERR_ILLEGAL_VALUE 3
#define MG_MODBUS_ERR_DEVICE_FAILURE 4
struct mg_modbus_req {
uint8_t func; // Function code, one of MG_MODBUS_FUNC_*
uint8_t error; // Error code user handler can set
uint16_t addr; // Address
union {
bool *bits;
uint16_t *regs;
} u;
uint16_t len; // Number of registers or bits
};
struct mg_connection *mg_modbus_listen(struct mg_mgr *mgr, const char *url,
mg_event_handler_t fn, void *fn_data);