/**************************************************************************** * 这些列算法的核心: * 第一步:将ICustomerRequestData分解成若干个IFunNumRequestDataBase; * 第二步:将第一步得到的若干个IFunNumRequestDataBase转换成对应数量的 * IFunNumRequestDataRTU(RTU请求帧) * 第三步:将若干个IFunNumRequestDataRTU转换成对应数量的请求帧字节流 ****************************************************************************/ private static List <List <byte> > CreateRequestCommandByteStreamsForFunNum01(ICustomerRequestData customerRequestData) { List <List <byte> > requesCommandByteStreams = new List <List <byte> >(); FunNum01CustomerRequestData funNum01CustomerRequestData = (FunNum01CustomerRequestData)customerRequestData; //第一步:将ICustomerRequestData分解成若干个IFunNumRequestDataBase; List <FunNum01RequestDataBase> funNum01RequestDataBases = funNum01CustomerRequestData.CovertToFunNum01RequestDataBases(); foreach (FunNum01RequestDataBase item in funNum01RequestDataBases) { FunNum01RequestDataRTU funNum01RequestDataRTU = new FunNum01RequestDataRTU(); //第二步:将第一步得到的若干个IFunNumRequestDataBase转换成对应数量的IFunNumRequestDataRTU(RTU请求帧) funNum01RequestDataRTU.FunNum01RequestDataBase = item; //第三步:将若干个IFunNumRequestDataRTU转换成对应数量的请求帧字节流 requesCommandByteStreams.Add(funNum01RequestDataRTU.ToByteList()); } return(requesCommandByteStreams); }
private static List <List <byte> > CreateRequestCommandByteStreamForFunNum01(List <DataPoint> dataPoints) { List <List <byte> > requestCommandByteStreams = new List <List <byte> >(); DataPoint dataPoint = dataPoints.First(); int theFirstRegisterAddress = dataPoints.First().StartRegisterAddress; int theLastRegisterAddress = dataPoints.Last().StartRegisterAddress + RegisterCountCalculator.GetRegisterCount(dataPoints.Last().DataPointDataType) - 1; int registerCount = theLastRegisterAddress - theFirstRegisterAddress + 1; FunNum01CustomerRequestData customerRequestData = new FunNum01CustomerRequestData(); customerRequestData.DeviceAddress = (byte)dataPoint.DeviceAddress; customerRequestData.FunctionNum = FunctionNumType.FunctionNum01; customerRequestData.StartingRegister = (ushort)theFirstRegisterAddress; customerRequestData.NumOfRegisterToRead = (ushort)registerCount; requestCommandByteStreams = TCPRequesCommandCreator.CreateRequestCommandByteStream(customerRequestData); return(requestCommandByteStreams); }