예제 #1
0
 /// <summary>
 /// 读取设备标签信息
 /// </summary>
 public DeviceTagInfo ReadTag(bool optical = false)
 {
     if (!optical || (_Tag == null && _ID != null))
     {
         _Tag = _HartComport.ReadTag(_ID.LongAddress);
     }
     return(_Tag);
 }
예제 #2
0
        /// <summary>
        /// 写标签信息
        /// </summary>
        public bool WriteTag(DeviceTagInfo tag)
        {
            if (_ID == null)
            {
                return(false);
            }
            bool ret = _HartComport.WriteTag(_ID.LongAddress, tag);

            if (ret)
            {
                _Tag = null;
            }
            return(ret);
        }
예제 #3
0
        /// <summary>
        /// 写标签信息
        /// </summary>
        public bool WriteTag(long longAddress, DeviceTagInfo tag)
        {
            RequestPacket request = new RequestPacket()
            {
                LongOrShort = 1,
                Address     = longAddress,
                Command     = 18,
            };
            List <byte> d = new List <byte>();

            d.AddRange(PackAsciiHelper.GetBytes(tag.Tag.PadRight(8, ' ').Substring(0, 8), 6));
            d.AddRange(PackAsciiHelper.GetBytes(tag.Description.PadRight(16, ' ').Substring(0, 16), 12));
            d.Add((byte)tag.Day);
            d.Add((byte)tag.Month);
            d.Add((byte)(tag.Year - 1990));
            request.DataContent = d.ToArray();
            ResponsePacket response = Request(request);

            return(response != null);
        }
예제 #4
0
        /// <summary>
        /// 读取设备标签信息
        /// </summary>
        public DeviceTagInfo ReadTag(long longAddress)
        {
            DeviceTagInfo ret     = null;
            RequestPacket request = new RequestPacket()
            {
                LongOrShort = 1, Address = longAddress, Command = 13
            };
            ResponsePacket response = Request(request);

            if (response != null && response.DataContent != null && response.DataContent.Length >= 21)
            {
                byte[] d = response.DataContent;
                ret             = new DeviceTagInfo();
                ret.Tag         = PackAsciiHelper.GetString(new byte[] { d[0], d[1], d[2], d[3], d[4], d[5] });                                             //字节0-5
                ret.Description = PackAsciiHelper.GetString(new byte[] { d[6], d[7], d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15], d[16], d[17] }); //字节6-17
                ret.Year        = 1990 + d[20];
                ret.Month       = d[19];
                ret.Day         = d[18];
            }
            return(ret);
        }