Ejemplo n.º 1
0
        private static List <List <byte> > CreateRequestCommandByteStreamForFunNum15(List <DataPoint> dataPoints)
        {
            List <List <byte> >         requestCommandByteStreams = new List <List <byte> >();
            FunNum15CustomerRequestData customerRequestData       = new FunNum15CustomerRequestData();

            DataPoint firstDataPoint          = dataPoints.First();
            int       theFirstRegisterAddress = dataPoints.First().StartRegisterAddress;
            int       theLastRegisterAddress  = dataPoints.Last().StartRegisterAddress
                                                + RegisterCountCalculator.GetRegisterCount(dataPoints.Last().DataPointDataType) - 1;
            int registerCount = theLastRegisterAddress - theFirstRegisterAddress + 1;

            customerRequestData.DeviceAddress       = (byte)firstDataPoint.DeviceAddress;
            customerRequestData.FunctionNum         = FunctionNumType.FunctionNum15;
            customerRequestData.StartingCoilAddress = (ushort)theFirstRegisterAddress;
            customerRequestData.NumOfCoilToForce    = (ushort)registerCount;

            foreach (var dataPoint in dataPoints)
            {
                if (Math.Abs(dataPoint.ValueToSet) > 0)
                {
                    customerRequestData.ForceData.Add(true);
                }
                else
                {
                    customerRequestData.ForceData.Add(false);
                }
            }

            requestCommandByteStreams =
                TCPRequesCommandCreator.CreateRequestCommandByteStream(customerRequestData);

            return(requestCommandByteStreams);
        }
Ejemplo n.º 2
0
        /// 根据DataPints的RegisterAddress分组,
        /// 每个组内的RegisterAddress都是连续的连续,例如:
        /// (1,2,3) (120,121) (300,301,302,303)
        /// </summary>
        /// <param name="dataPointsDataPints">
        ///
        /// </param>
        private static List <List <DataPoint> > GroupingDataPointsByRegisterAddressIsContinuous(List <DataPoint> dataPointsDataPints)
        {
            List <List <DataPoint> > result = new List <List <DataPoint> >();

            if (null == dataPointsDataPints || dataPointsDataPints.Count < 1)
            {
                return(result);
            }

            //先按RegisterAddress升序排序
            dataPointsDataPints.Sort(new DataPointRegisterAddressCompare());

            //小于等于-2 ,因为currDataPointStartRegisterAddress - 1 >=-1
            int previousDataPointEndRegisterAddress = -100;
            List <DataPoint> dataPointsGroup        = null;

            for (int i = 0; i < dataPointsDataPints.Count; i++)
            {
                int currDataPointStartRegisterAddress = dataPointsDataPints[i].StartRegisterAddress;

                if (previousDataPointEndRegisterAddress != currDataPointStartRegisterAddress - 1)
                {
                    if (null != dataPointsGroup)
                    {
                        result.Add(dataPointsGroup);
                    }

                    dataPointsGroup = new List <DataPoint>();
                }

                previousDataPointEndRegisterAddress = currDataPointStartRegisterAddress
                                                      + RegisterCountCalculator.GetRegisterCount(dataPointsDataPints[i].DataType) - 1;

                dataPointsGroup.Add(dataPointsDataPints[i]);

                if (i == dataPointsDataPints.Count - 1)
                {
                    result.Add(dataPointsGroup);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        private static List <List <byte> > CreateRequestCommandByteStreamForFunNum03(List <DataPoint> dataPoints)
        {
            List <List <byte> > requestCommandByteStreams = new List <List <byte> >();;
            DataPoint           firstDataPoint            = dataPoints.First();

            int theFirstRegisterAddress = dataPoints.First().StartRegisterAddress;
            int theLastRegisterAddress  = dataPoints.Last().StartRegisterAddress
                                          + RegisterCountCalculator.GetRegisterCount(dataPoints.Last().DataPointDataType) - 1;
            int registerCount = theLastRegisterAddress - theFirstRegisterAddress + 1;

            FunNum03CustomerRequestData customerRequestData = new FunNum03CustomerRequestData();

            customerRequestData.DeviceAddress           = (byte)firstDataPoint.DeviceAddress;
            customerRequestData.FunctionNum             = FunctionNumType.FunctionNum03;
            customerRequestData.StartingRegisterAddress = (ushort)theFirstRegisterAddress;
            customerRequestData.NumOfRegisterToRead     = (ushort)registerCount;

            requestCommandByteStreams =
                TCPRequesCommandCreator.CreateRequestCommandByteStream(customerRequestData);
            return(requestCommandByteStreams);
        }