public void TestGroupingDataPointsForReadRegister() { IUnitOfWork unitOfWork = new AdoUnitOfWork(); IDataPointRepository dataPointRepository = new DataPointRepository(unitOfWork); List <DataPoint> allDataPoints = dataPointRepository.FindAll().ToList(); int dataPointCount = 0; List <List <DataPoint> > dataPointsGroupedForRead = DataPointGrouper.GroupingDataPointsForReadRegister(allDataPoints); foreach (var groud in dataPointsGroupedForRead) { 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); }