modbus解析测试

zw
smartwyy 6 months ago
parent b414860582
commit 0ed9e6344a

@ -1,6 +1,5 @@
using HybirdFrameworkCore.Const; using HybirdFrameworkCore.Const;
using HybirdFrameworkCore.Utils; using HybirdFrameworkCore.Utils;
using HybirdFrameworkDriver.Common;
using log4net; using log4net;
namespace HybirdFrameworkDriver.ModbusTcpMaster; namespace HybirdFrameworkDriver.ModbusTcpMaster;
@ -42,7 +41,7 @@ public static class ModbusDecoder
if (wordSeq == EndingConst.WordSeq.CD) if (wordSeq == EndingConst.WordSeq.CD)
{ {
decodeUseBytes = BitUtls.ReverseWordSeq(bytes); decodeUseBytes = BitUtls.ReverseWordSeq(decodeUseBytes);
} }
foreach (var field in fields) foreach (var field in fields)

@ -1,7 +1,7 @@
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Const;
using HybirdFrameworkDriver.ModbusTcpMaster; using HybirdFrameworkDriver.ModbusTcpMaster;
using Repository.Station; using Repository.Station;
using Service.Execute.Api;
using Service.Plc.Msg; using Service.Plc.Msg;
namespace Service.Plc.Client; namespace Service.Plc.Client;
@ -33,14 +33,14 @@ public class PlcClient : ModbusTcpMaster
{ {
PlcMgr.DataValidityTime = DateTime.Now; PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData); ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
} }
var bytes02 = master.BatchReadHolderRegister(201, 222); var bytes02 = master.BatchReadHolderRegister(201, 222);
if (bytes02 != null) if (bytes02 != null)
{ {
PlcMgr.DataValidityTime = DateTime.Now; PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData); ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
_binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec01.Value, it => it.No == "1"); _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec01.Value, it => it.No == "1");
@ -68,7 +68,7 @@ public class PlcClient : ModbusTcpMaster
if (bytes03 != null) if (bytes03 != null)
{ {
PlcMgr.DataValidityTime = DateTime.Now; PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData); ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
} }
} }
} }

@ -1,4 +1,3 @@
using Entity.Api.Req;
using Entity.Api.Resp; using Entity.Api.Resp;
using Entity.Constant; using Entity.Constant;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
@ -17,9 +16,9 @@ namespace WebStarter.Controllers;
[Route("api/[controller]")] [Route("api/[controller]")]
public class SwapMonitorController : ControllerBase public class SwapMonitorController : ControllerBase
{ {
private readonly MonitorService? _swapMonitorService; private readonly MonitorService _swapMonitorService;
public SwapMonitorController(MonitorService? swapMonitorService) public SwapMonitorController(MonitorService swapMonitorService)
{ {
_swapMonitorService = swapMonitorService; _swapMonitorService = swapMonitorService;
} }

Loading…
Cancel
Save