Beispiel #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);
        }
Beispiel #2
0
        private static List <List <byte> > CreateRequestCommandByteStreamForFunNum05(List <DataPoint> dataPoints)
        {
            List <List <byte> >         requestCommandByteStreams = new List <List <byte> >();
            FunNum05CustomerRequestData customerRequestData       = new FunNum05CustomerRequestData();

            //功能码05是设置单个线圈的值,所以只有一个寄存器
            DataPoint firstDataPoint          = dataPoints.First();
            int       theFirstRegisterAddress = dataPoints.First().StartRegisterAddress;

            customerRequestData.DeviceAddress = (byte)firstDataPoint.DeviceAddress;
            customerRequestData.FunctionNum   = FunctionNumType.FunctionNum05;
            customerRequestData.CoilAddress   = (ushort)theFirstRegisterAddress;

            if (Math.Abs(firstDataPoint.ValueToSet) > 0)
            {
                customerRequestData.ON = true;
            }
            else
            {
                customerRequestData.ON = false;
            }

            requestCommandByteStreams =
                TCPRequesCommandCreator.CreateRequestCommandByteStream(customerRequestData);

            return(requestCommandByteStreams);
        }
Beispiel #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);
        }
Beispiel #4
0
        private static List <List <byte> > CreateRequestCommandByteStreamForFunNum16(DataAnalyzeMode dataAnalyzeMode, List <DataPoint> dataPoints)
        {
            List <List <byte> > requestCommandByteStreams = new List <List <byte> >();

            DataPoint firstDataPoint          = dataPoints.First();
            int       theFirstRegisterAddress = dataPoints.First().StartRegisterAddress;

            switch (firstDataPoint.DataPointDataType)
            {
            case DataPointDataType.S16:
            {
                FunNum16CustomerRequestData <short> customerRequestData =
                    new FunNum16CustomerRequestData <short>();
                customerRequestData.DataAnalyzeMode = dataAnalyzeMode;

                customerRequestData.DeviceAddress           = (byte)firstDataPoint.DeviceAddress;
                customerRequestData.FunctionNum             = FunctionNumType.FunctionNum16;
                customerRequestData.StartingRegisterAddress = (ushort)theFirstRegisterAddress;

                foreach (var dataPoint in dataPoints)
                {
                    customerRequestData.PresetData.Add((short)dataPoint.ValueToSet);
                }

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

            case DataPointDataType.U16:
            {
                FunNum16CustomerRequestData <ushort> customerRequestData =
                    new FunNum16CustomerRequestData <ushort>();
                customerRequestData.DataAnalyzeMode = dataAnalyzeMode;

                customerRequestData.DeviceAddress           = (byte)firstDataPoint.DeviceAddress;
                customerRequestData.FunctionNum             = FunctionNumType.FunctionNum16;
                customerRequestData.StartingRegisterAddress = (ushort)theFirstRegisterAddress;

                foreach (var dataPoint in dataPoints)
                {
                    customerRequestData.PresetData.Add((ushort)dataPoint.ValueToSet);
                }

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

            case DataPointDataType.S32:
            {
                FunNum16CustomerRequestData <int> customerRequestData =
                    new FunNum16CustomerRequestData <int>();
                customerRequestData.DataAnalyzeMode = dataAnalyzeMode;

                customerRequestData.DeviceAddress           = (byte)firstDataPoint.DeviceAddress;
                customerRequestData.FunctionNum             = FunctionNumType.FunctionNum16;
                customerRequestData.StartingRegisterAddress = (ushort)theFirstRegisterAddress;

                foreach (var dataPoint in dataPoints)
                {
                    customerRequestData.PresetData.Add((int)dataPoint.ValueToSet);
                }

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

            case DataPointDataType.U32:
            {
                FunNum16CustomerRequestData <uint> customerRequestData =
                    new FunNum16CustomerRequestData <uint>();
                customerRequestData.DataAnalyzeMode = dataAnalyzeMode;

                customerRequestData.DeviceAddress           = (byte)firstDataPoint.DeviceAddress;
                customerRequestData.FunctionNum             = FunctionNumType.FunctionNum16;
                customerRequestData.StartingRegisterAddress = (ushort)theFirstRegisterAddress;

                foreach (var dataPoint in dataPoints)
                {
                    customerRequestData.PresetData.Add((uint)dataPoint.ValueToSet);
                }

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

            case DataPointDataType.S64:
            {
                FunNum16CustomerRequestData <long> customerRequestData =
                    new FunNum16CustomerRequestData <long>();
                customerRequestData.DataAnalyzeMode = dataAnalyzeMode;

                customerRequestData.DeviceAddress           = (byte)firstDataPoint.DeviceAddress;
                customerRequestData.FunctionNum             = FunctionNumType.FunctionNum16;
                customerRequestData.StartingRegisterAddress = (ushort)theFirstRegisterAddress;

                foreach (var dataPoint in dataPoints)
                {
                    customerRequestData.PresetData.Add((long)dataPoint.ValueToSet);
                }

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

            case DataPointDataType.U64:
            {
                FunNum16CustomerRequestData <ulong> customerRequestData =
                    new FunNum16CustomerRequestData <ulong>();
                customerRequestData.DataAnalyzeMode = dataAnalyzeMode;

                customerRequestData.DeviceAddress           = (byte)firstDataPoint.DeviceAddress;
                customerRequestData.FunctionNum             = FunctionNumType.FunctionNum16;
                customerRequestData.StartingRegisterAddress = (ushort)theFirstRegisterAddress;

                foreach (var dataPoint in dataPoints)
                {
                    customerRequestData.PresetData.Add((ulong)dataPoint.ValueToSet);
                }

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

            case DataPointDataType.F32:
            {
                FunNum16CustomerRequestData <float> customerRequestData =
                    new FunNum16CustomerRequestData <float>();
                customerRequestData.DataAnalyzeMode = dataAnalyzeMode;

                customerRequestData.DeviceAddress           = (byte)firstDataPoint.DeviceAddress;
                customerRequestData.FunctionNum             = FunctionNumType.FunctionNum16;
                customerRequestData.StartingRegisterAddress = (ushort)theFirstRegisterAddress;

                foreach (var dataPoint in dataPoints)
                {
                    customerRequestData.PresetData.Add((float)dataPoint.ValueToSet);
                }

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

            case DataPointDataType.D64:
            {
                FunNum16CustomerRequestData <double> customerRequestData =
                    new FunNum16CustomerRequestData <double>();
                customerRequestData.DataAnalyzeMode = dataAnalyzeMode;

                customerRequestData.DeviceAddress           = (byte)firstDataPoint.DeviceAddress;
                customerRequestData.FunctionNum             = FunctionNumType.FunctionNum16;
                customerRequestData.StartingRegisterAddress = (ushort)theFirstRegisterAddress;

                foreach (var dataPoint in dataPoints)
                {
                    customerRequestData.PresetData.Add((double)dataPoint.ValueToSet);
                }

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

            case DataPointDataType.Bit:
                break;

            default:
                break;
            }


            return(requestCommandByteStreams);
        }
Beispiel #5
0
        /// <summary>
        /// 因为:功能码06是设置单个寄存器(占两字节,所以T的类型只能为short ushort)的值
        /// </summary>
        /// <param name="dataPoints"></param>
        /// <returns></returns>
        private static List <List <byte> > CreateRequestCommandByteStreamForFunNum06(DataAnalyzeMode dataAnalyzeMode, List <DataPoint> dataPoints)
        {
            List <List <byte> > requestCommandByteStreams = new List <List <byte> >();

            DataPoint firstDataPoint = dataPoints.First();

            int theFirstRegisterAddress = dataPoints.First().StartRegisterAddress;

            switch (firstDataPoint.DataPointDataType)
            {
            case DataPointDataType.S16:
            {
                FunNum06CustomerRequestData <short> customerRequestData =
                    new FunNum06CustomerRequestData <short>();
                customerRequestData.DataAnalyzeMode = dataAnalyzeMode;

                customerRequestData.DeviceAddress   = (byte)firstDataPoint.DeviceAddress;
                customerRequestData.FunctionNum     = FunctionNumType.FunctionNum06;
                customerRequestData.RegisterAddress = (ushort)theFirstRegisterAddress;
                customerRequestData.PresetData      = (short)firstDataPoint.ValueToSet;

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

            case DataPointDataType.U16:
            {
                FunNum06CustomerRequestData <ushort> customerRequestData =
                    new FunNum06CustomerRequestData <ushort>();
                customerRequestData.DataAnalyzeMode = dataAnalyzeMode;


                customerRequestData.DeviceAddress   = (byte)firstDataPoint.DeviceAddress;
                customerRequestData.FunctionNum     = FunctionNumType.FunctionNum06;
                customerRequestData.RegisterAddress = (ushort)theFirstRegisterAddress;
                customerRequestData.PresetData      = (ushort)firstDataPoint.ValueToSet;

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

            case DataPointDataType.S32:
            case DataPointDataType.U32:
            case DataPointDataType.S64:
            case DataPointDataType.U64:
            case DataPointDataType.F32:
            case DataPointDataType.D64:
                //因为:功能码06是设置单个寄存器(占两字节,所以T的类型只能为short ushort)的值
                //其他T类型只能由功能码16(设置多个寄存器的值)去处理
                requestCommandByteStreams = CreateRequestCommandByteStreamForFunNum16(dataAnalyzeMode, dataPoints);
                break;

            case DataPointDataType.Bit:
                break;

            default:
                break;
            }

            return(requestCommandByteStreams);
        }