private List <FunNum16CustomerRequestData <T> > Splite()
        {
            List <FunNum16CustomerRequestData <T> > customerRequestDatas = new List <FunNum16CustomerRequestData <T> >();

            int canOperatingRegisterMaxNumOneTime = ModbusProtocolRule.GetCanOperatingRegisterMaxNumOneTime(this.FunctionNum);
            int byteCountOfT = GetByteCountOfT();
            int byteCountOfOneCustomerRequestData       = byteCountOfT * canOperatingRegisterMaxNumOneTime;
            int presetDataCountOfOneCustomerRequestData = canOperatingRegisterMaxNumOneTime;

            InilizationTotalNumOfPresetData();
            customerRequestDatas = CustomerRequstDataAuxiliary.Splite <FunNum16CustomerRequestData <T> >(this.FunctionNum, this.TotalNumOfPresetData);

            for (int i = 0; i < customerRequestDatas.Count; i++)
            {
                if (1 == customerRequestDatas.Count)
                {
                    customerRequestDatas[i].DeviceAddress           = this.DeviceAddress;
                    customerRequestDatas[i].FunctionNum             = this.FunctionNum;
                    customerRequestDatas[i].StartingRegisterAddress = (ushort)(this.StartingRegisterAddress + byteCountOfOneCustomerRequestData * i);
                    customerRequestDatas[i].PresetData = this.PresetData;
                    customerRequestDatas[i].InilizationTotalNumOfPresetData();
                }
                else if (1 < customerRequestDatas.Count)
                {
                    if (i < customerRequestDatas.Count - 1)  //第一个包到倒数第二个包
                    {
                        customerRequestDatas[i].DeviceAddress           = this.DeviceAddress;
                        customerRequestDatas[i].FunctionNum             = this.FunctionNum;
                        customerRequestDatas[i].StartingRegisterAddress = (ushort)(this.StartingRegisterAddress + byteCountOfOneCustomerRequestData * i);
                        customerRequestDatas[i].PresetData = this.PresetData.GetRange(presetDataCountOfOneCustomerRequestData * i, presetDataCountOfOneCustomerRequestData);
                        customerRequestDatas[i].InilizationTotalNumOfPresetData();
                    }
                    else if (i == customerRequestDatas.Count - 1) //倒数第一个包
                    {
                        int retainPresetDataCount = 0;
                        if (0 == (this.TotalNumOfPresetData % presetDataCountOfOneCustomerRequestData))
                        {
                            retainPresetDataCount = presetDataCountOfOneCustomerRequestData;
                        }
                        else
                        {
                            retainPresetDataCount = this.TotalNumOfPresetData % presetDataCountOfOneCustomerRequestData;
                        }
                        customerRequestDatas[i].DeviceAddress           = this.DeviceAddress;
                        customerRequestDatas[i].FunctionNum             = this.FunctionNum;
                        customerRequestDatas[i].StartingRegisterAddress = (ushort)(this.StartingRegisterAddress + byteCountOfOneCustomerRequestData * i);
                        customerRequestDatas[i].PresetData = this.PresetData.GetRange(presetDataCountOfOneCustomerRequestData * i, retainPresetDataCount);
                        customerRequestDatas[i].InilizationTotalNumOfPresetData();
                    }
                }
            }

            return(customerRequestDatas);
        }
Exemple #2
0
        private List <FunNum15CustomerRequestData> Splite()
        {
            List <FunNum15CustomerRequestData> customerRequestDatas = new List <FunNum15CustomerRequestData>();

            int canOperatingRegisterMaxNumOneTime = ModbusProtocolRule.GetCanOperatingRegisterMaxNumOneTime(this.FunctionNum);

            InitializeNumOfCoilToForce();

            customerRequestDatas = CustomerRequstDataAuxiliary.Splite <FunNum15CustomerRequestData>(
                FunctionNumType.FunctionNum15,
                this.NumOfCoilToForce);
            for (int i = 0; i < customerRequestDatas.Count; i++)
            {
                if (1 == customerRequestDatas.Count)
                {
                    customerRequestDatas[i].DeviceAddress       = this.DeviceAddress;
                    customerRequestDatas[i].FunctionNum         = this.FunctionNum;
                    customerRequestDatas[i].StartingCoilAddress = (ushort)(this.StartingCoilAddress + canOperatingRegisterMaxNumOneTime * i);
                    customerRequestDatas[i].NumOfCoilToForce    = (ushort)this.ForceData.Count;
                    customerRequestDatas[i].ForceData           = this.ForceData;
                }
                else if (1 < customerRequestDatas.Count)
                {
                    if (i < customerRequestDatas.Count - 1)  //第一个包到倒数第二个包
                    {
                        customerRequestDatas[i].DeviceAddress       = this.DeviceAddress;
                        customerRequestDatas[i].FunctionNum         = this.FunctionNum;
                        customerRequestDatas[i].StartingCoilAddress = (ushort)(this.StartingCoilAddress + canOperatingRegisterMaxNumOneTime * i);
                        customerRequestDatas[i].NumOfCoilToForce    = (ushort)canOperatingRegisterMaxNumOneTime;
                        customerRequestDatas[i].ForceData           = this.ForceData.GetRange(canOperatingRegisterMaxNumOneTime * i, canOperatingRegisterMaxNumOneTime);
                    }
                    else if (i == customerRequestDatas.Count - 1) //倒数第一个包
                    {
                        int retainForceDataCount = 0;
                        if (0 == (this.NumOfCoilToForce % canOperatingRegisterMaxNumOneTime))
                        {
                            retainForceDataCount = canOperatingRegisterMaxNumOneTime;
                        }
                        else
                        {
                            retainForceDataCount = this.NumOfCoilToForce % canOperatingRegisterMaxNumOneTime;
                        }
                        customerRequestDatas[i].DeviceAddress       = this.DeviceAddress;
                        customerRequestDatas[i].FunctionNum         = this.FunctionNum;
                        customerRequestDatas[i].StartingCoilAddress = (ushort)(this.StartingCoilAddress + canOperatingRegisterMaxNumOneTime * i);
                        customerRequestDatas[i].NumOfCoilToForce    = (ushort)retainForceDataCount;
                        customerRequestDatas[i].ForceData           = this.ForceData.GetRange(canOperatingRegisterMaxNumOneTime * i, retainForceDataCount);
                    }
                }
            }

            return(customerRequestDatas);
        }
Exemple #3
0
        /// <summary>
        /// 将每个请求帧的客户端格式分成更小的请求帧:
        /// 原因:每次可以操作的寄存器个数有限。
        /// </summary>
        /// <returns>若干个小包</returns>
        private List <FunNum03CustomerRequestData> Splite()
        {
            int canOperatingRegisterMaxNumOneTime = ModbusProtocolRule.GetCanOperatingRegisterMaxNumOneTime(this.FunctionNum);
            List <FunNum03CustomerRequestData> customerRequestDatas = null;

            customerRequestDatas = CustomerRequstDataAuxiliary.Splite <FunNum03CustomerRequestData>(this.FunctionNum, this.NumOfRegisterToRead);

            for (int i = 0; i < customerRequestDatas.Count; i++)
            {
                if (1 == customerRequestDatas.Count)
                {
                    customerRequestDatas[i].DeviceAddress           = this.DeviceAddress;
                    customerRequestDatas[i].FunctionNum             = this.FunctionNum;
                    customerRequestDatas[i].StartingRegisterAddress = (ushort)(this.StartingRegisterAddress + canOperatingRegisterMaxNumOneTime * i);
                    customerRequestDatas[i].NumOfRegisterToRead     = this.NumOfRegisterToRead;
                }
                else if (1 < customerRequestDatas.Count)
                {
                    if (i < customerRequestDatas.Count - 1)  //第一个包到倒数第二个包
                    {
                        customerRequestDatas[i].DeviceAddress           = this.DeviceAddress;
                        customerRequestDatas[i].FunctionNum             = this.FunctionNum;
                        customerRequestDatas[i].StartingRegisterAddress = (ushort)(this.StartingRegisterAddress + canOperatingRegisterMaxNumOneTime * i);
                        customerRequestDatas[i].NumOfRegisterToRead     = (ushort)canOperatingRegisterMaxNumOneTime;
                    }
                    else if (i == customerRequestDatas.Count - 1) //倒数第一个包
                    {
                        int retainRegisterCount = 0;
                        if (0 == (this.NumOfRegisterToRead % canOperatingRegisterMaxNumOneTime))
                        {
                            retainRegisterCount = canOperatingRegisterMaxNumOneTime;
                        }
                        else
                        {
                            retainRegisterCount = this.NumOfRegisterToRead % canOperatingRegisterMaxNumOneTime;
                        }

                        customerRequestDatas[i].DeviceAddress           = this.DeviceAddress;
                        customerRequestDatas[i].FunctionNum             = this.FunctionNum;
                        customerRequestDatas[i].StartingRegisterAddress = (ushort)(this.StartingRegisterAddress + canOperatingRegisterMaxNumOneTime * i);
                        customerRequestDatas[i].NumOfRegisterToRead     = (ushort)retainRegisterCount;
                    }
                }
            }

            return(customerRequestDatas);
        }