public void ReleaseAll() { if (_isConnected) { tellListeners_Disconnect(_portName); } _isConnected = false; _isConnecting = false; if (_port != null) { _port.Dispose(); if (_port.IsOpen) { _port.Close(); } } _portName = null; stopReadThread(); _insertAndPullOutMonitorTimer.Dispose(); if (_connectTimeOutMonitorTimer != null) { _connectTimeOutMonitorTimer.Dispose(); } _INSTANCE = null; }
void onClick_connect() { if (PortConnectManager.GetInstance().IsConnected()) { AlertMananger.GetInstance().ShowConfirmDialog("Disconnect", "Are you sure you want to disconnect? The printing will fail if you disconnect when printing.", this); return; } if (PortConnectManager.GetInstance().IsConnecting()) { AlertMananger.GetInstance().ShowToast("Connecting, wait a minute."); return; } if (PortConnectManager.GetAllPortNames().Count == 0) { Debug.LogWarning("No port found" + "\n"); AlertMananger.GetInstance().ShowToast("Please connect the printer to your computer using the provided USB cable."); return; } if (dropdown_port.value >= PortConnectManager.GetAllPortNames().Count) { AlertMananger.GetInstance().ShowToast("Selelct a port first."); return; } //try to connect _loadingMsgId = AlertMananger.GetLoadingMsgId(); AlertMananger.GetInstance().ShowAlertLoading("Connecting...", _loadingMsgId); string portName = PortConnectManager.GetAllPortNames()[dropdown_port.value]; PortConnectManager.GetInstance().Connect(portName); }
/*************** main functions ***************/ public bool StartSend(string gcodeFilePath) { if (string.IsNullOrEmpty(gcodeFilePath) || !File.Exists(gcodeFilePath)) { Debug.Log("StartSend failed : Gcode File Path Exception" + "\n"); return(false); } //check port is ready ? if (!PortConnectManager.GetInstance().IsConnected()) { Debug.LogWarning("Port not connect " + "\n"); return(false); } foreach (Listener listener in _listenerList) { listener.OnSendStarted(); } StageManager.SetStage_Gcode_Send(); _struct.sending_GcodeFile = true; _struct.stop_Manaual = false; _struct.progress = 0; _struct.completedZ = 0; _gcodeQueue.Clear(); //M1001 L lock screen // _gcodeQueue.Enqueue ("M1001 L"); string[] gcodeList = File.ReadAllLines(gcodeFilePath); for (int i = 0; i < gcodeList.Length; i++) { string cmd = gcodeList [i]; //_gcodeQueue not include notes if (!cmd.StartsWith(";") && !string.IsNullOrEmpty(cmd) && cmd.Trim().Length > 0) { _gcodeQueue.Enqueue(cmd.Trim()); } //insert M105 per 10 lines if (i % 10 == 0) { _gcodeQueue.Enqueue("M105"); } } _gcodeLineCount = _gcodeQueue.Count; //send a cmd and receive "ok", so start send PortConnectManager.GetInstance().WriteCmd("M105"); Debug.Log("StartSend succeed" + "\n"); return(true); }
public static GcodeSenderManager GetInstance() { if (_INSTANCE == null) { _INSTANCE = new GcodeSenderManager(); PortConnectManager.GetInstance().AddListener(_INSTANCE); } return(_INSTANCE); }
void OnDestroy() { delteTempDir(); ConfigManager.GetInstance().ArchiveCustomProfiles(); ConfigManager.GetInstance().ArchiveParamsOfCustomMaterial(); PortConnectManager.GetInstance().ReleaseAll(); }
void Awake() { PortConnectManager.GetInstance().AddListener(this); ss_connect = new SpriteState(); ss_disconnect = new SpriteState(); sp_connect = Resources.Load("Images/cancel", typeof(Sprite)) as Sprite; ss_connect.pressedSprite = Resources.Load("Images/cancel_hover", typeof(Sprite)) as Sprite; sp_disconnect = Resources.Load("Images/confirm", typeof(Sprite)) as Sprite; ss_disconnect.pressedSprite = Resources.Load("Images/confirm_hover", typeof(Sprite)) as Sprite; }
void Update() { updateDropdown(PortConnectManager.GetAllPortNames()); if (PortConnectManager.GetInstance().IsConnected()) { btn_connect.spriteState = ss_connect; btn_connect.gameObject.GetComponent <Image>().sprite = sp_connect; btn_connect.GetComponentInChildren <Text>().text = "Disconnect"; } else { btn_connect.spriteState = ss_disconnect; btn_connect.gameObject.GetComponent <Image>().sprite = sp_disconnect; btn_connect.GetComponentInChildren <Text>().text = "Connect"; } }
public static PortConnectManager GetInstance() { if (_INSTANCE == null) { _INSTANCE = new PortConnectManager(); _INSTANCE._isConnected = false; _INSTANCE._isConnecting = false; //_INSTANCE._port = new SerialPort(); _INSTANCE._keepReading = false; _INSTANCE.startInsertMonitorTimer(); _INSTANCE._lastPortNameList = GetAllPortNames(); } return(_INSTANCE); }
public void OnConfirm() { PortConnectManager.GetInstance().Disconnect(); }
void Update() { //hide operate container when click empty place. check update_mode if (!EventSystem.current.IsPointerOverGameObject()) { if (Input.GetKeyDown(KeyCode.Mouse0)) { _mode = Mode_Enum.None; } } /*************** btn_export ***************/ bool exportable = StageManager.GetStageList().Contains(StageManager.Stage_Enum.Gcode_Render) && GcodeRenderManager.GetInstance().GetInfo().isRendered&& StageManager.GetCurStage() != StageManager.Stage_Enum.Gcode_Send && GcodeRenderManager.GetInstance().IsInBounds(); if (exportable) { btn_export.spriteState = _ss_exportEnable; btn_export.gameObject.GetComponent <Image>().sprite = _sp_export_normal; } else { btn_export.spriteState = _ss_exportDisable; btn_export.gameObject.GetComponent <Image>().sprite = _sp_export_disable; } /*************** btn_print ***************/ bool active_print = StageManager.GetStageList().Contains(StageManager.Stage_Enum.Gcode_Render) && !GcodeRenderManager.GetInstance().GetInfo().isParsing&& StageManager.GetCurStage() != StageManager.Stage_Enum.Gcode_Send && PortConnectManager.GetInstance().IsConnected() && GcodeRenderManager.GetInstance().IsInBounds(); btn_print.interactable = active_print; /*************** other widget ***************/ switch (StageManager.GetCurStage()) { case StageManager.Stage_Enum.Idle: btn_open.interactable = true; btn_move.interactable = false; btn_scale.interactable = false; btn_rotate.interactable = false; img_moveContainer.GetComponent <Transform>().gameObject.SetActive(false); img_scaleContainer.GetComponent <Transform>().gameObject.SetActive(false); img_rotateContainer.GetComponent <Transform>().gameObject.SetActive(false); break; case StageManager.Stage_Enum.Load_Model: if (ModelManager.GetInstance().GetInfo().isParsing) { btn_open.interactable = false; btn_move.interactable = false; btn_scale.interactable = false; btn_rotate.interactable = false; img_moveContainer.GetComponent <Transform>().gameObject.SetActive(false); img_scaleContainer.GetComponent <Transform>().gameObject.SetActive(false); img_rotateContainer.GetComponent <Transform>().gameObject.SetActive(false); } else { btn_open.interactable = true; btn_move.interactable = true; btn_scale.interactable = true; btn_rotate.interactable = true; update_mode(); } break; case StageManager.Stage_Enum.Gcode_Create: btn_open.interactable = false; btn_move.interactable = false; btn_scale.interactable = false; btn_rotate.interactable = false; img_moveContainer.GetComponent <Transform>().gameObject.SetActive(false); img_scaleContainer.GetComponent <Transform>().gameObject.SetActive(false); img_rotateContainer.GetComponent <Transform>().gameObject.SetActive(false); break; case StageManager.Stage_Enum.Gcode_Render: //Sigle thread so far //todo: Rendering/Rendered if (GcodeRenderManager.GetInstance().GetInfo().isParsing) { btn_open.interactable = false; btn_move.interactable = false; btn_scale.interactable = false; btn_rotate.interactable = false; img_moveContainer.GetComponent <Transform>().gameObject.SetActive(false); img_scaleContainer.GetComponent <Transform>().gameObject.SetActive(false); img_rotateContainer.GetComponent <Transform>().gameObject.SetActive(false); } else { btn_open.interactable = true; btn_move.interactable = true; btn_scale.interactable = true; btn_rotate.interactable = true; update_mode(); } break; case StageManager.Stage_Enum.Gcode_Send: btn_open.interactable = false; btn_move.interactable = false; btn_scale.interactable = false; btn_rotate.interactable = false; img_moveContainer.GetComponent <Transform>().gameObject.SetActive(false); img_scaleContainer.GetComponent <Transform>().gameObject.SetActive(false); img_rotateContainer.GetComponent <Transform>().gameObject.SetActive(false); break; } if (ModelManager.GetInstance().GetRenderOperateBean() != null) { if (!input_moveX.isFocused) { input_moveX.text = (ModelManager.GetInstance().GetRenderOperateBean().move.x).ToString("0.0"); } if (!input_moveY.isFocused) { input_moveY.text = (ModelManager.GetInstance().GetRenderOperateBean().move.y).ToString("0.0"); } if (!input_scale.isFocused) { input_scale.text = (ModelManager.GetInstance().GetRenderOperateBean().scale * 100).ToString("0.0"); } if (!input_rotateX.isFocused) { input_rotateX.text = (ModelManager.GetInstance().GetRenderOperateBean().rotate.x).ToString("0.0"); } if (!input_rotateY.isFocused) { input_rotateY.text = (ModelManager.GetInstance().GetRenderOperateBean().rotate.y).ToString("0.0"); } if (!input_rotateZ.isFocused) { input_rotateZ.text = (ModelManager.GetInstance().GetRenderOperateBean().rotate.z).ToString("0.0"); } slider_moveX.value = ModelManager.GetInstance().GetRenderOperateBean().move.x; slider_moveY.value = ModelManager.GetInstance().GetRenderOperateBean().move.y; slider_scale.value = ModelManager.GetInstance().GetRenderOperateBean().scale; slider_rotateX.value = ModelManager.GetInstance().GetRenderOperateBean().rotate.x; slider_rotateY.value = ModelManager.GetInstance().GetRenderOperateBean().rotate.y; slider_rotateZ.value = ModelManager.GetInstance().GetRenderOperateBean().rotate.z; } }
public void OnPortReceive(string line) { line = line.Trim(); if (line.StartsWith("T:") || line.StartsWith("ok T:")) { updateTemp(line); } if (line.ToLower().Contains("ok")) { if (_struct.stop_Manaual) { if (_endGcodeQueue_stopManaual.Count > 0) { string cmd = _endGcodeQueue_stopManaual.Dequeue(); PortConnectManager.GetInstance().WriteCmd(cmd); return; } } if (_struct.sending_GcodeFile) { if (_gcodeQueue.Count > 0) { string cmd = _gcodeQueue.Dequeue(); PortConnectManager.GetInstance().WriteCmd(cmd); updateProgress(); updateCompletedZ(cmd); } else { //print completed Debug.Log("Printing completed" + "\n"); _struct.sending_GcodeFile = false; _struct.stop_Manaual = false; _gcodeQueue.Clear(); _gcodeLineCount = 0; _struct.temp_target_nozzle = 0; _struct.temp_cur_nozzle = 0; _struct.temp_target_bed = 0; _struct.temp_cur_bed = 0; StageManager.GetStageList().Remove(StageManager.Stage_Enum.Gcode_Send); StageManager.SetStage_Gcode_Render(); foreach (Listener listener in _listenerList) { listener.OnSendCompleted(); } } } else { //sub thread Thread.Sleep(1000); PortConnectManager.GetInstance().WriteCmd("M105"); } } }