forked from wenjy/HighWayIot
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.9 KiB
C#
122 lines
3.9 KiB
C#
using HighWayIot.Log4net;
|
|
using HighWayIot.Plc;
|
|
using HighWayIot.Winform.Business;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
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<DataTypeEnum>().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.IsConnect;
|
|
PlcShowValue.Text = res.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// PLC读取按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ReadButton_Click(object sender, EventArgs e)
|
|
{
|
|
DataTypeEnum en = (DataTypeEnum)Convert.ToInt32(PlcType.SelectedValue);
|
|
|
|
string res = string.Empty;
|
|
|
|
switch (en)
|
|
{
|
|
case DataTypeEnum.Bool:
|
|
res = PlcConnect.ReadBool(PlcAddress.Text).ToString();
|
|
break;
|
|
case DataTypeEnum.Int16:
|
|
res = PlcConnect.ReadInt16(PlcAddress.Text).ToString();
|
|
break;
|
|
case DataTypeEnum.UInt16:
|
|
res = PlcConnect.ReadUInt16(PlcAddress.Text).ToString();
|
|
break;
|
|
case DataTypeEnum.Int32:
|
|
res = PlcConnect.ReadInt32(PlcAddress.Text).ToString();
|
|
break;
|
|
case DataTypeEnum.UInt32:
|
|
res = PlcConnect.ReadUInt32(PlcAddress.Text).ToString();
|
|
break;
|
|
case DataTypeEnum.Int64:
|
|
res = PlcConnect.ReadInt64(PlcAddress.Text).ToString();
|
|
break;
|
|
case DataTypeEnum.UInt64:
|
|
res = PlcConnect.ReadUInt64(PlcAddress.Text).ToString();
|
|
break;
|
|
case DataTypeEnum.Float:
|
|
res = PlcConnect.ReadFloat(PlcAddress.Text).ToString();
|
|
break;
|
|
case DataTypeEnum.Double:
|
|
res = PlcConnect.ReadDouble(PlcAddress.Text).ToString();
|
|
break;
|
|
default:
|
|
res = "不对劲儿奥";
|
|
break;
|
|
}
|
|
|
|
PlcShowValue.Text = res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// PLC写入按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
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();
|
|
}
|
|
}
|
|
}
|