|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using BPA.Helper;
- using BPASmart.Model;
- using BPA.Communication;
- using Newtonsoft.Json;
- using System.Diagnostics;
-
- namespace ComputerTestDemo
- {
- public partial class Form1 : Form
- {
- List<CommunicationModel> communicationModels = new List<CommunicationModel>();
- public Form1()
- {
- InitializeComponent();
- bool[] cct = new bool[120];
- GetData(cct);
- textBox1.Enabled = false;
- button1.Enabled = false;
- Json<CommunicationPar>.Read();
- communicationModels = Json<CommunicationPar>.Data.CommunicationDevices.Where(p => p.DeviceName.Length > 0).ToList();
- communicationModels.ForEach(item => { comboBox1.Items.Add(item.DeviceName); });
- Task.Run(new Action(() =>
- {
- MqttInit();
- }));
- }
-
- private TResult GetData<TResult>(TResult tc)
- {
-
- if (tc is Array tt)
- {
- var len = tt.Length;
- var va = tt.GetValue(0);
- }
-
-
-
- Type type = typeof(TResult);
- var name = type.Name;
- Debug.WriteLine(name);
- return default;
- }
-
- MqttHelper mqttHelper = new MqttHelper();
- private void MqttInit()
- {
- mqttHelper.Connect("admin", "fengyoufu067101!@#", "124.222.238.75", 61613, $"ֲʽλ:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
- mqttHelper.ConnectOk = new Action(() =>
- {
- this.Invoke(new Action(() => { textBox1.Enabled = true; button1.Enabled = true; }));
- });
- }
-
- private void Publish(PublishInfo publishInfo)
- {
- mqttHelper.Publish("DistributedHostComputer/Control", JsonConvert.SerializeObject(publishInfo));
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- string DeviceName = comboBox1.Text.Trim();
- string VarName = comboBox2.Text.Trim();
- var resDevices = communicationModels.FirstOrDefault(p => p.DeviceName == DeviceName);
- if (resDevices != null)
- {
- var resVars = resDevices.VarTableModels.FirstOrDefault(p => p.VarName == VarName);
- if (resVars != null)
- {
- PublishInfo publishInfo = new PublishInfo();
- publishInfo.PublishModels.Add(new PublishModel()
- {
- DataType = (EDataType)Enum.Parse(typeof(EDataType), resVars.DataType),
- DeviceName = DeviceName,
- RealAddress = resVars.RealAddress,
- Value = textBox1.Text.Trim(),
- });
- Publish(publishInfo);
- }
- }
- }
-
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- string selectName = comboBox1.Text.Trim();
- var res = communicationModels.FirstOrDefault(p => p.DeviceName == selectName);
- if (res != null)
- {
- comboBox2.Items.Clear();
- res.VarTableModels.ToList()?.ForEach(item => { comboBox2.Items.Add(item.VarName); });
- }
- }
- }
- }
|