Example #1
0
        private async void ThreadPoolCheckVersion(object obj)
        {
            System.Threading.Thread.Sleep(100);

            MqttSyncClient mqtt = new MqttSyncClient(new MqttConnectionOptions( )
            {
                IpAddress      = "118.24.36.220",
                Port           = 1883,
                UseRSAProvider = true,
            });
            OperateResult <string> read = await mqtt.ReadRpcAsync <string>("SupportList/GetDeviceSupport", new { token = string.Empty, unique = this.formName });

            if (read.IsSuccess)
            {
                if (!string.IsNullOrEmpty(read.Content))
                {
                    List <DeviceSupportList> devices = JArray.Parse(read.Content).ToObject <List <DeviceSupportList> >( );
                    Invoke(new Action <List <DeviceSupportList> >(RenderDevice), devices);
                }
            }
            else
            {
                MessageBox.Show("Request Server failed: " + read.Message);
            }
        }
Example #2
0
        private async void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.textBox1.Text))
            {
                MessageBox.Show("Model can't be null!");
                return;
            }

            button1.Enabled = false;

            MqttSyncClient mqtt = new MqttSyncClient(new MqttConnectionOptions( )
            {
                IpAddress      = "118.24.36.220",
                Port           = 1883,
                UseRSAProvider = true,
            });
            OperateResult <List <DeviceSupportList> > read = await mqtt.ReadRpcAsync <List <DeviceSupportList> >("SupportList/UploadSupport",
                                                                                                                 new { token = string.Empty, unique = this.formName, model = this.textBox1.Text, qq = this.textBox2.Text, name = this.textBox3.Text });

            if (read.IsSuccess)
            {
                MessageBox.Show("Upload data success");
                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ThreadPoolCheckVersion), null);
            }
            else
            {
                MessageBox.Show("Request Server failed: " + read.Message);
            }

            button1.Enabled = true;
        }
Example #3
0
        private async void button1_Click(object sender, EventArgs e)
        {
            // 连接
            MqttConnectionOptions options = new MqttConnectionOptions( )
            {
                IpAddress = textBox1.Text,
                Port      = int.Parse(textBox2.Text),
                ClientId  = textBox3.Text,
            };

            if (!string.IsNullOrEmpty(textBox9.Text) || !string.IsNullOrEmpty(textBox10.Text))
            {
                options.Credentials = new MqttCredential(textBox9.Text, textBox10.Text);
            }

            button1.Enabled = false;
            mqttSyncClient  = new MqttSyncClient(options);
            OperateResult connect = await mqttSyncClient.ConnectServerAsync( );

            if (connect.IsSuccess)
            {
                panel2.Enabled  = true;
                button1.Enabled = false;
                button2.Enabled = true;
                panel2.Enabled  = true;
                MessageBox.Show(StringResources.Language.ConnectServerSuccess);
            }
            else
            {
                button1.Enabled = true;
                MessageBox.Show(connect.Message);
            }
        }
Example #4
0
        public ActionResult StopPlc()
        {
            MqttSyncClient mqttSyncClient = new MqttSyncClient("127.0.0.1", 1883);

            HslCommunication.OperateResult <string, string> operate = mqttSyncClient.ReadString("StopPLC", "");
            if (operate.IsSuccess)
            {
                return(Content(operate.Content1));
            }
            else
            {
                return(Content("通讯失败!" + operate.Message));
            }
        }
Example #5
0
        private async void button7_Click_1(object sender, EventArgs e)
        {
            // 连接
            MqttConnectionOptions options = new MqttConnectionOptions( )
            {
                IpAddress      = textBox4.Text,
                Port           = int.Parse(textBox2.Text),
                ClientId       = textBox1.Text,
                UseRSAProvider = checkBox_rsa.Checked,
            };

            if (!string.IsNullOrEmpty(textBox9.Text) || !string.IsNullOrEmpty(textBox10.Text))
            {
                options.Credentials = new MqttCredential(textBox9.Text, textBox10.Text);
            }

            button7.Enabled = false;
            mqttSyncClient  = new MqttSyncClient(options);
            OperateResult connect = await mqttSyncClient.ConnectServerAsync( );

            if (connect.IsSuccess)
            {
                // 此处为什么关闭呢?因为文件的操作都是基于新的socket的,这样支持多线程操作,所以此处关闭也没事
                // Why is it closed here? Because file operations are based on the new socket, this supports multi-threaded operations, so it’s okay to close here
                mqttSyncClient.ConnectClose( );
                panel2.Enabled  = true;
                button7.Enabled = false;
                button1.Enabled = true;
                MessageBox.Show(StringResources.Language.ConnectServerSuccess);
            }
            else
            {
                button7.Enabled = true;
                MessageBox.Show(connect.Message);
            }

            // 创建本地文件存储的路径
            string path = Application.StartupPath + @"\Files";

            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
        }