-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpowermax.c
153 lines (121 loc) · 3.62 KB
/
powermax.c
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
/*
powermax.c - PowerMax plasma cutter RS-485 communication
Part of grblHAL
Copyright (c) 2025 Terje Io
grblHAL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
grblHAL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
*/
#include "thc.h"
#if PLASMA_ENABLE && 0
#include <math.h>
#include <string.h>
#include "../spindle/modbus_rtu.h"
static uint32_t modbus_address = 1;
static void rx_packet (modbus_message_t *msg);
static void rx_exception (uint8_t code, void *context);
static const modbus_callbacks_t callbacks = {
.retries = 5,
.retry_delay = 50,
.on_rx_packet = rx_packet,
.on_rx_exception = rx_exception
};
static bool set_cut_mode (uint16_t mode)
{
modbus_message_t rpm_cmd = {
.context = (void *)Plasma_SetMode,
.crc_check = false,
.adu[0] = modbus_address,
.adu[1] = ModBus_WriteRegister,
.adu[2] = 0x20,
.adu[3] = 0x93,
.adu[4] = mode >> 8,
.adu[5] = mode & 0xFF,
.tx_length = 8,
.rx_length = 8
};
return modbus_send(&rpm_cmd, &callbacks, true);
}
static bool set_amperage (float a)
{
uint16_t amps = (uint16_t)(a * 64);
modbus_message_t rpm_cmd = {
.context = (void *)Plasma_SetCurrent,
.crc_check = false,
.adu[0] = modbus_address,
.adu[1] = ModBus_WriteRegister,
.adu[2] = 0x20,
.adu[3] = 0x94,
.adu[4] = amps >> 8,
.adu[5] = amps & 0xFF,
.tx_length = 8,
.rx_length = 8
};
return modbus_send(&rpm_cmd, &callbacks, true);
}
static bool set_gas_pressure (float psi)
{
uint16_t pressure = (uint16_t)(psi * 128);
modbus_message_t mode_cmd = {
.context = (void *)Plasma_SetPressure,
.crc_check = false,
.adu[0] = modbus_address,
.adu[1] = ModBus_WriteRegister,
.adu[2] = 0x20,
.adu[3] = 0x96,
.adu[4] = pressure >> 8,
.adu[5] = pressure & 0xFF,
.tx_length = 8,
.rx_length = 8
};
return modbus_send(&mode_cmd, &callbacks, true);
}
static void rx_packet (modbus_message_t *msg)
{
if(!(msg->adu[0] & 0x80)) {
/*
switch((vfd_response_t)msg->context) {
case VFD_GetRPM:
spindle_validate_at_speed(spindle_data, f2rpm((msg->adu[3] << 8) | msg->adu[4]));
break;
case VFD_GetMinRPM:
freq_min = (msg->adu[3] << 8) | msg->adu[4];
break;
case VFD_GetMaxRPM:
freq_max = (msg->adu[3] << 8) | msg->adu[4];
spindle_hal->cap.rpm_range_locked = On;
spindle_hal->rpm_min = f2rpm(freq_min);
spindle_hal->rpm_max = f2rpm(freq_max);
break;
default:
break;
}
*/
}
}
static void rx_exception (uint8_t code, void *context)
{
// raise alarm?
}
/*
static void onReportOptions (bool newopt)
{
on_report_options(newopt);
if(!newopt)
report_plugin("PowerMax RS-485", "0.01");
}
*/
void powermax_init (void)
{
cutter.set_cut_mode = set_cut_mode;
cutter.set_current = set_amperage;
cutter.set_pressure = set_gas_pressure;
}
#endif