private void OnCollisionEnter(Collision collision) { if (collision.gameObject.layer == 9) { actions = Comport.IDDLE; } }
/// <summary> /// Get all serial port names /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PortDetails_Load(object sender, EventArgs e) { //string [] prt = SerialPort.GetPortNames(); List <string> comportList = Comport.GetComportList(); comportList.Add("COM1"); comportList.Add("COM2"); string[] prt = comportList.ToArray <string>(); IEnumerable <string> enu = prt.Distinct(); comboPort.DataSource = null; String[] ports = enu.ToArray <string>(); string[] portArray = new string[ports.Length]; for (int i = 0; i < ports.Length; i++) { ports[i] = ports[i].Trim(); for (int charChk = ports[i].Length - 1; charChk >= 0; charChk--) { if (Char.IsDigit(ports[i][charChk]) == false) { ports[i] = ports[i].Remove(charChk); } else { break; } } portArray[i] = ports[i]; } comboPort.DataSource = portArray; }
public void Activate() { RaycastHit hit; //if (state == transformations.GIGANT) { if (actions == Comport.CARGANDO) { bxSript.Soltar(); actions = Comport.IDDLE; } Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 10, Color.yellow); if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 10)) { if (hit.transform.gameObject.layer == 10) { bxSript = hit.transform.GetComponent <BoxScript>(); bxSript.Agarre(); Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 10, Color.red); Debug.Log("Did Hit"); actions = Comport.CARGANDO; } } //} }
public bool Init(MotionCardCfg motionCfg, ICommunicationPortCfg communicationPortCfg) { this.motionCfg = motionCfg; MAX_AXIS = motionCfg.MaxAxisNo; MIN_AXIS = motionCfg.MinAxisNo; comport = CommunicationMgr.Instance.FindPortByPortName(motionCfg.PortName) as Comport; _controller = IrixiEE0017.CreateInstance(motionCfg.PortName); if (comport == null) { return(false); } _controller = IrixiEE0017.CreateInstance(motionCfg.PortName); if (_controller != null) { _controller.OnAxisStateChanged += OnIrixiAxisStateChanged; if (motionCfg.NeedInit) { return(_controller.Init(Int32.Parse(comport.ToString().ToLower().Replace("com", "")))); } else { return(true); } } return(false); }
public bool Init(IOCardCfg ioCfg, ICommunicationPortCfg communicationPortCfg) { this.ioCfg = ioCfg; comport = CommunicationMgr.Instance.FindPortByPortName(ioCfg.PortName) as Comport; if (comport == null) { return(false); } else { _controller = IrixiEE0017.CreateInstance(ioCfg.PortName); if (_controller != null) { _controller.OnOutputStateChanged += _controller_OnOutputStateChanged; _controller.OnInputStateChanged += _controller_OnInputStateChanged; if (ioCfg.NeedInit) { return(_controller.Init(Int32.Parse(comport.ToString().ToLower().Replace("com", "")))); } else { return(true); } } return(false); } }
private void button_Stop_Click_1(object sender, EventArgs e) { // Close COM_Port try { Comport.Close(); } catch (Exception ex2) { MessageBox.Show(ex2.Message, "COM Port is using by another Process."); } }
private void Comport_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { // Read incoming serial data and read line by line com_RGB = Comport.ReadLine(); // pass that data to displaydata_event this.Invoke(new EventHandler(RGBpass_event)); } catch (Exception ex3) { MessageBox.Show(ex3.Message, "COM PORT Error : Restart Programme"); } }
public void Jump() { if (state == transformations.GIGANT) { return; } if (actions == Comport.AIR) { return; } if (actions == Comport.CARGANDO) { return; } rb.AddForce(transform.up * jumpForce, ForceMode.Impulse); actions = Comport.AIR; }
public bool Init(MotionCardCfg motionCfg, ICommunicationPortCfg communicationPortCfg) { try { this.motionCfg = motionCfg; MAX_AXIS = motionCfg.MaxAxisNo; MIN_AXIS = motionCfg.MinAxisNo; ComportCfg portCfg = communicationPortCfg as ComportCfg; comport = CommunicationMgr.Instance.FindPortByPortName(motionCfg.PortName) as Comport; _controller = M12Wrapper.CreateInstance(portCfg.Port, portCfg.BaudRate); _controller.OnUnitStateUpdated += OnIrixiAxisStateChanged; _controller.Open(); return(true); } catch { return(false); } }
public bool Init(IOCardCfg ioCfg, ICommunicationPortCfg communicationPortCfg) { try { this.ioCfg = ioCfg; ComportCfg portCfg = communicationPortCfg as ComportCfg; comport = CommunicationMgr.Instance.FindPortByPortName(ioCfg.PortName) as Comport; if (comport == null) { return(false); } else { _controller = M12Wrapper.CreateInstance(portCfg.Port, portCfg.BaudRate); _controller.Open(); return(true); } } catch { return(false); } }
//public static public void LoadConfig(out List <string> errList) { #region >>>>Hardware init errList = new List <string>(); try { var json_string = File.ReadAllText(File_HardwareCfg); HardwareCfgMgr = JsonConvert.DeserializeObject <HardwareCfgManager>(json_string); } catch (Exception ex) { errList.Add($"Unable to load config file { File_HardwareCfg}, { ex.Message}"); } IMotion motionBase = null; IIO ioBase = null; InstrumentBase instrumentBase = null; LightBase lightBase = null; Type hardWareMgrType = HardwareCfgMgr.GetType(); //先初始化通信端口 foreach (var it in hardWareMgrType.GetProperties()) { switch (it.Name) { case "Comports": foreach (var comportCfg in HardwareCfgMgr.Comports) { CommunicationPortBase port = new Comport(comportCfg); CommunicationMgr.Instance.AddCommunicationPort(comportCfg.PortName, port); } break; case "Ethernets": case "Gpibs": case "Visas": break; default: break; } } foreach (var it in hardWareMgrType.GetProperties()) { switch (it.Name) { case "MotionCards": var motionCfgs = it.GetValue(HardwareCfgMgr) as MotionCardCfg[]; if (motionCfgs == null) { break; } foreach (var motionCfg in motionCfgs) { if (motionCfg.Enabled) { motionBase = hardWareMgrType.Assembly.CreateInstance("JPT_TosaTest.MotionCards." + motionCfg.Name.Substring(0, motionCfg.Name.IndexOf("[")), true, BindingFlags.CreateInstance, null, /*new object[] { motionCfg }*/ null, null, null) as IMotion; if (motionBase != null) { if (motionCfg.ConnectMode.ToLower() != "none") { var p = hardWareMgrType.GetProperty($"{motionCfg.ConnectMode}s"); var portCfgs = p.GetValue(HardwareCfgMgr) as ICommunicationPortCfg[]; var ports = from portCfg in portCfgs where portCfg.PortName == motionCfg.PortName select portCfg; if (ports != null && ports.Count() > 0) { if (motionBase.Init(motionCfg, ports.ElementAt(0))) { //设置单位,轴类型, 软限位等 for (int i = 0; i < motionBase.MAX_AXIS - motionBase.MIN_AXIS + 1; i++) { var settings = HardwareCfgMgr.AxisSettings.Where(a => a.AxisNo == i + motionBase.MIN_AXIS); try { motionBase.SetAxisPara(i, settings == null ? null : settings.First()); } catch (Exception ex) { errList.Add($"{ex.Message}"); } } MotionMgr.Instance.AddMotionCard(motionCfg.Name, motionBase); } else { errList.Add($"{motionCfg.Name} init failed"); } } else { errList.Add($"{motionCfg.Name} init failed"); } } else //无需选择通信端口 { if (motionBase.Init(motionCfg, null)) { //设置单位,轴类型, 软限位等 for (int i = 0; i < motionBase.MAX_AXIS - motionBase.MIN_AXIS; i++) { var settings = HardwareCfgMgr.AxisSettings.Where(a => a.AxisNo == i + motionBase.MIN_AXIS); try { motionBase.SetAxisPara(i, settings == null ? null : settings.First()); } catch (Exception ex) { errList.Add($"{ex.Message}"); } } MotionMgr.Instance.AddMotionCard(motionCfg.Name, motionBase); } else { errList.Add($"{motionCfg.Name} init failed"); } } } else { errList.Add($"{motionCfg.Name} Create instanse failed"); } } } break; case "IOCards": var ioCfgs = it.GetValue(HardwareCfgMgr) as IOCardCfg[]; if (ioCfgs == null) { break; } foreach (var ioCfg in ioCfgs) { if (ioCfg.Enabled) { ioBase = hardWareMgrType.Assembly.CreateInstance("JPT_TosaTest.IOCards." + ioCfg.Name.Substring(0, ioCfg.Name.IndexOf("[")), true, BindingFlags.CreateInstance, null, null, null, null) as IIO; if (ioBase != null) { ioBase.ioCfg = ioCfg; if (ioCfg.ConnectMode.ToLower() != "none") //没有屏蔽端口 { var p = hardWareMgrType.GetProperty($"{ioCfg.ConnectMode}s"); var portCfgs = p.GetValue(HardwareCfgMgr) as ICommunicationPortCfg[]; var ports = from portCfg in portCfgs where portCfg.PortName == ioCfg.PortName select portCfg; if (ports != null && ports.Count() > 0) { if (ioBase.Init(ioCfg, ports.ElementAt(0))) { IOCardMgr.Instance.AddIOCard(ioCfg.Name, ioBase); } else { errList.Add($"{ioCfg.Name} init failed"); } } else { errList.Add($"{ioCfg.Name} init failed"); } } else //无需选择通信端口 { if (ioBase.Init(ioCfg, null)) { IOCardMgr.Instance.AddIOCard(ioCfg.Name, ioBase); } else { errList.Add($"{ioCfg.Name} init failed"); } } } else { errList.Add($"{ioCfg.Name} Create instanse failed"); } } } break; case "Instruments": var instrumentCfgs = it.GetValue(HardwareCfgMgr) as InstrumentCfg[]; if (instrumentCfgs == null) { break; } foreach (var instrumentCfg in instrumentCfgs) { if (instrumentCfg.Enabled) { instrumentBase = hardWareMgrType.Assembly.CreateInstance("JPT_TosaTest.Instruments." + instrumentCfg.InstrumentName.Substring(0, instrumentCfg.InstrumentName.IndexOf("[")), true, BindingFlags.CreateInstance, null, null, null, null) as InstrumentBase; if (instrumentBase != null) { if (instrumentBase.Init()) { } } } } break; case "Cameras": var cameraCfgs = it.GetValue(HardwareCfgMgr) as CameraCfg[]; break; case "Lights": var lightCfgs = it.GetValue(HardwareCfgMgr) as LightCfg[]; foreach (var lightCfg in lightCfgs) { if (lightCfg.Enabled) { lightBase = hardWareMgrType.Assembly.CreateInstance("JPT_TosaTest.Vision.Light." + lightCfg.Name.Substring(0, lightCfg.Name.IndexOf("[")), true, BindingFlags.CreateInstance, null, null, null, null) as LightBase; if (lightBase != null) { if (lightCfg.ConnectMode.ToLower() != "none") { var p = hardWareMgrType.GetProperty($"{lightCfg.ConnectMode}s"); var portCfgs = p.GetValue(HardwareCfgMgr) as ICommunicationPortCfg[]; var ports = from portCfg in portCfgs where portCfg.PortName == lightCfg.PortName select portCfg; if (ports != null && ports.Count() > 0) { if (lightBase.Init(lightCfg, ports.ElementAt(0))) //如果不需要初始化就直接加入字典 { LigtMgr.Instance.AddLight(lightCfg.Name, lightBase); } else { errList.Add($"{lightCfg.Name} init failed"); } } else { errList.Add($"{lightCfg.Name} init failed"); } } else //无需选择通信端口 { if (lightBase.Init(lightCfg, null)) { LigtMgr.Instance.AddLight(lightCfg.Name, lightBase); } else { errList.Add($"{lightCfg.Name} init failed"); } } } else { errList.Add($"{lightCfg.Name} Create instanse failed"); } } } break; default: break; } } #endregion #region >>>>Software init try { var json_string = File.ReadAllText(File_SoftwareCfg); SoftwareCfgMgr = JsonConvert.DeserializeObject <SoftwareCfgManager>(json_string); } catch (Exception ex) { errList.Add(String.Format("Unable to load config file {0}, {1}", File_SoftwareCfg, ex.Message)); } Type tStationCfg = SoftwareCfgMgr.GetType(); PropertyInfo[] pis = tStationCfg.GetProperties(); WorkFlowConfig[] WorkFlowCfgs = null; WorkFlowBase workFlowBase = null; foreach (PropertyInfo pi in pis) { if (pi.Name == "WorkFlowConfigs") { WorkFlowCfgs = pi.GetValue(SoftwareCfgMgr) as SoftwareManager.WorkFlowConfig[]; foreach (var it in WorkFlowCfgs) { if (it.Enable) { workFlowBase = tStationCfg.Assembly.CreateInstance("JPT_TosaTest.WorkFlow." + it.Name, true, BindingFlags.CreateInstance, null, new object[] { it }, null, null) as WorkFlowBase; if (workFlowBase == null) { errList.Add($"Station: {it.Name} Create instance failed!"); } else { WorkFlowMgr.Instance.AddStation(it.Name, workFlowBase); } } } } } #endregion #region >>>>SystemCfg try { var json_string = File.ReadAllText(File_SystemParaCfg); SystemParaCfgMgr = JsonConvert.DeserializeObject <SystemParaCfgManager>(json_string); } catch (Exception ex) { errList.Add(String.Format("Unable to load config file {0}, {1}", File_SystemParaCfg, ex.Message)); } #endregion #region >>>> UserCfg init try { var json_string = File.ReadAllText(File_UserCfg); UserCfgMgr = JsonConvert.DeserializeObject <UserCfgManager>(json_string); } catch (Exception ex) { errList.Add(String.Format("Unable to load config file {0}, {1}", File_UserCfg, ex.Message)); } #endregion #region >>>>ProcessPara //从文件中读取参数 try { var json_string = File.ReadAllText(File_ProcessPara); ProcessDataMgr = JsonConvert.DeserializeObject <ProcessParaMgr>(json_string); } catch (Exception ex) { errList.Add(String.Format("Unable to load config file {0}, {1}", File_UserCfg, ex.Message)); } #endregion }