コード例 #1
0
 /// <summary>
 /// 读取设备唯一标识
 /// </summary>
 public UniqueIdentifier ReadUniqueID(bool optical = false)
 {
     if (!optical)
     {
         _ID = _HartComport.ReadUniqueID(PollingAddress);
     }
     return(_ID);
 }
コード例 #2
0
 /// <summary>
 /// 关闭与设备的连接
 /// </summary>
 public void Close()
 {
     _ID = null;
     if (_HartComport != null && _HartComport.IsOpened)
     {
         _HartComport.Close();
     }
 }
コード例 #3
0
 /// <summary>
 /// 连接设备
 /// </summary>
 public void Connect()
 {
     if (_HartComport == null && Comport > 0 && Baud > 0)
     {
         _HartComport       = new HartComport(Comport, Baud);
         _HartComport.Debug = Debug;
     }
     if (_HartComport != null && !_HartComport.IsOpened)
     {
         _HartComport.Open();
     }
     if (_HartComport != null && _HartComport.IsOpened)
     {
         _ID = _HartComport.ReadUniqueID(PollingAddress);
     }
 }
コード例 #4
0
ファイル: HartComport.cs プロジェクト: wpmyj/512-HartTool
        /// <summary>
        /// 读取设备唯一标识
        /// </summary>
        public UniqueIdentifier ReadUniqueID(int shortAddress)
        {
            UniqueIdentifier ret     = null;
            RequestPacket    request = new RequestPacket()
            {
                LongOrShort = 0, Address = shortAddress, Command = 0x00
            };
            ResponsePacket response = Request(request);

            if (response != null && response.DataContent != null && response.DataContent.Length >= 12)
            {
                ret = new UniqueIdentifier();
                ret.ManufactureID         = response.DataContent[1];
                ret.ManufactureDeviceType = response.DataContent[2];
                ret.DeviceID = LJH.GeneralLibrary.SEBinaryConverter.BytesToInt(new byte[] { response.DataContent[11], response.DataContent[10], response.DataContent[9] });
            }
            return(ret);
        }
コード例 #5
0
 private void ShowDeviceState()
 {
     HartSDK.UniqueIdentifier did = null;
     if (HartDevice != null && HartDevice.IsConnected)
     {
         did = HartDevice.ReadUniqueID();
     }
     txtDeviceID.IntergerValue      = did != null ? did.DeviceID : 0;
     btnWritePollingAddress.Enabled = HartDevice != null && HartDevice.IsConnected;
     btnWritePollingAddress.Enabled = HartDevice != null && HartDevice.IsConnected;
     foreach (Control ctrl in pCommand.Controls)
     {
         if (ctrl is Button)
         {
             ctrl.Enabled = HartDevice != null && HartDevice.IsConnected;
         }
     }
     if (_ActiveForm != null)
     {
         IHartCommunication iHart = _ActiveForm as IHartCommunication;
         iHart.HartDevice = HartDevice;
         iHart.ReadData();
     }
 }