private void start_button_Click(object sender, EventArgs e) { if (!HNC_Connect.iscon) { } else if (HNC_Connect.iscon && (!HNC_Connect.smplseted)) { } HNC_Connect.smplon(); }
private void cfirm_button_Click(object sender, EventArgs e) { if (!HNC_Connect.check_connect()) { MessageBox.Show("请先连接机床", "提示", MessageBoxButtons.OK); return; } HNC_Connect.smplperiod(); HNC_Connect.smplset(Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text)); Thread.Sleep(10); HNC_Connect.smplset(Convert.ToInt32(textBox3.Text), Convert.ToInt32(textBox4.Text)); HNC_Connect.smplseted = true; cfirm_button.Text = "已配置"; this.Visible = false; }
private void connect_button_Click(object sender, EventArgs e) { ipl = local_textBox.Text; ipr = remote_textBox.Text; port = Convert.ToUInt16(port_textBox.Text); int ret = HNC_Connect.start_connect(ipr, ipl, port); if (ret == 0) { connect_button.Text = "已连接"; connect_button.Enabled = false; } else if (ret == 1) { MessageBox.Show("请检查适配器", "初始化失败", MessageBoxButtons.OK); } else if (ret == 2) { MessageBox.Show("请检查ip", "连接失败", MessageBoxButtons.OK); } }
private static void m_send() { long freq = 0; if (QueryPerformanceFrequency(ref freq) == false) { throw new Exception("不支持高精度计时."); } double count_per_millsec = freq / 1000.0; long start_time = 0; long now_time = 0; QueryPerformanceCounter(ref start_time); while (true) { if (!HNC_Connect.issmpl) { continue; } QueryPerformanceCounter(ref now_time); while (now_time - start_time < 50 * count_per_millsec) { QueryPerformanceCounter(ref now_time); } bool dataable = (HNC_Connect.i_que.Count > 60) && (HNC_Connect.v_que.Count > 1100) && (HNC_Connect.s_que.Count > 1100); if (dataable) { HNC_Connect.getdata.WaitOne(); List <byte> pack = new List <byte>(); for (int p = 0; p < 50; p++) { i_temp[p] = HNC_Connect.i_que.Dequeue(); //int i1=HNC_Connect.i_que.Dequeue(); //i_temp[p] = 2200; for (int p1 = 0; p1 < 20; p1++) { v_temp[p * 20 + p1] = HNC_Connect.v_que.Dequeue(); s_temp[p * 20 + p1] = HNC_Connect.s_que.Dequeue(); } } HNC_Connect.getdata.ReleaseMutex(); pack.AddRange(HNC_Connect.temp2[counter]); pack.AddRange(HNC_Connect.data2byte(i_temp)); pack.AddRange(HNC_Connect.data2byte(v_temp)); pack.AddRange(HNC_Connect.data2byte(s_temp)); Upload.socketsend(pack.ToArray()); //Console.WriteLine("发送数据"+counter.ToString()); if (counter < 3) { counter++; } } start_time = now_time; //Upload.socketsend(HNC_Connect.datatemp[3].ToArray()); } }
private void DataC_Load(object sender, EventArgs e) { #region Series Init S1 = new Series("V"); S1.ChartType = SeriesChartType.Line; S2 = new Series("S"); S2.ChartType = SeriesChartType.Line; S3 = new Series("I"); S3.ChartType = SeriesChartType.Line; S3.Color = Color.FromArgb(255, 255, 255, 0); S2.Color = Color.FromArgb(255, 255, 255, 0); S1.Color = Color.FromArgb(255, 255, 255, 0); for (int i = 0; i < 1000; i++) { S1.Points.AddXY(i, 0); S2.Points.AddXY(i, 0); S3.Points.AddXY(i, 0); } this.chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.FromArgb(112, 255, 255, 255); this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(112, 255, 255, 255); chart1.ChartAreas[0].BackColor = Color.FromArgb(255, 0, 144, 208); //chart1.ChartAreas[0].AxisX.Enabled = AxisEnabled.True; //chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.True; this.chart1.ChartAreas[0].AxisX.Maximum = 1000; this.chart1.ChartAreas[0].AxisX.Minimum = 0; this.chart2.ChartAreas[0].AxisX.Maximum = 1000; this.chart2.ChartAreas[0].AxisX.Minimum = 0; chart1.ChartAreas[0].AxisX.IntervalOffset = 0.10D; this.chart2.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.FromArgb(112, 255, 255, 255); this.chart2.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(112, 255, 255, 255); chart2.ChartAreas[0].BackColor = Color.FromArgb(255, 0, 144, 208); //chart2.ChartAreas[0].AxisX.Enabled = AxisEnabled.True; //chart2.ChartAreas[0].AxisY.Enabled = AxisEnabled.True; this.chart3.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.FromArgb(112, 255, 255, 255); this.chart3.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(112, 255, 255, 255); //chart3.ChartAreas[0].AxisX.Enabled = AxisEnabled.True; //chart3.ChartAreas[0].AxisY.Enabled = AxisEnabled.True; chart3.ChartAreas[0].BackColor = Color.FromArgb(255, 0, 144, 208); //chart1.ChartAreas[0].AxisY.MaximumAutoSize = 1; //chart2.ChartAreas[0].AxisY.MaximumAutoSize = 1; //chart3.ChartAreas[0].AxisY.MaximumAutoSize = 1; //this.chart1.ChartAreas[0].AxisY.Maximum = 1500 * 0.1; //this.chart1.ChartAreas[0].AxisY.Minimum = -500 * 0.1; //this.chart2.ChartAreas[0].AxisY.Maximum = 1500 * 0.1; //this.chart2.ChartAreas[0].AxisY.Minimum = -500 * 0.1; this.chart3.ChartAreas[0].AxisY.Maximum = 50 * 0.1; this.chart3.ChartAreas[0].AxisY.Minimum = -50 * 0.1; this.chart1.ChartAreas[0].AxisY.Maximum = 50 * 0.1; this.chart1.ChartAreas[0].AxisY.Minimum = -50 * 0.1; this.chart2.ChartAreas[0].AxisY.Maximum = 50 * 0.1; this.chart2.ChartAreas[0].AxisY.Minimum = -50 * 0.1; //this.chart3.ChartAreas[0].AxisY.Maximum = 10000.0 * 0.1; //this.chart3.ChartAreas[0].AxisY.Minimum = -10000.0 * 0.1; //chart1.ChartAreas[0].AxisX.Enabled = AxisEnabled.True; //chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.True; //chart2.ChartAreas[0].AxisX.Enabled = AxisEnabled.True; //chart2.ChartAreas[0].AxisY.Enabled = AxisEnabled.True; //chart3.ChartAreas[0].AxisX.Enabled = AxisEnabled.True; //chart3.ChartAreas[0].AxisY.Enabled = AxisEnabled.True; chart1.ChartAreas[0].AxisX.Enabled = AxisEnabled.False; chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.False; chart2.ChartAreas[0].AxisX.Enabled = AxisEnabled.False; chart2.ChartAreas[0].AxisY.Enabled = AxisEnabled.False; chart3.ChartAreas[0].AxisX.Enabled = AxisEnabled.False; chart3.ChartAreas[0].AxisY.Enabled = AxisEnabled.False; chart1.Series.Add(S1); chart2.Series.Add(S2); chart3.Series.Add(S3); #endregion #region form_timer form_timer = new System.Timers.Timer(); form_timer.Elapsed += new System.Timers.ElapsedEventHandler(tick_count); form_timer.Interval = 50; form_timer.Start(); #endregion HNC_Connect.thread_connect(); T_message_send(); }