private void Btn_Connect_Click(object sender, EventArgs e) { if (Btn_Connect.Text == "Connect") { string ip = TB_IP.Text; ushort port = ushort.Parse(TB_Port.Text); int timeout = 2; string ret = Itri2Fanuc.Connect(ip, port, timeout); if (ret == "EW_OK") { TB_ConStatus.Text = "Connect"; Btn_Connect.Text = "DisConnect"; TB_ConStatus.BackColor = Color.Green; Btn_Set.Enabled = true; Btn_Delete.Enabled = true; Btn_Start.Enabled = true; Btn_RdPrm.Enabled = true; Btn_WrPrm.Enabled = true; Btn_UploadCode.Enabled = true; Btn_DownloadCode.Enabled = true; Btn_FrqResStart.Enabled = true; TB_IP.Enabled = false; TB_Port.Enabled = false; mts.GetHndl(Itri2Fanuc); } else { MessageBox.Show("Connect failed:" + ret, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (Btn_Connect.Text == "DisConnect") { Itri2Fanuc.SamplingCancel(); Itri2Fanuc.SamplingEnd(); string ret = Itri2Fanuc.DisConnect(); if (ret == "EW_OK") { Inertial(); } } }
private void timer1_Tick(object sender, EventArgs e) { string SmplStat = "3"; try { SmplStat = Itri2Fanuc.SamplingRead(); } catch { MessageBox.Show("Memory Error(Please reboot CNC)", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); timer1.Enabled = false; } if (SmplStat.Equals("1") || SmplStat.Equals("0")) { //DateTime CurTime = new DateTime(); //CurTime = DateTime.Now; //MarkTime.Add((CurTime.Hour * 10000000) + (CurTime.Minute * 100000) + (CurTime.Second * 1000) + (CurTime.Millisecond)); TB_ConStatus.Text = "Sampling..."; if (DataIndex == 0) { Smplsw.Write("SamplingRate:" + SmplPeriod + "ms\r\n\r\n"); for (int i = 0; i < NumOfChanl; i++) { if (i == 0) { Smplsw.Write(SmplAxis[i] + "-" + SmplType[i]); } else { Smplsw.Write("," + SmplAxis[i] + "-" + SmplType[i]); } } Smplsw.Write("\r\n"); for (int i = 0; i < NumOfChanl; i++) { if (i == 0) { Smplsw.Write(SmplUnit[i]); } else { Smplsw.Write("," + SmplUnit[i]); } } Smplsw.Write("\r\n"); } for (int i = 0; i < Itri2Fanuc.DataLength; i++) { if (DataIndex % Math.Ceiling(SmplPeriod) == 0) { for (int j = 0; j < NumOfChanl; j++) { if (j == 0) { Smplsw.Write(Itri2Fanuc.CollectData[j, i]); } else { Smplsw.Write("," + Itri2Fanuc.CollectData[j, i]); } } Smplsw.Write("\r\n"); } DataIndex++; } if (SmplStat.Equals("0")) { string ret = Itri2Fanuc.SamplingEnd(); if (ret.Equals("EW_OK")) { TB_ConStatus.Text = "Sampling end"; Smplsw.Close(); Smplsw.Dispose(); Btn_Start.Enabled = true; Btn_End.Enabled = false; timer1.Enabled = false; //timer2.Enabled = false; } } } else if (SmplStat.Equals("-1")) { TB_ConStatus.Text = "Waiting for trigger..."; } }