R2000-UHD demo
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Threading;using System.IO;namespace R2000_UHD_Demo{ public partial class Form1 : Form { public static string IpAddress { get; set; } string Packet_Type = "B"; string path; bool Scanstart = false; // bool OneTurnFinish = false; FileStream fs; StreamWriter sw; public Form1() { InitializeComponent(); IpAddress = textBox2.Text; // BT_ReleaseH.Enabled = false; BT_StartScan.Enabled = false; BT_STOPScan.Enabled = false; BT_TCPConnect.Enabled = false; BT_TCPClose.Enabled = false; BT_ReleaseH.Enabled = false; Scanstart = false; comboBox2.SelectedIndex = 0; // int i; for (i = 0; i < 25200; i ) { R2000StreamTcpClient.R2000ScanPoints[i] = new R2000ScanPoint(0, 0, 0); R2000StreamTcpClient.R2000SingleTurnPoints[i] = new R2000ScanPoint(0, 0, 0); } } public string R2000IP() { return IpAddress; } private void button1_Click(object sender, EventArgs e) // Get Protocol Info { if (IpAddress != "") { //Get R2000 Feedback Data Thread R2000Thread = new Thread(new ThreadStart(R2000StreamTcpClient.R2000RecDataStream)); R2000Thread.IsBackground = true; R2000Thread.Start(); TBox_Status.Text = R2000Commands.Get_Protocol_Info(IpAddress) (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; } else { TBox_Error.Text = "Please Enter IP" (Char)13 (Char)10; } if (R2000Commands.Int16_Sucess == 1) { ChBox_TimerS.Checked = true; //------------------------------- BT_TCPConnect.Enabled = false; BT_RequestH.Enabled = true; BT_ReleaseH.Enabled = false; BT_StartScan.Enabled = false; BT_TCPConnect.Enabled = false; TBox_Error.Text = "Connection Testing Sucessful" (Char)13 (Char)10; Bt_Reboot.Enabled = true; } else { TBox_Error.Text = "Wrong IP or Wrong Network Setting, Check again" (Char)13 (Char)10; } } private void button2_Click(object sender, EventArgs e) // Request Handle TCP { // Button Request Handle if (IpAddress != "") { TBox_Status.Text = R2000Commands.Request_Handle_TCP(IpAddress, Packet_Type, "watchdogtimeout=30000", "0") (Char)13 (Char)10 "\n\rError: " R2000Commands.Int16_ErrorCode " \n\rSuccess: " R2000Commands.Int16_Sucess; if (R2000Commands.Int16_Sucess == 1) { label1.Text = R2000Commands.Port; Lbl_HandleValue.Text = R2000Commands.Handle; BT_ReleaseH.Enabled = true; BT_StartScan.Enabled = false; BT_TCPConnect.Enabled = true; BT_RequestH.Enabled = false; TBox_Error.Text = "Handle Request Successful" (Char)13 (Char)10 label1.Text (Char)13 (Char)10 Lbl_HandleValue.Text; } } else { BT_ReleaseH.Enabled = false; BT_StartScan.Enabled = false; BT_TCPConnect.Enabled = false; BT_RequestH.Enabled = true; TBox_Error.Text = "IP Address = NULL"; } } private void button3_Click(object sender, EventArgs e) // Release Handle { TBox_Status.Text = R2000Commands.Release_Handle(IpAddress) (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; Scanstart = false; if (R2000Commands.Int16_Sucess == 1) { label1.Text = "Port = "; R2000Commands.Port = ""; Lbl_HandleValue.Text = "Handle = "; R2000Commands.Handle = ""; TBox_Error.Text = "Handle is Released" (Char)13 (Char)10; BT_TCPConnect.Enabled = false; BT_RequestH.Enabled = true; BT_StartScan.Enabled = false; } else { TBox_Error.Text = "Handle Release is not Suceessful"; BT_RequestH.Enabled = true; BT_TCPConnect.Enabled = false; BT_StartScan.Enabled = false; } } private void button4_Click(object sender, EventArgs e) // Start Scan Output { //Scan Start TBox_Status.Text = R2000Commands.Start_Scanoutput(IpAddress) (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; Scanstart = true; BT_STOPScan.Enabled = true; BT_StartScan.Enabled = false; BT_RequestH.Enabled = false; BT_ReleaseH.Enabled = true; //DateTime StartTime = DateTime.Now(); int i; for (i = 0; i < 25200; i ) { R2000StreamTcpClient.R2000ScanPoints[i].Distance = 0; R2000StreamTcpClient.R2000ScanPoints[i].EchoValue = 0; } TBox_Error.Text = "Scan is Starting at: " (Char)13 (Char)10 DateTime.Now.ToString(); print_R2000Header(); } private void button5_Click(object sender, EventArgs e) // Stop Scan Output { TBox_Status.Text = R2000Commands.Stop_Scanoutput(IpAddress) (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; Scanstart = false; BT_ReleaseH.Enabled = true; BT_StartScan.Enabled = true; BT_STOPScan.Enabled = false; BT_TCPConnect.Enabled = true; TBox_Error.Text = "Scan stopped"; } private void textBox2_TextChanged(object sender, EventArgs e) { IpAddress = textBox2.Text; } private void button6_Click(object sender, EventArgs e) // TCP Connect { // TCP Connect if (R2000Commands.Port != "") { R2000StreamTcpClient.R2000UHDTCPconnect(IpAddress, R2000Commands.Port); BT_TCPClose.Enabled = true; BT_TCPConnect.Enabled = false; BT_StartScan.Enabled = true; TBox_Error.Text = "TCP is Connected to R2000" (Char)13 (Char)10 " " label1.Text; } else { BT_ReleaseH.Enabled = true; BT_TCPConnect.Enabled = true; BT_StartScan.Enabled = false; TBox_Error.Text = "ERROR: PORT = NULL"; } } private void button7_Click(object sender, EventArgs e) // TCP Close { R2000StreamTcpClient.SocketCloseCommand = true; //R2000StreamTcpClient.R2000UHDTCPclose(); //Scanstart = false; BT_TCPConnect.Enabled = true; BT_TCPClose.Enabled = false; BT_ReleaseH.Enabled = true; TBox_Error.Text = "TCP Connection is closed" (Char)13 (Char)10; //关闭流 //sw.Close(); ///fs.Close(); } private void timer_Watchdog_Tick(object sender, EventArgs e) { //TBox_Status.Text = R2000Commands.Feed_Watchdog(IpAddress); //TBox_Test.Text = R2000Commands.Feed_Watchdog(IpAddress); TBox_Test.Text = R2000Commands.Feed_Watchdog(IpAddress); } // Head Info Display at Text Box public void print_R2000Header() { string txt = "packet_type = "; switch (R2000StreamTcpClient.packet_type) { case 65: txt = txt "A" (Char)13 (Char)10; break; case 66: txt = txt "B" (Char)13 (Char)10; break; case 67: txt = txt "C" (Char)13 (Char)10; break; default: txt = txt (Char)13 (Char)10; break; } txt = txt "packet_size = " R2000StreamTcpClient.packet_size.ToString("D") (Char)13 (Char)10; txt = txt "header_size = " R2000StreamTcpClient.header_size.ToString("D") (Char)13 (Char)10; txt = txt "scan_number = " R2000StreamTcpClient.scan_number.ToString("D") (Char)13 (Char)10; txt = txt "packet_number = " R2000StreamTcpClient.packet_number.ToString("D") (Char)13 (Char)10; txt = txt "timestamp_raw = " R2000StreamTcpClient.timestamp_raw.ToString("D") (Char)13 (Char)10; txt = txt "timestamp_sync = " R2000StreamTcpClient.timestamp_sync.ToString("D") (Char)13 (Char)10; txt = txt "scan_frequency = " R2000StreamTcpClient.scan_frequency.ToString("D") (Char)13 (Char)10; txt = txt "num_points_scan = " R2000StreamTcpClient.num_points_scan.ToString("D") (Char)13 (Char)10; txt = txt "num_points_packet = " R2000StreamTcpClient.num_points_packet.ToString("D") (Char)13 (Char)10; txt = txt "first_index = " R2000StreamTcpClient.first_index.ToString("D") (Char)13 (Char)10; txt = txt "first_angle = " R2000StreamTcpClient.first_angle.ToString("D") (Char)13 (Char)10; txt = txt "angular_increment = " R2000StreamTcpClient.angular_increment.ToString("D") (Char)13 (Char)10; txt = txt (char)13 (Char)10 "TCP Connected = " R2000StreamTcpClient.IsConnectedTCP (Char)13 (Char)10; txt = txt "TCP Connection: " R2000StreamTcpClient.ErrorMsg_TCP_Connections (Char)13 (Char)10; this.TBox_Header.Text = txt; } public void print_R2000ScanData() { string txt = ""; string str = ""; // new int i; int InvData = -1; //new int startvalue; if (textBox3.Text == "") //startvalue = R2000StreamTcpClient.num_points_scan; startvalue = 0; else startvalue = Convert.ToInt32(textBox3.Text); if (startvalue > 25164) startvalue = 25164; txt = "Scan data point " startvalue "-" (startvalue 35) ":" (Char)13 (Char)10; txt = txt "Startpoint: Distance mm: Echo: Angle:" (Char)13 (Char)10; //for (i = startvalue; i < (startvalue 36); i ) //for (i = 0; i < startvalue; i ) for (i = startvalue; i < (startvalue 36); i ) { txt = txt i.ToString("00000") " "; str = str i.ToString("00000") " "; if (R2000StreamTcpClient.R2000ScanPoints[i].Distance == 0xFFFFFFFF) { txt = txt "-00001"; str = str InvData.ToString("00000"); } else { txt = txt R2000StreamTcpClient.R2000ScanPoints[i].Distance.ToString("000000"); str = str R2000StreamTcpClient.R2000ScanPoints[i].Distance.ToString("000000"); } txt = txt " | " R2000StreamTcpClient.R2000ScanPoints[i].EchoValue.ToString("00000") " | " R2000StreamTcpClient.R2000ScanPoints[i].Angle.ToString("000.00000") (Char)13 (Char)10; str = str " " R2000StreamTcpClient.R2000ScanPoints[i].Angle.ToString("000.00000") " " R2000StreamTcpClient.R2000ScanPoints[i].EchoValue.ToString("00000") (Char)13 (Char)10; } this.textBox_ScanPoints.Text = txt; this.Txb_NPS.Text = Convert.ToString(startvalue); //........................................................................... // if (R2000StreamTcpClient.IsConnectedTCP && button4.Enabled == false) //{ // Write(str); //} } public void write_close() { sw.Close(); fs.Close(); } public void Write(string txt) { //开始写入 sw.Write(txt); //清空缓冲区 sw.Flush(); //关闭流 //sw.Close(); //fs.Close(); } private void timer1_Tick(object sender, EventArgs e) { //print_R2000Header(); //HeadInfoPrinting(); if (Chbox_AutoUpdate.Checked == true) { print_R2000ScanData(); HeadInfoPrinting(); } else { HeadInfoPrinting(); } } private void checkBox_Type_A_CheckedChanged_1(object sender, EventArgs e) { if (checkBox_Type_A.Checked == true) { Packet_Type = "A"; checkBox_Type_B.Checked = false; checkBox_Type_C.Checked = false; checkBox_Type_A.Enabled = false; checkBox_Type_B.Enabled = true; checkBox_Type_C.Enabled = true; } } private void checkBox_Type_B_CheckedChanged(object sender, EventArgs e) { if (checkBox_Type_B.Checked == true) { Packet_Type = "B"; checkBox_Type_A.Checked = false; checkBox_Type_C.Checked = false; checkBox_Type_A.Enabled = true; checkBox_Type_B.Enabled = false; checkBox_Type_C.Enabled = true; } } private void checkBox_Type_C_CheckedChanged_1(object sender, EventArgs e) { if (checkBox_Type_C.Checked == true) { Packet_Type = "C"; checkBox_Type_A.Checked = false; checkBox_Type_B.Checked = false; checkBox_Type_A.Enabled = true; checkBox_Type_B.Enabled = true; checkBox_Type_C.Enabled = false; } } private void exitToolStripMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show("Exit Program? 退出程序?", "R2000_UHD_Demo", MessageBoxButtons.YesNo) == DialogResult.Yes) { this.Close(); } } // Check for NUM only private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar)) e.Handled = true; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) // Select Scan Rate { switch (CmBox_SamplePS.SelectedIndex) { case 0: TBox_Status.Text = R2000Commands.Set_Parameter(IpAddress, "scan_frequency=50&samples_per_scan=360") (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; break; case 1: TBox_Status.Text = R2000Commands.Set_Parameter(IpAddress, "scan_frequency=50&samples_per_scan=720") (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; break; case 2: TBox_Status.Text = R2000Commands.Set_Parameter(IpAddress, "scan_frequency=50&samples_per_scan=1440") (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; break; case 3: TBox_Status.Text = R2000Commands.Set_Parameter(IpAddress, "scan_frequency=10&samples_per_scan=3600") (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; break; case 4: TBox_Status.Text = R2000Commands.Set_Parameter(IpAddress, "scan_frequency=50&samples_per_scan=3600") (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; break; case 5: TBox_Status.Text = R2000Commands.Set_Parameter(IpAddress, "scan_frequency=50&samples_per_scan=5040") (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; break; case 6: TBox_Status.Text = R2000Commands.Set_Parameter(IpAddress, "scan_frequency=35&samples_per_scan=7200") (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; break; case 7: TBox_Status.Text = R2000Commands.Set_Parameter(IpAddress, "scan_frequency=20&samples_per_scan=12600") (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; break; case 8: TBox_Status.Text = R2000Commands.Set_Parameter(IpAddress, "scan_frequency=10&samples_per_scan=25200") (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; break; default: break; } } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBox2.SelectedIndex) { case 0: this.Timer_Print.Interval = 500; break; case 1: this.Timer_Print.Interval = 50; break; case 2: this.Timer_Print.Interval = 100; break; case 3: this.Timer_Print.Interval = 200; break; case 4: this.Timer_Print.Interval = 500; break; default: break; } } private void showRefelctorToolStripMenuItem_Click(object sender, EventArgs e) { frmReflector frm = new frmReflector(); frm.Show(); } private void HeadInfoPrinting() { double Angleres = 0; double firstangle = 0.0; double firstangleabsolute = 0.0; Angleres = Convert.ToDouble(R2000StreamTcpClient.angular_increment); firstangle = Convert.ToDouble(R2000StreamTcpClient.first_angle) / 10000; if (R2000StreamTcpClient.num_points_scan != 0) firstangleabsolute = (R2000StreamTcpClient.first_index * 360) / R2000StreamTcpClient.num_points_scan; this.Txb_NPS.Text = R2000StreamTcpClient.num_points_scan.ToString("00") " 点"; this.TxB_TimeS.Text = R2000StreamTcpClient.timestamp_raw.ToString("D"); this.TxB_NPPackage.Text = R2000StreamTcpClient.num_points_packet.ToString("D"); this.TxB_ScanNr.Text = R2000StreamTcpClient.scan_number.ToString("00000"); this.TxB_PackNr.Text = R2000StreamTcpClient.packet_number.ToString("D"); this.TxB_ScanFreq.Text = (R2000StreamTcpClient.scan_frequency / 1000).ToString("D") " Hz"; this.TxB_AngleRes.Text = (Angleres / 10000).ToString("0.00000") " °"; this.TxB_FirstIndex.Text = R2000StreamTcpClient.first_index.ToString("0000"); this.TxB_FirstAngle.Text = firstangle.ToString("0.0") " °"; this.TxB_StatusFlag.Text = R2000StreamTcpClient.field_status.ToString("D"); this.TxB_AngleAbsolute.Text = firstangleabsolute.ToString("0.0") " °"; //labels display this.Lbl_PackType.Text = R2000StreamTcpClient.packet_type.ToString("00"); this.Lbl_HeaderSize.Text = R2000StreamTcpClient.header_size.ToString("00"); this.Lbl_PackageSize.Text = R2000StreamTcpClient.packet_size.ToString("0000"); } private void BT_Close_Click_1(object sender, EventArgs e) { /* // Close TCP R2000StreamTcpClient.SocketCloseCommand = true; // release handle TBox_Status.Text = R2000Commands.Release_Handle(IpAddress) (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; if (R2000Commands.Int16_Sucess == 1) { label1.Text = "Port = "; R2000Commands.Port = ""; Lbl_HandleValue.Text = "Handle = "; R2000Commands.Handle = ""; } */ BT_RequestH.Enabled = true; BT_ReleaseH.Enabled = false; BT_StartScan.Enabled = false; BT_TCPConnect.Enabled = false; Form1.ActiveForm.Close(); } private void Form1_Load(object sender, EventArgs e) { BT_RequestH.Enabled = true; BT_ReleaseH.Enabled = false; BT_StartScan.Enabled = false; BT_TCPConnect.Enabled = false; BT_STOPScan.Enabled = false; BT_TCPClose.Enabled = false; timer_Watchdog.Enabled = false; Timer_Print.Enabled = false; Bt_Reboot.Enabled = false; } private void BT_PrintScan_Click(object sender, EventArgs e) { print_R2000ScanData(); HeadInfoPrinting(); } private void BT_PrintAll_Click(object sender, EventArgs e) { if (Scanstart == false) { TBox_Error.Text = "Please Start Scan First " DateTime.Now.ToString() (Char)13 (Char)10; return; } string txt = ""; int i; int startvalue = 0; //------------------------------- //初始化写文件 path = Application.StartupPath "\\" TBox_FileName.Text ".txt"; //fs = new FileStream(path, FileMode.Create); fs = new FileStream(path, FileMode.Append); sw = new StreamWriter(fs); //-------------------------------- txt = txt "Print Start at: " DateTime.Now.ToString() (Char)13 (Char)10; txt = "Scan data point " startvalue "-" (startvalue 35) ":" (Char)13 (Char)10; txt = txt "Startpoint: Distance mm: Echo: Angle:" (Char)13 (Char)10; TBox_Error.Text = "Preperation at: " DateTime.Now.ToString() (Char)13 (Char)10; Write(txt); for (i = 0; i < 25200; i ) { //txt = txt i.ToString("00000") " "; txt = i.ToString("00000") " "; if (R2000StreamTcpClient.R2000ScanPoints[i].Distance == 0xFFFFFFFF) { txt = txt "-000001"; //txt = "-1"; } else { //txt = txt R2000StreamTcpClient.R2000ScanPoints[i].Distance.ToString("000000"); txt = txt R2000StreamTcpClient.R2000ScanPoints[i].Distance.ToString("000000"); } //Write(txt); txt = txt " " R2000StreamTcpClient.R2000ScanPoints[i].EchoValue.ToString("00000") " " R2000StreamTcpClient.R2000ScanPoints[i].Angle.ToString("000.00000") (Char)13 (Char)10; Write(txt); } //txt = txt "Print Stop at : " DateTime.Now.ToString() (Char)13 (Char)10; txt = "Print Stop at : " DateTime.Now.ToString() (Char)13 (Char)10; TBox_Error.Text = TBox_Error.Text "Ready to Write to File at " DateTime.Now.ToString() (Char)13 (Char)10; Write(txt); TBox_Error.Text = TBox_Error.Text "Write to File Finish at " DateTime.Now.ToString() (Char)13 (Char)10; write_close(); } private void BT_GetParam_Click(object sender, EventArgs e) { if (IpAddress != "") TBox_Status.Text = R2000Commands.Get_Parameter_Info(IpAddress) (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; } private void scanSettingToolStripMenuItem_Click(object sender, EventArgs e) { frmSettingOverview frm = new frmSettingOverview(); frm.Show(); } private void BT_SendSetting_Click(object sender, EventArgs e) { // using set_scanoutput_config command String parameter = ""; if (IpAddress == null) { TBox_Error.Text = " No IP Address is valid"; return; } if (Lbl_HandleValue.Text == "Handle") { TBox_Error.Text = " No Handle Exist"; return; } parameter = "handle=" Lbl_HandleValue.Text "&packet_type=" Packet_Type; TBox_Status.Text = R2000Commands.set_scanoutput_config(IpAddress, parameter) (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; TBox_Error.Text = "Packet Type Change Sucessfully "; } private void BT_GetScanConfig_Click(object sender, EventArgs e) { String parameter = ""; if (IpAddress == null) { TBox_Error.Text = " No IP Address is valid"; return; } if (Lbl_HandleValue.Text == "Handle") { TBox_Error.Text = " No Handle Exist"; return; } parameter = "handle=" Lbl_HandleValue.Text; TBox_Status.Text = R2000Commands.get_scanoutput_config(IpAddress, parameter) (Char)13 (Char)10 "\nError: " R2000Commands.Int16_ErrorCode " \nSuccess: " R2000Commands.Int16_Sucess; TBox_Error.Text = "Get Scan Output Configuration Sucessfully"; } private void hMIWindowsToolStripMenuItem_Click(object sender, EventArgs e) { frmHMIDisplay frm = new frmHMIDisplay(); frm.Show(); } private void restartToolStripMenuItem_Click(object sender, EventArgs e) { TBox_Status.Text = R2000Commands.reboot_device(IpAddress); TBox_Error.Text = "R2000 Rebooting " (Char)13 (Char)10; } private void communicationProtocolToolStripMenuItem_Click(object sender, EventArgs e) { frmManualView frm = new frmManualView(); frm.Show(); } private void ChBox_TimerS_CheckedChanged(object sender, EventArgs e) { if (ChBox_TimerS.Checked == true) { timer_Watchdog.Enabled = true; Timer_Print.Enabled = true; } else { timer_Watchdog.Enabled = false; Timer_Print.Enabled = false; } } private void Bt_Reboot_Click(object sender, EventArgs e) { TBox_Status.Text = R2000Commands.reboot_device(IpAddress); if (R2000Commands.Int16_Sucess == 1) TBox_Error.Text = "R2000 Rebooting " (Char)13 (Char)10 "it will take 10 sec"; } private void Chbox_AutoUpdate_CheckedChanged(object sender, EventArgs e) { if (Chbox_AutoUpdate.Checked == true) { Timer_Print.Enabled = true; Timer_Print.Start(); } else { Timer_Print.Enabled = false; Timer_Print.Stop(); } } private void BT_UpdateValue_Click(object sender, EventArgs e) { // Print Out Current Value // print_R2000Header(); if (Lbl_HandleValue.Text == "Handle") { TBox_Error.Text = "Please Get Handle" (Char)13 (Char)10; return; } //--------------------------------------------------------- if (Chbox_AutoUpdate.Checked == true) return; if (BT_UpdateValue.Text == "Update Start") { if (Timer_Print.Enabled == false) { Timer_Print.Enabled = true; Timer_Print.Start(); BT_UpdateValue.Text = "Update Stop"; TBox_Error.Text = "Head Information is Updated" (Char)13 (Char)10; } else { BT_UpdateValue.Text = "Update Stop"; //BT_UpdateValue.BackColor = System PeachPuff; } } else { if (Timer_Print.Enabled == true) { //Timer_Print.Enabled = true; //Timer_Print.Start(); BT_UpdateValue.Text = "Update Start"; Timer_Print.Enabled = false; Timer_Print.Stop(); TBox_Error.Text = "Head Information Update Stopped" (Char)13 (Char)10; } } HeadInfoPrinting(); } private void BT_PrintSingleTurn_Click(object sender, EventArgs e) { string txt = ""; int i; int startvalue; double SingleTurnTime = 0.0; //--------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------- if (textBox3.Text == "") startvalue = 0; else startvalue = Convert.ToInt32(textBox3.Text); if (startvalue > 25164) startvalue = 25164; txt = "Scan data point " startvalue "-" (startvalue 35) ":" (Char)13 (Char)10; txt = txt "Startpoint: Distance mm: Echo: Angle:" (Char)13 (Char)10; for (i = startvalue; i < (startvalue 36); i ) { txt = txt i.ToString("000000") " "; if (R2000StreamTcpClient.R2000SingleTurnPoints[i].Distance == 0xFFFFFFFF) { txt = txt "-1"; } else { txt = txt R2000StreamTcpClient.R2000SingleTurnPoints[i].Distance.ToString("000000"); } txt = txt " | " R2000StreamTcpClient.R2000SingleTurnPoints[i].EchoValue.ToString("00000") " | " R2000StreamTcpClient.R2000SingleTurnPoints[i].Angle.ToString("000.00000") (Char)13 (Char)10; } this.textBox_ScanPoints.Text = txt; this.Txb_NPS.Text = Convert.ToString(startvalue); this.Lbl_TotalPacket.Text = R2000StreamTcpClient.SingleTurnPacketNr.ToString("D"); //this.Lbl_TotalTime.Text = R2000StreamTcpClient.SingleTurnTimeTotal.ToString("D"); ///----------Calculation NTP Format Time, ps // SingleTurnTime = Convert.ToDouble(R2000StreamTcpClient.SingleTurnTimeTotal); SingleTurnTime = (SingleTurnTime * 1000/ 4294967296); this.Lbl_TotalTime.Text = SingleTurnTime.ToString("0.00000") "ms"; TBox_Error.Text = "Single Turn Printing Finish" (Char)13 (Char)10; } private void BT_GetSingleTurn_Click(object sender, EventArgs e) { if (Scanstart == false) { TBox_Error.Text = "Please Start Scanning" (Char)13 (Char)10; return; } R2000StreamTcpClient.SingleScanFinish = false; R2000StreamTcpClient.SingleTurnStart = false; TBox_Error.Text = "Single Turn Measurment Done" (Char)13 (Char)10; } private void BT_STurnToFile_Click(object sender, EventArgs e) { string txt = ""; int i; int startvalue = 0; if (Scanstart == false) { TBox_Error.Text = "Please Start Scan First " DateTime.Now.ToString() (Char)13 (Char)10; return; } //------------------------------- //初始化写文件 path = Application.StartupPath "\\" TBox_SingleTurnFileName.Text ".txt"; //fs = new FileStream(path, FileMode.Create); fs = new FileStream(path, FileMode.Append); sw = new StreamWriter(fs); //-------------------------------- txt = txt "Print Start at: " DateTime.Now.ToString() (Char)13 (Char)10; txt = "Scan data point " startvalue "-" (startvalue 35) ":" (Char)13 (Char)10; txt = txt "Startpoint: Distance mm: Echo: Angle:" (Char)13 (Char)10; TBox_Error.Text = "Single Turn Save at: " (Char)13 (Char)10 DateTime.Now.ToString() (Char)13 (Char)10; Write(txt); for (i = 0; i < 25200; i ) { //txt = txt i.ToString("00000") " "; txt = i.ToString("00000") " "; if (R2000StreamTcpClient.R2000SingleTurnPoints[i].Distance == 0xFFFFFFFF) { txt = txt "-000001"; //txt = "-1"; } else { //txt = txt R2000StreamTcpClient.R2000ScanPoints[i].Distance.ToString("000000"); txt = txt R2000StreamTcpClient.R2000SingleTurnPoints[i].Distance.ToString("000000"); } //Write(txt); txt = txt " " R2000StreamTcpClient.R2000SingleTurnPoints[i].EchoValue.ToString("00000") " " R2000StreamTcpClient.R2000SingleTurnPoints[i].Angle.ToString("000.00000") (Char)13 (Char)10; Write(txt); } //txt = txt "Print Stop at : " DateTime.Now.ToString() (Char)13 (Char)10; txt = "Print Stop at : " DateTime.Now.ToString() (Char)13 (Char)10; TBox_Error.Text = TBox_Error.Text "Single Turn Ready to Write to File at " (Char)13 (Char)10 DateTime.Now.ToString() (Char)13 (Char)10; Write(txt); TBox_Error.Text = TBox_Error.Text "Write to File Finish at: " (Char)13 (Char)10 DateTime.Now.ToString() (Char)13 (Char)10; write_close(); } private void BT_R2000Info_Click(object sender, EventArgs e) { frmSettingOverview frm = new frmSettingOverview(); frm.Show(); } private void BT_OpenHMIWindows_Click(object sender, EventArgs e) { frmHMIDisplay frm = new frmHMIDisplay(); frm.Show(); } }}
评论