-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodbus.h
47 lines (41 loc) · 850 Bytes
/
modbus.h
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
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef MODBUS_H_
#define MODBUS_H_
#include <stdint.h>
#include <stdbool.h>
#include <asm/stm8/features.h>
#define READ_COIL_STATUS 01
#define READ_INPUT_STATUS 02
#define READ_HOLDING_REGISTERS 03
#define READ_INPUT_REGISTERS 04
#define WRITE_SINGLE_COIL 05
#define WRITE_SINGLE_REGISTER 06
#define WRITE_MULTIPLE_COILS 15
#define WRITE_MULTIPLE_REGISTERS 16
struct modbus_response
{
uint8_t dev_addr;
uint8_t func;
uint8_t data_len;
uint8_t data[];
};
struct modbus_request
{
uint8_t dev_addr;
uint8_t func;
uint8_t reg_addr_hi;
uint8_t reg_addr_lo;
union
{
uint8_t reg_count_hi;
uint8_t write_data_hi;
};
union
{
uint8_t reg_count_lo;
uint8_t write_data_lo;
};
uint8_t crc_lo;
uint8_t crc_hi;
};
bool modbus(struct modbus_response *response, struct modbus_request *request, uint8_t dev_addr);
#endif /* MODBUS_H_ */