123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using HandyControl.Controls;
- using HslCommunication;
- using HslCommunication.Profinet.Inovance;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace LogoForceTestApp.Modules.MainModule
- {
- public class InovanceTcp//汇川H5U
- {
- public InovanceTcpNet tcpNet;
-
- public bool Connection(string ip, int port)
- {
- tcpNet = new InovanceTcpNet(ip, port, 1);//ip,端口,站号
- //tcpNet.Station = 1;
- //tcpNet.AddressStartWithZero = true;
- //tcpNet.IsStringReverse = false;
- tcpNet.Series = HslCommunication.Profinet.Inovance.InovanceSeries.H5U;
- //tcpNet.DataFormat = HslCommunication.Core.DataFormat.CDAB;
- //tcpNet.Series = InovanceSeries.H5U;
- OperateResult connect = tcpNet.ConnectServer();
- if (connect.IsSuccess)
- {
- //连接成功
- return true;
- }
- else
- {
- return false;
- }
- }
- public void ConnectionClose()
- {
- tcpNet.ConnectClose();
- }
- public void WriteDate<T>(string address, T t)
- {
- dynamic temp = t;
- OperateResult result = tcpNet.Write(address, temp);//WriteDate("D200",10);WriteDate("W5.0",true);
- Thread.Sleep(500);
- }
- public bool[] Read(string add,ushort lenght=1)
- {
- bool[] obj = tcpNet.ReadBool(add, lenght).Content;
- return obj;
- }
- public bool ReadBool(string add)
- {
- var obj = tcpNet.ReadBool(add).Content;
- return obj;
- }
- public int ReadInt(string add)//short
- {
- var obj = tcpNet.ReadInt16(add).Content;
- return obj;
- }
- //public int ReadInt(string add)
- //{
- // var obj = tcpNet.ReadInt32(add).Content;
- // return obj;
- //}
- public void WriteInt(string add,int val)
- {
- tcpNet.Write(add, val);
- }
- public void WriteBool(string add, bool val)
- {
- tcpNet.Write(add, val);
- }
- }
- }
|