//async internal void PlayFile(string GCodeFilePath, Func <string, DeviceGcodePlayStates, string[]> task = null) { if (!File.Exists(GCodeFilePath)) { throw new Exception("File not Existents"); } GCode = new List <string>(File.ReadAllLines(GCodeFilePath)); this.Playing = true; this.CurentCodePossitionIndex = -1; SerialPortData.Clear(); PlayAction = task; if (this.PlayAction != null) { var extraGCode = this.PlayAction(null, DeviceGcodePlayStates.Start); this.priorityCommands.AddRange(extraGCode); } try { while (this.Playing) { //InputReceivedTimeOut.CancelAfter(TimeSpan.FromSeconds(5)); if (!SendNextLine()) { if (this.PlayAction == null) { break; } var extraGCode = this.PlayAction(null, DeviceGcodePlayStates.End); this.priorityCommands.AddRange(extraGCode); if (!SendNextLine()) { break; } } if (!OkInputReceived.WaitOne(TimeSpan.FromSeconds(this.DeviceTimoutSeconds))) { this.OnTimoutOccurred("Device not responding"); this.OnJobFinished(false); break; } } } catch (Exception ex) { this.OnErrorOccurred(ex); } finally { this.Playing = false; } return; }
protected string StartSerialReading(SerialPortData serialPortData, HardwareSerialProtocolName protocol, ref string Data) { string res = serialPortData.StartCommandTrans(protocol.ToString(), GetSerialData); if (res == "") { Data = serialPortData.Data; } return(res); }
/// <summary> /// 添加一个串口控制类SerialPortControl实例。 /// </summary> /// <param name="serialport">串口控制类实例</param> public void AddHardware(SerialPortData serialport) { if (serialport == null) { return; } if (_SerialPortCollection.ContainsKey(serialport.OwnerPort.PortName)) { return; } _SerialPortCollection.Add(serialport.OwnerPort.PortName, serialport); }
public CommandForm(MainForm mainform) { m_mainform = mainform; m_atc = mainform.m_atc; m_spPort = mainform.m_spPort; //m_cmdClient = mainform.m_cmdClient; InitializeComponent(); m_atc.ReceivedEventHandle = OnReceivedCommand; //try //{ //if(m_mainform.IsNetworkConnected()) //{ //m_cmdClient = new TextCmdClient(); //m_cmdClient.Host = m_mainform.m_address;// "localhost"; //m_cmdClient.Port = MainForm.COMMANDS_PORT; //m_cmdClient.OnReceivedEventHandle = m_atc.ReceivedFunc; //m_atc.SendCmd = m_cmdClient.Send; //m_atc.ReceivedEventHandle = OnReceivedCommand; //m_cmdClient.Start(); //} //else //{ //m_atc.SendCmd = m_spPort.SendData; //m_spPort.ReceivedDataHandle = m_atc.ReceivedFunc; //m_atc.ReceivedEventHandle = OnReceivedCommand; //m_mainform.m_spPort.ReceivedDataHandle = OnReceivedCommand; //} //m_sw = new System.IO.StreamWriter(System.Windows.Forms.Application.StartupPath + "\\Debug" + System.DateTime.Now.ToShortDateString() + ".log", true, Encoding.ASCII); //} //catch //{ // MessageBox.Show("Connect Error!"); // this.Close(); //} }
protected void StopSerialRealSend(SerialPortData serialPortData) { serialPortData.StopRealSend(); }
protected void StartSerialRealSend(SerialPortData serialPortData, HardwareSerialProtocolName protocol) { serialPortData.StartRealSend(protocol.ToString(), "", null, 500); }
//public void NotifyDoneEvent(EnumEventName eventname, string eventinfo = "") //{ // _ioPublisher.notifyDoneEventSubscribers(this, new StateEventArgs(eventname.ToString(), eventinfo)); //} protected bool GetSerialData(string ReadString, ref string GetData, SerialPortData PortData) { return(PortData.GetReturnData(ReadString, ref GetData, PortData)); }
public SystemHardware() { hardwares = HardwareInfoList.ReadSetting(); HardwareInfoList.SaveSetting(hardwares); CommonFunction.CheckAndRestore(CommonFunction.DefaultConfigPath + "MotionConfig0.cfg", CommonFunction.DefaultBackupConfigPath + "MotionConfig0.cfg"); CommonFunction.CheckAndRestore(CommonFunction.DefaultConfigPath + "MotionConfig1.cfg", CommonFunction.DefaultBackupConfigPath + "MotionConfig1.cfg"); CommonFunction.CheckAndRestore(CommonFunction.DefaultConfigPath + "MotionConfig2.cfg", CommonFunction.DefaultBackupConfigPath + "MotionConfig2.cfg"); CommonFunction.CheckAndRestore(CommonFunction.DefaultConfigPath + "MotionConfig3.cfg", CommonFunction.DefaultBackupConfigPath + "MotionConfig3.cfg"); CommonFunction.CheckAndRestore(CommonFunction.DefaultConfigPath + "ExtMdl1.cfg", CommonFunction.DefaultBackupConfigPath + "ExtMdl1.cfg"); m_MotionCards[0] = new GTS_CAxisCard(new GTS_CardArg(0, "GTS-400#1", GTS_CardType.GTS400PG), CommonFunction.DefaultConfigPath + "MotionConfig0.cfg"); m_MotionCards[1] = new GTS_CAxisCard(new GTS_CardArg(1, "GTS-400#2", GTS_CardType.GTS400PG), CommonFunction.DefaultConfigPath + "MotionConfig1.cfg"); m_MotionCards[2] = new GTS_CAxisCard(new GTS_CardArg(2, "GTS-400#3", GTS_CardType.GTS400PG), CommonFunction.DefaultConfigPath + "MotionConfig2.cfg"); m_MotionCards[3] = new GTS_CAxisCard(new GTS_CardArg(3, "GTS-400#4", GTS_CardType.GTS400PG), CommonFunction.DefaultConfigPath + "MotionConfig3.cfg"); m_IOSysList[0] = ((GTS_CAxisCard)m_MotionCards[0]).IOSys; m_IOSysList[1] = ((GTS_CAxisCard)m_MotionCards[1]).IOSys; m_IOSysList[2] = ((GTS_CAxisCard)m_MotionCards[2]).IOSys; m_IOSysList[3] = ((GTS_CAxisCard)m_MotionCards[3]).IOSys; m_IOSysList[4] = new GoogleExtIOSystem("GoogleExt", 4, 64, 64, CommonFunction.DefaultConfigPath + "ExtMdl1.cfg"); for (int i = 0; i < m_SerialPortControlList.Length; i++) { m_SerialPortControlList[i] = new SerialPortControl(m_SystemSerialPorts, ((HardwareSerialPortName)i).ToString()); m_SerialPortDataList[i] = new SerialPortData(m_SerialPortControlList[i]); } BaseIOPort temp; for (int i = 0; i < 64; i++) { temp = m_IOSysList[i / 16].GetInPort(i % 16); temp.PortName = "In" + ((HardwareInportName)i).ToString(); temp.PortCode = "EXI" + i.ToString("000"); if (temp.ReadSetting()) { temp.WriteSetting(); } temp = m_IOSysList[i / 16].GetOutPort(i % 16); temp.PortName = "Out" + ((HardwareOutportName)i).ToString(); temp.PortCode = "EXO" + i.ToString("000"); if (temp.ReadSetting()) { temp.WriteSetting(); } temp.SetOutput(false); } for (int i = 0; i < 64; i++) { temp = m_IOSysList[4].GetInPort(i); temp.PortName = "In" + ((HardwareInportName)(i + 64)).ToString(); temp.PortCode = "EXI" + (i + 64).ToString("000"); if (temp.ReadSetting()) { temp.WriteSetting(); } temp = m_IOSysList[4].GetOutPort(i); temp.PortName = "Out" + ((HardwareOutportName)(i + 64)).ToString(); temp.PortCode = "EXO" + (i + 64).ToString("000"); if (temp.ReadSetting()) { temp.WriteSetting(); } temp.SetOutput(false); } }