private async void btnOk_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.Cursor = Cursors.Wait;
                SunRizDriver.SunRizDriverClient client = new SunRizDriver.SunRizDriverClient(Data.Address, Data.Port.Value);
                await Task.Run(() =>
                {
                    if (client.CheckDriver() == false)
                    {
                        throw new Exception("无法连接此网关");
                    }
                    var serverInfo = client.GetServerInfo();
                    this.Data.Name = serverInfo.Name;
                    this.Data.SupportEnumDevice = serverInfo.SupportEnumDevice;
                    this.Data.SupportEnumPoints = serverInfo.SupportEnumPoints;
                    this.Data.Status            = CommunicationDriver_StatusEnum.Online;
                    this.Data.id = Helper.Remote.InvokeSync <int>("UpdateGateway", this.Data);

                    //清空对象属性的变化记录
                    this.Data.ChangedProperties.Clear();
                });

                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
            }
            finally
            {
                this.Cursor = null;
            }
        }
Example #2
0
        public void GetServerInfoTest()
        {
            SunRizModbusTcpDriver.ModbusDriverServer server = new ModbusDriverServer(588);
            server.Start();

            SunRizDriver.SunRizDriverClient client = new SunRizDriver.SunRizDriverClient("127.0.0.1", 588);
            var info = client.GetServerInfo();

            server.Stop();
        }
        /// <summary>
        /// 设置数据连接相关的属性输入框
        /// </summary>
        void setPointPropertyInput()
        {
            //获取通讯网关
            _container.Cursor = Cursors.Hand;
            Helper.Remote.Invoke <CommunicationDriver>("GetDriver", (gateway, err) => {
                _container.Cursor = null;
                if (err != null)
                {
                    MessageBox.Show(MainWindow.Instance, err);
                }
                else
                {
                    gatewayClient       = new SunRizDriver.SunRizDriverClient(gateway.Address, gateway.Port.GetValueOrDefault());
                    var serverInfo      = gatewayClient.GetServerInfo();
                    string[] properties = gatewayClient.GetPointProperties();
                    bool isNew          = false;
                    if (_PointJsonDict == null)
                    {
                        _PointJsonDict = new Dictionary <string, string>();
                        isNew          = true;
                    }
                    for (int i = 0; i < properties.Length; i++)
                    {
                        var item           = properties[i];
                        string strProperty = item;
                        if (strProperty.Contains("{"))
                        {
                            strProperty = strProperty.Substring(0, strProperty.IndexOf("{"));
                        }

                        if (isNew)
                        {
                            _PointJsonDict[strProperty] = "";
                        }
                        addPropertyItem(strProperty, i == 0 && serverInfo.SupportEnumPoints);
                    }
                }
            }, Device.DriverID);
        }