Example #1
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);
            }
        }
Example #2
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);
            }
        }
Example #3
0
        /// <summary>
        /// 读取C_Off状态,是否关闭温控器输出
        /// </summary>
        /// <param name="Address">站号地址</param>
        /// <param name="Channel">通道地址</param>
        /// <param name="State">使用Ref返回C_Off状态</param>
        /// <returns>成功或失败</returns>
        public static bool Get_C_Off(byte Address, ushort Channel, ref bool State)
        {
            if (PMAMaster == null)
            {
                return(false);
            }
            byte   SlaveAddress = Address;
            ushort StartAddress = (ushort)(1497 + Channel * 512);
            ushort DataLenght   = 1;

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

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

                if (Auxiliary.UshortToShort(Value[0]) == 0)
                {
                    State = true;
                }
                else
                {
                    State = false;
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #4
0
        /// <summary>
        /// 设定加热功率上限
        /// </summary>
        /// <param name="Address">站号地址</param>
        /// <param name="Channel">通道地址</param>
        /// <param name="Limit">功率上限值</param>
        /// <returns></returns>
        public static bool SetPowerLimit(byte Address, ushort Channel, ushort Limit)
        {
            if (PMAMaster == null)
            {
                return(false);
            }
            byte   SlaveAddress = Address;
            ushort StartAddress = (ushort)(17572 + Channel * 512);
            ushort Value        = Auxiliary.ShortToUshort((short)(Limit * 10));

            try
            {
                lock (LockValue)
                {
                    PMAMaster.WriteSingleRegister(SlaveAddress, StartAddress, Value);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #5
0
        /// <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);
            }
        }