public void TestGroupingDataPointsForWriteRegister() { IUnitOfWork unitOfWork = new AdoUnitOfWork(); IDataPointRepository dataPointRepository = new DataPointRepository(unitOfWork); List <DataPoint> allDataPoints = dataPointRepository.FindAll().ToList(); int dataPointCount = 0; List <List <DataPoint> > dataPointsGroupedForWrite = DataPointGrouper.GroupingDataPointsForWriteRegister(allDataPoints); foreach (var groud in dataPointsGroupedForWrite) { dataPointCount += groud.Count; } Assert.IsTrue(allDataPoints.Count == dataPointCount); }
/// <summary> /// 根据数据点获取读取寄存器命令(若干个请求字节流) /// </summary> /// <param name="dataPoints"> /// dataPoints中的DataPoint不必满足如下条件: /// 1.设备地址相同; /// 2.读寄存器用的功能码相同; /// 3.相邻DataPoint的寄存器地址是连续的。 /// /// 该方法内部将自动调整为以上条件 /// </param> /// <returns></returns> public static List <List <byte> > CreateReadRegisterCommands(List <DataPoint> dataPoints) { List <List <byte> > readRegisterCommands = new List <List <byte> >(); if (null == dataPoints) { return(readRegisterCommands); } List <List <DataPoint> > dataPointsGroupedForRead = DataPointGrouper.GroupingDataPointsForReadRegister(dataPoints); foreach (var dataPointsGroup in dataPointsGroupedForRead) { List <List <byte> > requestCommadBytes = TCPRequestCommandByteStreamCreator.CreateRequestCommandByteStreamForReadRegisterBy(dataPointsGroup); foreach (var requestCommadByte in requestCommadBytes) { readRegisterCommands.Add(requestCommadByte); } } return(readRegisterCommands); }
/// <summary> /// 根据数据点获取写寄存器命令(若干个请求字节流) /// </summary> /// <param name="dataAnalyzeMode">数据解析模式</param> /// <param name="dataPoints"> /// dataPoints中的DataPoint不必满足如下条件: /// 1.设备地址相同; /// 2.读寄存器用的功能码相同; /// 3.相邻DataPoint的寄存器地址是连续的。 /// /// 该方法内部将自动调整为以上条件 /// </param> /// <returns></returns> public static List <List <byte> > CreateWriteRegisterCommands(DataAnalyzeMode dataAnalyzeMode, List <DataPoint> dataPoints) { List <List <byte> > writeRegisterCommands = new List <List <byte> >(); if (null == dataPoints || dataPoints.Count < 1) { return(writeRegisterCommands); } List <List <DataPoint> > dataPointsGroupedForWrite = DataPointGrouper.GroupingDataPointsForWriteRegister(dataPoints); foreach (var dataPointsGroup in dataPointsGroupedForWrite) { List <List <byte> > requestCommadBytes = TCPRequestCommandByteStreamCreator.CreateRequestCommandByteStreamForWriteRegisterBy(dataAnalyzeMode, dataPointsGroup); foreach (var requestCommadByte in requestCommadBytes) { writeRegisterCommands.Add(requestCommadByte); } } return(writeRegisterCommands); }