/// <summary> /// 控制系统灯 /// </summary> /// <param name="colo"></param> /// <returns></returns> public bool ControlSystemLED(string colo) { SerialResponse re = null; if (colo.Equals("黄")) { re = Send(Commands.SystemLED, new List <byte>() { (byte)0 }); } else if (colo.Equals("绿")) { re = Send(Commands.SystemLED, new List <byte>() { (byte)1 }); } else if (colo.Equals("红")) { re = Send(Commands.SystemLED, new List <byte>() { (byte)2 }); } return(re.UserDatas[0] == 0); }
/// <summary> /// 右灯 /// </summary> /// <param name="status"></param> /// <returns></returns> public bool RightLamp(bool status) { SerialResponse re = Send(Commands.RightLamp, new List <byte>() { (byte)(status ? 1 : 0) }); if (re == null) { return(false); } return(re.UserDatas[0] == 0); }
/// <summary> /// 获得电动爪B的位置 /// </summary> /// <returns></returns> public int GetElectricClampB() { try { SerialResponse re = Send(Commands.ElectricClampBLocation, new List <byte>() { }); int reDis = re.UserDatas[2] + re.UserDatas[1] * 256; return(reDis); } catch (Exception e) { Log.error(e.Message); return(0); } }
/// <summary> /// 移动电动夹B /// </summary> /// <param name="distance"></param> /// <returns></returns> public bool MoveElectricClampB(int distance) { try { SerialResponse re = Send(Commands.ElectricClampB, splitIntToDoubleByte(distance)); if (re == null) { return(false); } return(re.UserDatas[0] == 0); } catch (Exception e) { Log.error(e.Message); return(false); } }
/// <summary> /// 控制速度 /// </summary> /// <param name="sta"></param> /// <returns></returns> public bool ControlSpeed(string sta) { try { SerialResponse re = Send(Commands.Speed, new List <byte>() { (byte)(Convert.ToInt32(sta) - 1) }); if (re == null) { return(false); } return(re.UserDatas[0] == 0); } catch (Exception e) { Log.error(e.Message); return(false); } }
/// <summary> /// 电动夹爪A归零 /// </summary> /// <returns></returns> public bool RefreshElectricClampA() { try { SerialResponse re = Send(Commands.ElectricClampAReset, new List <byte>() { (byte)1 }); if (re == null) { return(false); } return(re.UserDatas[0] == 0); } catch (Exception e) { Log.error(e.Message); return(false); } }
/// <summary> /// 发送数据 /// </summary> /// <param name="command"></param> /// <param name="datas"></param> /// <returns></returns> private SerialResponse Send(Commands command, List <byte> datas) { try { SerialRequest serialRequest = SerialControl.CreateRequest(); serialRequest.SetData((byte)command, datas); SerialResponse response = SerialControl.Send(serialRequest); if (response.SourceDatas == null || response.SourceDatas.Count() == 0) { Log.error("异常,未接收到任何数据"); throw new Exception("异常,为接收到任何数据!"); } if (response.UserDatas[0] != 0x00) { Log.error(string.Format("操作命令异常 : 命令关键字 - {0}, 错误吗 - {1}, 实际接收的全部数据 - {2}" , serialRequest.KeyWorld.ToString("x2"), response.UserDatas[0].ToString("x2"), response.SourceDatas.JoinToString(",", b => b.ToString("X2") ))); throw new Exception(string.Format("操作命令异常 : 命令关键字 - {0}, 错误吗 - {1}, 实际接收的全部数据 - {2}" , serialRequest.KeyWorld.ToString("x2"), response.UserDatas[0].ToString("x2"), response.SourceDatas.JoinToString(",", b => b.ToString("X2") ))); } else { Log.log("接受数据 : ", response.SourceDatas.JoinToString(",", b => b.ToString("X2") )); return(response); } } catch (Exception ex) { Log.error("发送数据问题:" + ex.Message); return(null); } }