Exemple #1
0
 private void SimulatorClient_Load(object sender, EventArgs e)
 {
     MqttJson    = new MqttJson();
     MqttClients = new List <IMqttClient>();
     MqttOptions = new List <MqttClientOptions>();
     this.dataGridViewPara.AutoGenerateColumns   = false;
     this.dataGridViewDevice.AutoGenerateColumns = false;
 }
Exemple #2
0
        private void btOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog dig = new OpenFileDialog();

            dig.Filter = "IO点表(*.lio)|*.lio";
            if (dig.ShowDialog(this) == DialogResult.OK)
            {
                FileStream fs = null;
                try
                {
                    MqttJson tempMqttJson = null;
                    fs = new FileStream(dig.FileName, FileMode.Open);
                    fs.Seek(0, SeekOrigin.Current);
                    IFormatter formatter = new BinaryFormatter();
                    while (fs.Position < fs.Length)
                    {
                        tempMqttJson = (MqttJson)formatter.Deserialize(fs);
                        if (tempMqttJson != null)
                        {
                            break;
                        }
                    }
                    if (tempMqttJson != null)
                    {
                        MqttJson = tempMqttJson;
                        this.dataGridViewDevice.DataSource = MqttJson.Devices;

                        this.tbClientIP.Text         = MqttJson.ServerIP;
                        this.tbPassword.Text         = MqttJson.Password;
                        this.tbPeried.Text           = MqttJson.HeartPeried;
                        this.tbPort.Text             = MqttJson.Port;
                        this.tbUser.Text             = MqttJson.User;
                        this.tbUpdateCycleTopic.Text = MqttJson.UpdateCycleTopic;
                        this.tbDataTopic.Text        = MqttJson.DataTopic;
                        this.tbDataPassiveTopic.Text = MqttJson.DataPassiveTopic;
                        this.tbCommandTopic.Text     = MqttJson.CommandTopic;
                        MessageBox.Show(this, "打开文件成功!");
                    }
                    else
                    {
                        MessageBox.Show(this, "打开文件失败");
                    }
                }
                catch (Exception emx)
                {
                    MessageBox.Show(emx.Message + " " + emx.InnerException);
                }
                finally
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
            }
        }