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.

140 lines
4.5 KiB
C#

using HighWayIot.Log4net;
using HighWayIot.Plc;
using HighWayIot.Plc.PlcHelper;
using HighWayIot.Repository.domain;
using HighWayIot.Repository.service;
using HighWayIot.Rfid;
using HighWayIot.TouchSocket;
using HighWayIot.Winform.Business;
using HighWayIot.Winform.Properties;
using HslCommunication;
using Models;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
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;
/// <summary>
/// TCP客户端
/// </summary>
private TouchSocketTcpClient _touchSocketTcpClient = TouchSocketTcpClient.Instance;
/// <summary>
/// RFID数据分析
/// </summary>
private RfidDataAnalyse _RfidDataAnalyse = new RfidDataAnalyse();
XmlUtil xmlUtil = new XmlUtil();
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 =
//PlcType.DataSource = ;
}
/// <summary>
/// RFID测试
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
var a = _touchSocketTcpClient.Send($"192.168.0.{RFIDtext.Text}", _RfidDataAnalyse.Send02H(1000));
LogHelper.Instance.Info($"192.168.0.{RFIDtext.Text} 发送" + (a ? "成功" : "失败"));
}
/// <summary>
/// 测试按钮3
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{
byte[] sideBytes = new byte[2];
sideBytes[0] = sideBytes[0].SetBoolByIndex(0, false);
sideBytes[0] = sideBytes[0].SetBoolByIndex(1, true);
sideBytes[0] = sideBytes[0].SetBoolByIndex(2, false);
sideBytes[0] = sideBytes[0].SetBoolByIndex(3, true);
sideBytes[0] = sideBytes[0].SetBoolByIndex(4, false);
sideBytes[0] = sideBytes[0].SetBoolByIndex(5, true);
sideBytes[0] = sideBytes[0].SetBoolByIndex(6, false);
sideBytes[0] = sideBytes[0].SetBoolByIndex(7, true);
sideBytes[1] = sideBytes[1].SetBoolByIndex(0, false);
sideBytes[1] = sideBytes[1].SetBoolByIndex(1, true);
ushort sideBitData = sideBytes.FromBytes();
sideBytes = BitConverter.GetBytes(sideBitData);
if (PlcConnect.PlcWriteBytes2("D409", sideBytes).IsSuccess)
{
MessageBox.Show("写入成功");
}
}
/// <summary>
/// 测试按钮1
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
OperateResult<byte[]> sideResult = PlcConnect.ReadByte2("D409", 1);
byte[] sideData;
if (sideResult.IsSuccess)
{
sideData = sideResult.Content;
List<bool> result = new List<bool>();
result.Add(sideData[0].GetBoolByIndex(0));
result.Add(sideData[0].GetBoolByIndex(1));
result.Add(sideData[0].GetBoolByIndex(2));
result.Add(sideData[0].GetBoolByIndex(3));
result.Add(sideData[0].GetBoolByIndex(4));
result.Add(sideData[0].GetBoolByIndex(5));
result.Add(sideData[0].GetBoolByIndex(6));
result.Add(sideData[0].GetBoolByIndex(7));
result.Add(sideData[1].GetBoolByIndex(0));
result.Add(sideData[1].GetBoolByIndex(1));
}
}
private void TestButton1_Click(object sender, EventArgs e)
{
}
private void TestButton2_Click(object sender, EventArgs e)
{
}
}
}