MainWindow.xaml.cs 3.31 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        FLY.Thick.BulkDataModule.BulkDataClient mBulkDataClient;
        int Bookmark=-1;
        public MainWindow()
        {
            InitializeComponent();
            
        }

        void Init_BulkdataClient() 
        {
            //创建与bulkdata服务通讯的客户端
            mBulkDataClient = new FLY.Thick.BulkDataModule.BulkDataClient(false);

            //给客户端 加入 读取 横向扫描 数据请求

            FLY.Thick.BulkDataModule.BulkDataClient.BulkDataGraphFrame bulkdata_client =
                new FLY.Thick.BulkDataModule.BulkDataClient.BulkDataGraphFrame();

            // BM = -1 读取的是上一幅扫描数据
            // BM = 0 读取的是当前扫描数据
            bulkdata_client.BM = -1;

            // 混合数是1 
            bulkdata_client.Mix = 1;

            //让界面 bookmark 绑定 bulkdata_client.BookMark
            this.DataContext = bulkdata_client;

            //关注 bulkdata_client 属性的变化,就可以得到扫描数据的结果
            bulkdata_client.PropertyChanged += (sender, e) =>
            {
                FLY.Thick.BulkDataModule.BulkDataClient.BulkDataGraphFrame bc =
                    sender as FLY.Thick.BulkDataModule.BulkDataClient.BulkDataGraphFrame;

                if (e.PropertyName == "BookMark")
                {
                    //只要 bc.BookMark 更新了,且不是 -1,证明有新数据来!!!
                    if (Bookmark == -1)
                    {
                        Bookmark = bc.BookMark;
                    }
                    else if (bc.BookMark != -1)
                    {
                        //能获得到数据
                        if (Bookmark != bc.BookMark)
                        {
                            Bookmark = bc.BookMark;

                            //bc.Frame 就是数据!!!!!!!!!
                            //bc.Frame.ToArray();

                        }
                    }
                }
            };
            mBulkDataClient.Add(bulkdata_client);

        }
        void Init2() 
        {
            //远端测厚仪的地址可能是 192.168.1.39 具体要看 测厚仪的设置。
            //端口号 20006
            FObjBase.FObjSys.Current.Connect_to_Another_OBJSys(
                new System.Net.IPEndPoint(System.Net.IPAddress.Parse("192.168.1.39"), 20006),
                mBulkDataClient.ID);


            //启动Poll系统!!!
            FObjBase.PollModule.Current.Start();// 创建一个 System.Windows.Threading.DispatcherTimer,整套系统都在里面跑

        }
        bool b = false;
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            b = true;
            Init_BulkdataClient();
            Init2();
            button1.IsEnabled = false;
        }
    }

}