using HighWayIot.Log4net; using HighWayIot.Plc; using HighWayIot.Winform.Business; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace HighWayIot.Winform.UserControlPages { public partial class TestPage : UserControl { private static LogHelper logger = LogHelper.Instance; public TestPage() { InitializeComponent(); Init(); } private void Init() { ArrayList list = new ArrayList(); foreach (var kv in GeneralUtils.GetEnumKeyValuePairs().ToDictionary(i => i.Key, i => i.Value)) { list.Add(kv); } PlcType.DataSource = list; PlcType.DisplayMember = "Key"; PlcType.ValueMember = "Value"; //PlcType.DataSource = //PlcType.DataSource = ; } XmlUtil xmlUtil = new XmlUtil(); private void button1_Click(object sender, EventArgs e) { var list = xmlUtil.ConfigReader(); foreach (var item in list) { Console.WriteLine(item.RoleIndex + item.PageName); } } private void button2_Click(object sender, EventArgs e) { var res = PlcConnect.Test(); PlcShowValue.Text = res.ToString(); } /// /// PLC读取按钮 /// /// /// private void ReadButton_Click(object sender, EventArgs e) { DataTypeEnum type = (DataTypeEnum)Convert.ToInt32(PlcType.SelectedValue); Type t = GeneralUtils.GetTypeByEnum(type); var result = PlcConnect.PlcRead(PlcAddress.Text, type); PlcShowValue.Text = Convert.ToDecimal(result).ToString(); } /// /// PLC写入按钮 /// /// /// private void WriteButton_Click(object sender, EventArgs e) { if(!decimal.TryParse(PlcValue.Text, out decimal value)) { MessageBox.Show("类型转换错误!"); } var result = PlcConnect.PlcWrite(PlcAddress.Text, value, (DataTypeEnum)Convert.ToInt32(PlcType.SelectedValue)); bool r = result.IsSuccess; PlcShowValue.Text = r.ToString(); } } }