コード例 #1
0
        /// <summary>
        /// 解析协议消息
        /// </summary>
        /// <param name="rcvBytes"></param>
        /// <param name="rspBytes"></param>
        /// <returns></returns>
        private bool ParseMessage(byte[] rcvBytes, out byte[] rspBytes)
        {
            rspBytes = null;
            int len = rcvBytes.Length;

            if (CBType == CanbusType.RectOne)
            {
                //判断长度
                if (len != 12)
                {
                    return(false);
                }
                byte addr = (byte)(rcvBytes[0] * 2 + rcvBytes[1] / 128);
                //检查地址是否有设备
                if (!DeviceDict.ContainsKey(addr))
                {
                    return(false);
                }
                //设备处理消息
                CanbusDevice device = DeviceDict[rcvBytes[0]];
                return(device.ParseCanMessage(rcvBytes, out rspBytes));
            }
            else if (CBType == CanbusType.RectTwo)
            {
                return(false);
            }
            return(false);
        }
コード例 #2
0
 /// <summary>
 /// 根据设备名获取设备
 /// </summary>
 /// <param name="devicename">设备名称</param>
 /// <param name="device">设备</param>
 /// <returns></returns>
 public bool GetDeviceByName(string devicename, out CanbusDevice device)
 {
     foreach (CanbusDevice dv in DeviceDict.Values)
     {
         if (dv.Name == devicename)
         {
             device = dv;
             return(true);
         }
     }
     device = null;
     return(false);
 }
コード例 #3
0
 /// <summary>
 /// 增加设备
 /// </summary>
 /// <param name="device"></param>
 /// <returns></returns>
 public bool AddDevice(CanbusDevice device)
 {
     if ((DeviceDict.ContainsKey(device.Address)) || (DeviceNameDict.ContainsValue(device.Name)))
     {
         MsgLogger.PushMsg(device.Name, "Add", "Fail, already exist.");
         return(false);
     }
     else
     {
         DeviceDict.Add(device.Address, device);
         DeviceNameDict.Add(device.Address, device.Name);
         MsgLogger.PushMsg(device.Name, "Add", "Success.");
         return(true);
     }
 }