Halcon_Gocator_VisualStudio

代码中启动另一个exe程序:

1
2
3
4
5
6
ProcessStartInfo info = new ProcessStartInfo();
            info.FileName = @"D:\Kita\SOFT_WARE\qq\Bin\QQ.exe";
            info.Arguments = "";
            info.WindowStyle = ProcessWindowStyle.Minimized;
            Process pro = Process.Start(info);
            //pro.WaitForExit();

  Gocator Sdk获取数据:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
dataSet = system.ReceiveData(30000000);
           for (int i = 0; i < dataSet.Count; i++)
           {
               GoDataMsg dataFrame = (GoDataMsg)dataSet.Get(i);
               if (dataFrame.MessageType==GoDataMessageType.UniformSurface)
               {
                   GoSurfaceMsg dataSurface = (GoSurfaceMsg)dataFrame;
                   long width = dataSurface.Width;
                   long length = dataSurface.Length;
                   long bufferSize = width * length;
 
                   IntPtr bufferPointer = dataSurface.Data;
 
                   //Console.WriteLine("Whole Part Height Map received:");
                   //Console.WriteLine(" Buffer width: {0}", width);
                   //Console.WriteLine(" Buffer length: {0}", length);
 
                    
                   short[] ranges = new short[bufferSize];
                   Marshal.Copy(bufferPointer, ranges, 0, ranges.Length);
                   RecSurfData.Add(ranges);

  其中用到Marshal类的copy函数,需要using System.Runtime.InteropServices;

 

打开选择文件窗口,并返回选中文件绝对路径

1
2
3
4
5
6
using Microsoft.Win32;
 
  OpenFileDialog dialog = new OpenFileDialog();
  dialog.ShowDiag(); //返回一个可空的布尔值
     
    Console.Write(dialog.Filename);  //路径保存在这里

  

切换空间字体颜色;

1
StateConnect.Foreground = Brushes.Green;

  

 TextBox作为InfoLog使用

1
2
3
4
5
6
7
8
9
10
VerticalScrollBarVisibility="Auto" Foreground="Green"
 
 
 public void StateBox(string txt)
        {
            string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff");
            string str = time + "->"+"\r\n"+txt+"\r\n";
            WindowStateLog.AppendText(str);
            WindowStateLog.ScrollToEnd();
        }

  

打开文件选择对话框,选择文件获取路径

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using Microsoft.Win32;
 
private void BtnOpenFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            //op.InitialDirectory = "D:/3D";
            op.Title = "请选择导入csv文件";
            op.Filter = "csv文件|*.csv";
            
            if (op.ShowDialog() ==true)
            {
                SingleDataPath = op.FileName;
                TextBoxPath.Text = op.FileName;
            }
            else {
                MessageBox.Show("未选中任何文件");
            }
        }
1
OpenFileDialog 也可直接返回Stream对象,直接进行读写操作;<br><br><br>
1
2
OutPutFile = new StreamWriter("D:/3D/output.csv",true);
//查看构造函数重载,采用覆盖,末尾添加等模式

  

1
textbox作为状态log输出框
1
2
3
4
5
6
7
VerticalScrollBarVisibility="Auto"
 
WPF里面 自动显示滚动条
 
            WindowStateLog.AppendText(str);
            WindowStateLog.ScrollToEnd();
末尾添加新log并把焦点聚焦在最后一排

  

1
<br><br>

 

posted @   黄晓魚  阅读(668)  评论(2编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示