示例#1
0
文件: PMA.cs 项目: shijiaquan/Chiller
        /// <summary>
        /// 获取指定通道的设定值
        /// </summary>
        /// <param name="Address">站号地址</param>
        /// <param name="Channel">通道地址</param>
        /// <param name="SP">设定的温度</param>
        /// <returns></returns>
        public static bool Get_SP(byte Address, ushort Channel, ref float SP)
        {
            if (PMAMaster == null)
            {
                return(false);
            }
            byte   SlaveAddress = Address;
            ushort StartAddress = (ushort)(17526 + Channel * 512);
            ushort DataLenght   = 1;

            ushort[] ReturnData;
            try
            {
                lock (LockValue)
                {
                    ReturnData = PMAMaster.ReadInputRegisters(SlaveAddress, StartAddress, DataLenght);
                }

                if (ReturnData != null && ReturnData.Length == DataLenght)
                {
                    SP = Auxiliary.UshortToShort(ReturnData[0]) / 10f;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// 获取电机当前速度
        /// </summary>
        /// <param name="address">站号</param>
        /// <param name="SpeedOut">读取的速度</param>
        /// <returns>成功或失败</returns>
        public static bool GetNowSpeed(byte Address, ref ushort SpeedOut)
        {
            try
            {
                ushort[] ReturnData;

                lock (LockValue)
                {
                    Thread.Sleep(2);
                    ReturnData = PanasonicA6Master.ReadHoldingRegisters(Address, 16421, 01);
                }

                if (ReturnData != null && ReturnData.Length != 0)
                {
                    SpeedOut = (ushort)Math.Abs(Auxiliary.UshortToShort(ReturnData[0]));
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
示例#3
0
文件: PMA.cs 项目: shijiaquan/Chiller
        /// <summary>
        /// 读取Y.Y2状态,是否激活Y2输出
        /// </summary>
        /// <param name="Address">站号地址</param>
        /// <param name="Channel">通道地址</param>
        /// <param name="State">使用Ref返回Y_Y2状态</param>
        /// <returns>成功或失败</returns>
        public static bool Get_Y_Y2(byte Address, ushort Channel, ref short State)
        {
            if (PMAMaster == null)
            {
                return(false);
            }
            byte   SlaveAddress = Address;
            ushort StartAddress = (ushort)(1495 + Channel * 512);
            ushort DataLenght   = 1;

            ushort[] Value;
            try
            {
                lock (LockValue)
                {
                    Value = PMAMaster.ReadHoldingRegisters(SlaveAddress, StartAddress, DataLenght);
                }

                if (Value.Length != DataLenght)
                {
                    return(false);
                }

                State = Auxiliary.UshortToShort(Value[0]);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// 获取电机编码器的温度
        /// </summary>
        /// <param name="Address">地址0-31</param>
        /// <param name="Temp">使用Ref返回电机编码器的温度</param>
        /// <returns></returns>
        public static bool GetEncoderTemp(byte Address, ref short Temp)
        {
            try
            {
                ushort[] ReturnData;

                lock (LockValue)
                {
                    Thread.Sleep(2);
                    ReturnData = PanasonicA6Master.ReadHoldingRegisters(Address, 16411, 01);
                }

                if (ReturnData != null && ReturnData.Length != 0)
                {
                    Temp = Auxiliary.UshortToShort(ReturnData[0]);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
示例#5
0
文件: PMA.cs 项目: shijiaquan/Chiller
        /// <summary>
        /// 获取全部通道的温度
        /// </summary>
        /// <param name="Address">站号地址</param>
        /// <param name="ChannelNumber">通道数量</param>
        /// <param name="Address">返回的温度数组</param>
        /// <returns>成功或失败</returns>
        public static bool GetAll_PV(byte Address, ushort ChannelNumber, ref float[] Temp)
        {
            if (PMAMaster == null)
            {
                return(false);
            }
            byte   SlaveAddress = Address;
            ushort StartAddress = (ushort)(17006);
            ushort DataLenght   = ChannelNumber;

            Temp = new float[ChannelNumber];
            ushort[] ReturnData;
            try
            {
                lock (LockValue)
                {
                    ReturnData = PMAMaster.ReadInputRegisters(SlaveAddress, StartAddress, DataLenght);
                }
                if (ReturnData != null && ReturnData.Length == DataLenght)
                {
                    for (int i = 0; i < DataLenght; i++)
                    {
                        Temp[i] = Auxiliary.UshortToShort(ReturnData[i]) / 10f;
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }