예제 #1
0
        /// <summary>
        /// Creates a new Modbus command based on the element configuration.
        /// </summary>
        private ModbusCmd CreateModbusCmd(DeviceTemplateOptions options,
                                          ElemGroupConfig elemGroupConfig, ElemConfig elemConfig, int elemIndex)
        {
            ModbusCmd modbusCmd = deviceModel.CreateModbusCmd(elemGroupConfig.DataBlock, false);

            modbusCmd.Name      = elemConfig.Name;
            modbusCmd.Address   = (ushort)(elemGroupConfig.Address + elemIndex);
            modbusCmd.ElemType  = elemConfig.ElemType;
            modbusCmd.ElemCnt   = 1;
            modbusCmd.ByteOrder = ModbusUtils.ParseByteOrder(elemConfig.ByteOrder) ??
                                  options.GetDefaultByteOrder(ModbusUtils.GetDataLength(elemConfig.ElemType));
            modbusCmd.CmdNum  = 0;
            modbusCmd.CmdCode = elemConfig.TagCode;

            modbusCmd.InitReqPDU();
            modbusCmd.InitReqADU(deviceModel.Addr, transMode);
            return(modbusCmd);
        }
예제 #2
0
        /// <summary>
        /// Creates a new Modbus command based on the command configuration.
        /// </summary>
        private ModbusCmd CreateModbusCmd(DeviceTemplateOptions options, CmdConfig cmdConfig)
        {
            ModbusCmd modbusCmd = deviceModel.CreateModbusCmd(cmdConfig.DataBlock, cmdConfig.Multiple);

            modbusCmd.Name      = cmdConfig.Name;
            modbusCmd.Address   = (ushort)cmdConfig.Address;
            modbusCmd.ElemType  = cmdConfig.ElemType;
            modbusCmd.ElemCnt   = cmdConfig.ElemCnt;
            modbusCmd.ByteOrder = ModbusUtils.ParseByteOrder(cmdConfig.ByteOrder) ??
                                  options.GetDefaultByteOrder(ModbusUtils.GetDataLength(cmdConfig.ElemType) * cmdConfig.ElemCnt);
            modbusCmd.CmdNum  = cmdConfig.CmdNum;
            modbusCmd.CmdCode = cmdConfig.CmdCode;

            if (cmdConfig.DataBlock == DataBlock.Custom)
            {
                modbusCmd.SetFuncCode((byte)cmdConfig.CustomFuncCode);
            }

            modbusCmd.InitReqPDU();
            modbusCmd.InitReqADU(deviceModel.Addr, transMode);
            return(modbusCmd);
        }