-
Notifications
You must be signed in to change notification settings - Fork 0
/
MODBUS_KALEJA.h
154 lines (112 loc) · 4.9 KB
/
MODBUS_KALEJA.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//Header File for MODBUS_KALEJA
//
//Library for controlling MODBUS related motorcontrollers from KALEJA
//
//Author: Jan Linzmaier
//Date: 01/24/2021
#ifndef __MODBUS_KALEJA__
#define __MODBUS_KALEJA__
#include <stdint.h>
#include <HardwareSerial.h>
#include <Arduino.h>
//Variables:
#define B_38400 0x01
#define B_19200 0x00
#define P_EVEN 0x00
#define P_NONE 0x01
//Classes:
class MODBUS_KALEJA{
private:
uint8_t baudrate;
uint8_t parity;
uint8_t serialStarted;
public:
MODBUS_KALEJA(HardwareSerial& refSer, uint8_t baud, uint8_t par, uint8_t pin):SerPort(refSer), baudrate(baud), parity(par), EnPin(pin){
serialStarted = 0;
};
HardwareSerial& SerPort;
uint8_t EnPin;
int8_t begin(void);
int8_t end(void);
uint8_t getStat(void);
void setStat(uint8_t s);
};
class MControl{
private:
uint8_t address;
int64_t transcieve(uint8_t RW, uint16_t addr, uint16_t data);
MODBUS_KALEJA bus;
public:
MControl(uint8_t device_address, MODBUS_KALEJA Ser): address(device_address), bus(Ser){};
//General Functions (Dont't use if you dont't know what you are doing)
int8_t MC_WRITE(uint16_t addr, uint16_t data); //Write one register
int64_t MC_READ_HOLD(uint16_t addr); //Read one holding register
int64_t MC_READ_ROM(uint16_t addr, uint8_t n); //Read n read only registers
//System Control:
int8_t EEPROM_SAVE(void); //Save Settings to EEPROM
int8_t EEPROM_RELOAD(void); //Load Settings from EEPROM
int8_t DEVICE_RESET(void); //SoftReset Device
int8_t FACTORY_DEFAULTS(void); //Reload Factory Settings
//MODBUS Watchog:
int8_t WATCHDOG_OFF(void); //Disable Modbus Watchdog
int8_t WATCHDOG_ON(uint16_t ms); //Enable Watchdog, Timer set to Time in ms(1-65535)
int32_t WATCHDOG_GET(void); //get Watchdog Time in ms
//Current:
int8_t CURRENT_LIMIT_OFF(void); //Disable Current Limit
int8_t CURRENT_LIMIT_ON(uint16_t mA); //Enable Current Limit. Set Current Limit to Current in mA(500-4000)
int32_t CURRENT_LIMIT_GET(void); //Get Current Limit in mA
//Start Ramp:
int8_t START_RAMP_OFF(void); //Disable Start Ramp
int8_t START_RAMP_ON(uint16_t ms); //Enable Start Ramp. Set Ramp Time to Time in ms(1-4000)
int32_t START_RAMP_GET(void); //Get Start Ramp in ms
//Start Ramp:
int8_t STOP_RAMP_OFF(void); //Disable Stop Ramp
int8_t STOP_RAMP_ON(uint16_t ms); //Enable Stop Ramp. Set Ramp Time to Time in ms(1-4000)
int32_t STOP_RAMP_GET(void); //Get Stop Ramp in ms
//Rotational Speed(PWM):
int8_t PWM_OFF(void); //Set Motor Speed to 0
int8_t PWM_ON(uint16_t pwm); //Set Motor Speed to pwm/327 in Percent(1631-32767)
int32_t PWM_GET(void); //get Motor PWM Settings in 327*Percent
//Current monitoring delay
int8_t CM_DELAY_OFF(void); //Disable current monitoring delay
int8_t CM_DELAY_ON(uint16_t ms); //Enable current monitoring delay. Set Time in ms(1-1000)
int32_t CM_DELAY_GET(void); //Get current monitoring delay in ms
//Motor Internal Resistance for IxR Compensation
int8_t IXR_COMP_OFF(void); //Disable IxR Compensation
int8_t IXR_COMP_ON(uint16_t mOhm); //Enable IxR Compensation, Set Motor Internal Resistance to mOhm(1-4000)
int32_t IXR_COMP_GET(void); //Get Motor Internal Resistance in mOhm
//Dir right settings
int8_t DIR_LEFT_OFF(void); //Disable left turning direction
int8_t DIR_LEFT_ON(void); //Enable left turning direction
int8_t DIR_LEFT_GET(void); //Get left turning direction settings
//Dir right settings
int8_t DIR_RIGHT_OFF(void); //Disable right turning direction
int8_t DIR_RIGHT_ON(void); //Enable right turning direction
int8_t DIR_RIGHT_GET(void); //Get right turning direction settings
//Brake Selection:
int8_t BRAKE_OFF(void); //Disable Motor Breaking
int8_t BRAKE_ON(void); //Enable Motor Breaking
int16_t BRAKE_GET(void); //get Brake Settings
//Overcurrent Settings
int8_t OVERCURRENT_SET_SHUTOFF(void); //Set Behaviour to Overcurrent Shutoff(0)
int8_t OVERCURRENT_SET_LIMIT(void); //Set Behaviour to Overcurrent Limiting(1)
int16_t OVERCURRENT_GET(void); //get Overcurrent Behaviour
//READ_ONLY:
//Product Number:
int64_t PROD_NUMBER(void); //Returns Product Number
//Harware Version:
int32_t HARDWARE_VERSION(void); //Returns Hardware Version
//Software Version:
int32_t SOFTWARE_VERSION(void); //Returns Software Version
//Serial number:
int64_t SERIAL_NUMBER(void); //Returns Serial Number
//Current:
int32_t CURRENT(void); //Returns the current being drawn by the Motor right now(0-65535)
//PWM:
int32_t PWM(void); //Returns the pwm at which the motor is running right now
//Direction:
int16_t DIR(void); //Returns the direction in which the motor is running right now
//Module Temperature:
int32_t TEMP(void); //Returns the Temperature of the Module
};
#endif