Commit f29bb245 by 树林

fix: FC06 写地址默认改回基于 1,与 FC03 一致

写通道不做 -1 时点表 87 会落到设备 88;默认写也 PDU=地址-1,读写对齐。

Co-authored-by: Cursor <cursoragent@cursor.com>
parent 86a12035
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
"pollMs": 2000, "pollMs": 2000,
"modbusAddressBase": 1, "modbusAddressBase": 1,
"modbusAddressOffset": -1, "modbusAddressOffset": -1,
"modbusWriteAddressBase": 0, "modbusWriteAddressBase": 1,
"modbusWriteAddressOffset": 0, "modbusWriteAddressOffset": -1,
"adminUsername": "admin", "adminUsername": "admin",
"adminPassword": "Admin@123", "adminPassword": "Admin@123",
"modbusHosts": [ "modbusHosts": [
......
...@@ -102,8 +102,8 @@ struct AppState { ...@@ -102,8 +102,8 @@ struct AppState {
int pollMs = 2000; int pollMs = 2000;
/** FC03 读:点表→PDU,现场读点常需 -1(点表 68 → PDU 67) */ /** FC03 读:点表→PDU,现场读点常需 -1(点表 68 → PDU 67) */
int modbusAddressOffset = -1; int modbusAddressOffset = -1;
/** FC05/FC06 写:与读分开;部分设备写通道不做 -1,默认 0(点表地址即 PDU) */ /** FC05/FC06 写:与读同为 -1(点表 87 → PDU 86 → 设备侧 87);基于 0 时会写到 88 */
int modbusWriteAddressOffset = 0; int modbusWriteAddressOffset = -1;
std::string adminUser = "admin"; std::string adminUser = "admin";
std::string adminPass = "Admin@123"; std::string adminPass = "Admin@123";
std::vector<ModbusHost> modbusHosts; std::vector<ModbusHost> modbusHosts;
...@@ -115,7 +115,7 @@ struct AppState { ...@@ -115,7 +115,7 @@ struct AppState {
std::map<std::string, PointValue> values; // key = point id std::map<std::string, PointValue> values; // key = point id
std::map<std::string, bool> hostOk; std::map<std::string, bool> hostOk;
std::map<std::string, int> hostLatencyMs; std::map<std::string, int> hostLatencyMs;
std::string version = "0.3.3-write-addr"; std::string version = "0.3.4-write-base1";
std::map<std::string, Session> sessions; std::map<std::string, Session> sessions;
bool pollRunning = false; bool pollRunning = false;
}; };
...@@ -369,10 +369,14 @@ void loadConfigFile(const std::string& path) { ...@@ -369,10 +369,14 @@ void loadConfigFile(const std::string& path) {
g.modbusAddressOffset = extractInt(body, "modbusAddressOffset", g.modbusAddressOffset); g.modbusAddressOffset = extractInt(body, "modbusAddressOffset", g.modbusAddressOffset);
} }
if (body.find("\"modbusWriteAddressBase\"") != std::string::npos) { if (body.find("\"modbusWriteAddressBase\"") != std::string::npos) {
applyModbusWriteAddressBase(extractInt(body, "modbusWriteAddressBase", 0)); applyModbusWriteAddressBase(extractInt(body, "modbusWriteAddressBase", 1));
} else if (body.find("\"modbusWriteAddressOffset\"") != std::string::npos) { } else if (body.find("\"modbusWriteAddressOffset\"") != std::string::npos) {
g.modbusWriteAddressOffset = g.modbusWriteAddressOffset =
extractInt(body, "modbusWriteAddressOffset", g.modbusWriteAddressOffset); extractInt(body, "modbusWriteAddressOffset", g.modbusWriteAddressOffset);
} else if (body.find("\"modbusAddressBase\"") == std::string::npos &&
body.find("\"modbusAddressOffset\"") == std::string::npos) {
// 旧配置未写 write 项时,写与读对齐为 -1
g.modbusWriteAddressOffset = g.modbusAddressOffset;
} }
auto listen = extractString(body, "listen"); auto listen = extractString(body, "listen");
if (!listen.empty()) g.listenHost = listen; if (!listen.empty()) g.listenHost = listen;
...@@ -1218,7 +1222,7 @@ int main(int argc, char** argv) { ...@@ -1218,7 +1222,7 @@ int main(int argc, char** argv) {
g.modbusAddressOffset = extractInt(req.body, "modbusAddressOffset", g.modbusAddressOffset); g.modbusAddressOffset = extractInt(req.body, "modbusAddressOffset", g.modbusAddressOffset);
} }
if (req.body.find("\"modbusWriteAddressBase\"") != std::string::npos) { if (req.body.find("\"modbusWriteAddressBase\"") != std::string::npos) {
applyModbusWriteAddressBase(extractInt(req.body, "modbusWriteAddressBase", 0)); applyModbusWriteAddressBase(extractInt(req.body, "modbusWriteAddressBase", 1));
} else if (req.body.find("\"modbusWriteAddressOffset\"") != std::string::npos) { } else if (req.body.find("\"modbusWriteAddressOffset\"") != std::string::npos) {
g.modbusWriteAddressOffset = g.modbusWriteAddressOffset =
extractInt(req.body, "modbusWriteAddressOffset", g.modbusWriteAddressOffset); extractInt(req.body, "modbusWriteAddressOffset", g.modbusWriteAddressOffset);
......
...@@ -36,7 +36,7 @@ async function loadHealth() { ...@@ -36,7 +36,7 @@ async function loadHealth() {
const readBase = const readBase =
h.modbusAddressBase === 0 || h.modbusAddressBase === '0' ? '读·基于0' : '读·基于1'; h.modbusAddressBase === 0 || h.modbusAddressBase === '0' ? '读·基于0' : '读·基于1';
const writeBase = const writeBase =
h.modbusWriteAddressBase === 1 || h.modbusWriteAddressBase === '1' ? '写·基于1' : '写·基于0'; h.modbusWriteAddressBase === 0 || h.modbusWriteAddressBase === '0' ? '写·基于0' : '写·基于1';
const items = [ const items = [
['服务', h.ok ? '正常' : '异常', h.ok], ['服务', h.ok ? '正常' : '异常', h.ok],
['平台', h.platformUrl || '—', true], ['平台', h.platformUrl || '—', true],
...@@ -70,11 +70,11 @@ async function loadConfig() { ...@@ -70,11 +70,11 @@ async function loadConfig() {
: '1'; : '1';
document.getElementById('cfgAddrBase').value = base; document.getElementById('cfgAddrBase').value = base;
const writeBase = const writeBase =
cfgCache.modbusWriteAddressBase === 1 || cfgCache.modbusWriteAddressBase === '1' cfgCache.modbusWriteAddressBase === 0 || cfgCache.modbusWriteAddressBase === '0'
? '1' ? '0'
: cfgCache.modbusWriteAddressOffset === -1 : cfgCache.modbusWriteAddressOffset === 0
? '1' ? '0'
: '0'; : '1';
document.getElementById('cfgWriteAddrBase').value = writeBase; document.getElementById('cfgWriteAddrBase').value = writeBase;
renderModbus(cfgCache.modbusHosts || []); renderModbus(cfgCache.modbusHosts || []);
renderDevices(cfgCache); renderDevices(cfgCache);
...@@ -261,8 +261,8 @@ async function boot() { ...@@ -261,8 +261,8 @@ async function boot() {
pollMs: Number(document.getElementById('cfgPoll').value), pollMs: Number(document.getElementById('cfgPoll').value),
modbusAddressBase: addrBase === 0 ? 0 : 1, modbusAddressBase: addrBase === 0 ? 0 : 1,
modbusAddressOffset: addrBase === 0 ? 0 : -1, modbusAddressOffset: addrBase === 0 ? 0 : -1,
modbusWriteAddressBase: writeAddrBase === 1 ? 1 : 0, modbusWriteAddressBase: writeAddrBase === 0 ? 0 : 1,
modbusWriteAddressOffset: writeAddrBase === 1 ? -1 : 0, modbusWriteAddressOffset: writeAddrBase === 0 ? 0 : -1,
modbusHosts: readModbusFromTable(), modbusHosts: readModbusFromTable(),
}; };
cfgCache = await api('/admin/api/config', { method: 'PUT', body: JSON.stringify(body) }); cfgCache = await api('/admin/api/config', { method: 'PUT', body: JSON.stringify(body) });
......
...@@ -49,10 +49,10 @@ ...@@ -49,10 +49,10 @@
<div class="field field-wide"> <div class="field field-wide">
<label>FC05/FC06 写地址基准</label> <label>FC05/FC06 写地址基准</label>
<select id="cfgWriteAddrBase"> <select id="cfgWriteAddrBase">
<option value="0">基于 0(点表地址即 PDU,不做偏移)</option>
<option value="1">基于 1(点表地址 → PDU = 地址 − 1)</option> <option value="1">基于 1(点表地址 → PDU = 地址 − 1)</option>
<option value="0">基于 0(点表地址即 PDU,不做偏移)</option>
</select> </select>
<span class="hint">写线圈/写寄存器与读可分开。写到了偏小的地址时选「基于 0」。</span> <span class="hint">与读默认同为基于 1。若写到偏大地址(如 87→88)选基于 1;偏小则选基于 0。</span>
</div> </div>
</div> </div>
<h2 style="margin-top:18px">Modbus TCP 主机</h2> <h2 style="margin-top:18px">Modbus TCP 主机</h2>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment