1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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 Tuple<bool,bool> ReadBool(string add)
- {
- var obj = tcpNet.ReadBool(add);
- return new Tuple<bool, bool>(obj.IsSuccess, obj.Content);
- }
- public int ReadInt(string add)//short
- {
- var result = tcpNet.ReadInt16(add);
- var obj = result.Content;
- if (result.IsSuccess)
- {
- return obj;
- }
- else
- {
- return -1;
- }
- }
- //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);
- }
- }
- }
|