Commit f9a936eb authored by 徐生海's avatar 徐生海

Initial commit

parent 1c26e954
Pipeline #171 failed with stages
## ide
# 忽略操作系统生成的文件
DS_Store
# 忽略日志文件
*.log
**/.vs
**/.idea
work.md
__pycache__/
*.py[cod]
$__pycache__$
/logs/
/Resource/
/dist/
/build/
# 忽略环境变量文件
env
# 忽略依赖文件夹
node_modules/
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModBusAPI
{
public class Class1
{
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YQLInterfaces
{
public class YQLModBusContext
{
public string Addr { get; set; } // 连接地址
public int Port { get; set; } // 连接端口
public int Slave { get; set; } // 从站地址
public int ReadTimes { get; set; } // 超时时长
public int SendTimes { get; set; } // 超时时长
public YQLModBusContext() {
Addr = "192.168.10.208";
Port = 502 ;
Slave = 1 ;
ReadTimes = 500 ;
SendTimes = 500 ;
}
public void setParameter(string addr, int port, int readtime = 1000, int sendtime = 1000, int slave = 1)
{
Addr = addr ;
Port = port ;
Slave = slave ;
ReadTimes = readtime ;
SendTimes = sendtime;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using Modbus.Device;
using YQLInterfaces;
using YQLUtils;
namespace ModBusAPI
{
public class YQLMController: IYQLModBusController
{
private static readonly object locker = new object();
public IYQLModBus Instance() { return new YQLModBus(); }
public IYQLModBus GetInstance(string addr, int port, int readtime = 1000, int sendtime = 1000, int slave = 1)
{
return YQLModBus.GetInstance(addr, port, readtime, sendtime, slave);
}
public bool ReadBool (IYQLModBus Manager, int address)
{
var result = Settings.DEFAULT_BOOL;
lock (locker)
{
try
{
result = Manager.ReadBool(address);
}
catch (Exception) { }
}
return result;
}
public short ReadInt16 (IYQLModBus Manager, int address)
{
var result = Settings.DEFAULT_SHORT;
lock (locker)
{
try
{
result = Manager.ReadInt16(address);
}
catch (Exception) { }
}
return result;
}
public ushort ReadUInt16 (IYQLModBus Manager, int address)
{
var result = Settings.DEFAULT_USHORT;
lock (locker)
{
try
{
result = Manager.ReadUInt16(address);
}
catch (Exception) { }
}
return result;
}
public int ReadInt32 (IYQLModBus Manager, int address)
{
var result = Settings.DEFAULT_INT;
lock (locker)
{
try
{
result = Manager.ReadInt32(address);
}
catch (Exception) { }
}
return result;
}
public uint ReadUInt32 (IYQLModBus Manager, int address)
{
var result = Settings.DEFAULT_UINT;
lock (locker)
{
try
{
result = Manager.ReadUInt32(address);
}
catch (Exception) { }
}
return result;
}
public long ReadInt64 (IYQLModBus Manager, int address)
{
var result = Settings.DEFAULT_LONG;
lock (locker)
{
try
{
result = Manager.ReadInt64(address);
}
catch (Exception) { }
}
return result;
}
public ulong ReadUInt64 (IYQLModBus Manager, int address)
{
var result = Settings.DEFAULT_ULONG;
lock (locker)
{
try
{
result = Manager.ReadUInt64(address);
}
catch (Exception) { }
}
return result;
}
public float ReadFloat (IYQLModBus Manager, int address)
{
var result = Settings.DEFAULT_FLOAT;
lock (locker)
{
try
{
result = Manager.ReadFloat(address);
}
catch (Exception) { }
}
return result;
}
public int SendBool (IYQLModBus Manager, int address, bool buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendBool(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendInt16 (IYQLModBus Manager, int address, short buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendInt16(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendUInt16 (IYQLModBus Manager, int address, ushort buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendUInt16(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendInt32 (IYQLModBus Manager, int address, int buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendInt32(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendUInt32 (IYQLModBus Manager, int address, uint buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendUInt32(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendInt64 (IYQLModBus Manager, int address, long buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendInt64(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendUInt64 (IYQLModBus Manager, int address, ulong buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendUInt64(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendFloat (IYQLModBus Manager, int address, float buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendFloat(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public bool [] ReadBools (IYQLModBus Manager, int address, int count) {
var result = Settings.DEFAULT_BOOL_ARRAY;
lock (locker)
{
try
{
result = Manager.ReadBools(address, count);
}
catch (Exception) { }
}
return result;
}
public short [] ReadInt16s (IYQLModBus Manager, int address, int count) {
var result = Settings.DEFAULT_SHORT_ARRAY;
lock (locker)
{
try
{
result = Manager.ReadInt16s(address, count);
}
catch (Exception) { }
}
return result;
}
public ushort [] ReadUInt16s (IYQLModBus Manager, int address, int count) {
var result = Settings.DEFAULT_USHORT_ARRAY;
lock (locker)
{
try
{
result = Manager.ReadUInt16s(address, count);
}
catch (Exception) { }
}
return result;
}
public int [] ReadInt32s (IYQLModBus Manager, int address, int count) {
var result = Settings.DEFAULT_INT_ARRAY;
lock (locker)
{
try
{
result = Manager.ReadInt32s(address, count);
}
catch (Exception) { }
}
return result;
}
public uint [] ReadUInt32s (IYQLModBus Manager, int address, int count) {
var result = Settings.DEFAULT_UINT_ARRAY;
lock (locker)
{
try
{
result = Manager.ReadUInt32s(address, count);
}
catch (Exception) { }
}
return result;
}
public long [] ReadInt64s (IYQLModBus Manager, int address, int count) {
var result = Settings.DEFAULT_LONG_ARRAY;
lock (locker)
{
try
{
result = Manager.ReadInt64s(address, count);
}
catch (Exception) { }
}
return result;
}
public ulong [] ReadUInt64s (IYQLModBus Manager, int address, int count) {
var result = Settings.DEFAULT_ULONG_ARRAY;
lock (locker)
{
try
{
result = Manager.ReadUInt64s(address, count);
}
catch (Exception) { }
}
return result;
}
public float [] ReadFloats (IYQLModBus Manager, int address, int count) {
var result = Settings.DEFAULT_FLOAT_ARRAY;
lock (locker)
{
try
{
result = Manager.ReadFloats(address, count);
}
catch (Exception) { }
}
return result;
}
public int SendBools (IYQLModBus Manager, int address, bool [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendBools(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendInt16s (IYQLModBus Manager, int address, short [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendInt16s(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendUInt16s (IYQLModBus Manager, int address, ushort[] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendUInt16s(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendInt32s (IYQLModBus Manager, int address, int [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendInt32s(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendUInt32s (IYQLModBus Manager, int address, uint [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendUInt32s(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendInt64s (IYQLModBus Manager, int address, long [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendInt64s(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendUInt64s (IYQLModBus Manager, int address, ulong [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendUInt64s(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
public int SendFloats (IYQLModBus Manager, int address, float [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
lock (locker)
{
try
{
isWarning = Manager.SendFloats(address, buffer);
}
catch (Exception) { }
}
return isWarning;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using Modbus.Device;
using YQLInterfaces;
using YQLUtils;
namespace ModBusAPI
{
public class YQLModBus: YQLInterface, IYQLModBus
{
public IYQLModBus Instance() {
return new YQLModBus();
}
public static IYQLModBus GetInstance(string addr, int port, int readtime = 1000, int sendtime = 1000, int slave = 1)
{
var modbus = new YQLModBus();
modbus.setParameter(addr, port, readtime, sendtime, slave);
modbus.ReOpen();
return modbus;
}
public bool hasManager { get { return Manager != null; } }
public bool hasParameter { get { return Parameter != null; } }
public bool IsValid { get { return hasManager && hasParameter; } }
public bool IsOpen { get {
try
{
return IsValid && Manager.Client != null && Manager.Client.Connected && Manager.Client.RemoteEndPoint != null;
}
catch (Exception) { }
return false;
} }
public bool IsConnected {
get {
try
{
return IsValid && Manager.Client != null && Manager.Client.Connected && Manager.Client.RemoteEndPoint != null;
}
catch (Exception) { }
return false;
}
}
public bool IsAvailable
{
get
{
try
{
return IsValid && Manager.Client != null && Manager.Client.Connected && Manager.Client.RemoteEndPoint != null;
}
catch (Exception) { }
return false;
}
}
public int Open () {
int isWarning = Settings.RECODE_FAILURE;
try
{
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int Close () {
int isWarning = Settings.RECODE_SUCCEED;
try
{
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int ReOpen ()
{
Close();
return Open();
}
public void initManager () {
initParameter();
try
{
if(!hasManager)
{
Manager = new TcpClient(Parameter.Addr, Parameter.Port);
Manager.ReceiveTimeout = Parameter.ReadTimes;
Manager.SendTimeout = Parameter.SendTimes;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); Manager = null; }
}
public void deleManager ()
{
try
{
if (hasManager)
{
Manager.Close();
Manager.Dispose();
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
Manager = null;
GC.Collect();
}
public void initParameter ()
{
if (!hasParameter)
{
try
{
Parameter = new YQLModBusContext();
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
}
}
public void deleParameter ()
{
try
{
Parameter = null;
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
GC.Collect();
}
public void setParameter(string addr, int port, int readtime = 1000, int sendtime = 1000, int slave = 1)
{
initParameter();
if (hasParameter)
Parameter.setParameter(addr, port, readtime, sendtime, slave);
}
public bool ReadBool (int address )
{
var result = Settings.DEFAULT_BOOL;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
bool[] data = master.ReadCoils((ushort)address, (ushort)1);
result = data.Length >= 1 ? Convert.ToBoolean(data[0]) : Settings.DEFAULT_BOOL;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result;
}
public short ReadInt16 (int address )
{
var result = Settings.DEFAULT_SHORT;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
ushort[] data = master.ReadHoldingRegisters((ushort)address, 1);
result = data.Length >= 1 ? Convert.ToInt16(data[0]) : Settings.DEFAULT_SHORT;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result;
}
public ushort ReadUInt16 (int address )
{
var result = Settings.DEFAULT_USHORT;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
ushort[] data = master.ReadHoldingRegisters((ushort)address, 1);
result = data.Length >= 1 ? data[0] : Settings.DEFAULT_USHORT;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result;
}
public int ReadInt32 (int address )
{
var result = Settings.DEFAULT_INT;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
ushort[] data = master.ReadHoldingRegisters((ushort)address, 2);
result = ModBusUtil.UShortToInt(data);
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result;
}
public uint ReadUInt32 (int address )
{
var result = Settings.DEFAULT_UINT;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
ushort[] data = master.ReadHoldingRegisters((ushort)address, 2);
result = ModBusUtil.UShortToUInt(data);
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result;
}
public long ReadInt64 (int address )
{
var result = Settings.DEFAULT_LONG;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
ushort[] data = master.ReadHoldingRegisters((ushort)address, 4);
result = ModBusUtil.UShortToLong(data);
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result;
}
public ulong ReadUInt64 (int address )
{
var result = Settings.DEFAULT_ULONG;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
ushort[] data = master.ReadHoldingRegisters((ushort)address, 4);
result = ModBusUtil.UShortToULong(data);
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result;
}
public float ReadFloat (int address )
{
var result = Settings.DEFAULT_FLOAT;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
ushort[] data = master.ReadHoldingRegisters((ushort)address, 2);
result = ModBusUtil.UShortToFloat(data);
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result;
}
public int SendBool (int address, bool buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
master.WriteSingleCoil((byte)Parameter.Slave, (ushort)address, buffer);
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendInt16 (int address, short buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if(!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
master.WriteSingleRegister((byte)Parameter.Slave, (ushort)address, Convert.ToUInt16(buffer));
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendUInt16 (int address, ushort buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
master.WriteSingleRegister((byte)Parameter.Slave, (ushort)address, buffer);
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendInt32 (int address, int buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
master.WriteMultipleRegisters((byte)Parameter.Slave,(ushort)address, ModBusUtil.IntToUShortArray(buffer));
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendUInt32 (int address, uint buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
master.WriteMultipleRegisters((byte)Parameter.Slave, (ushort)address, ModBusUtil.UIntToUShortArray(buffer));
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendInt64 (int address, long buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
master.WriteMultipleRegisters((byte)Parameter.Slave, (ushort)address, ModBusUtil.LongToUShortArray(buffer));
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendUInt64 (int address, ulong buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
master.WriteMultipleRegisters((byte)Parameter.Slave, (ushort)address, ModBusUtil.ULongToUShortArray(buffer));
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendFloat (int address, float buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
master.WriteMultipleRegisters((byte)Parameter.Slave, (ushort)address, ModBusUtil.FloatToUShortArray(buffer));
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public bool [] ReadBools (int address, int count) {
var result = Settings.DEFAULT_BOOL_ARRAY;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
result = master.ReadCoils((ushort)address, Convert.ToUInt16(count));
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result;
}
public short [] ReadInt16s (int address, int count) {
var result = Settings.DEFAULT_SHORT_ARRAY;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
ushort[] data = master.ReadHoldingRegisters((ushort)address, Convert.ToUInt16(count));
if (data.Length > 0)
{
var array = new List<short>();
foreach (ushort d in data)
{
array.Add(Convert.ToInt16(d));
}
result = array.ToArray();
}
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result;
}
public ushort [] ReadUInt16s (int address, int count) {
var result = Settings.DEFAULT_USHORT_ARRAY;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
result = master.ReadHoldingRegisters((ushort)address, Convert.ToUInt16(count));
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result;
}
public int [] ReadInt32s (int address, int count) {
var result = new List<int>();
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
var data = master.ReadHoldingRegisters((ushort)address, Convert.ToUInt16(count * 2));
for (int i = 0; i < data.Length; i += 2)
{
ushort[] slice = new ushort[2];
Array.Copy(data, i, slice, 0, 2);
result.Add(ModBusUtil.UShortToInt(slice));
}
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result.ToArray();
}
public uint [] ReadUInt32s (int address, int count)
{
var result = new List<uint>();
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
var data = master.ReadHoldingRegisters((ushort)address, Convert.ToUInt16(count * 2));
for (int i = 0; i < data.Length; i += 2)
{
ushort[] slice = new ushort[2];
Array.Copy(data, i, slice, 0, 2);
result.Add(ModBusUtil.UShortToUInt(slice));
}
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result.ToArray();
}
public long [] ReadInt64s (int address, int count) {
var result = new List<long>();
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
var data = master.ReadHoldingRegisters((ushort)address, Convert.ToUInt16(count * 4));
for (int i = 0; i < data.Length; i += 4)
{
ushort[] slice = new ushort[4];
Array.Copy(data, i, slice, 0, 4);
result.Add(ModBusUtil.UShortToLong(slice));
}
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result.ToArray();
}
public ulong [] ReadUInt64s (int address, int count) {
var result = new List<ulong>();
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
var data = master.ReadHoldingRegisters((ushort)address, Convert.ToUInt16(count * 4));
for (int i = 0; i < data.Length; i += 4)
{
ushort[] slice = new ushort[4];
Array.Copy(data, i, slice, 0, 4);
result.Add(ModBusUtil.UShortToULong(slice));
}
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return result.ToArray();
}
public float [] ReadFloats (int address, int count) {
var result = new List<float>();
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
var data = master.ReadHoldingRegisters((ushort)address, Convert.ToUInt16(count));
for (int i = 0; i < data.Length; i += 2)
{
ushort[] slice = new ushort[2];
Array.Copy(data, i, slice, 0, 2);
result.Add(ModBusUtil.UShortToFloat(slice));
}
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
float[] buffer = result.ToArray();
return buffer;
}
public int SendBools (int address, bool [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
master.WriteMultipleCoils((byte)Parameter.Slave, (ushort)address, buffer.ToArray());
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendInt16s (int address, short [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
var data = new List<ushort>();
foreach (short d in buffer)
data.Add(Convert.ToUInt16(d));
master.WriteMultipleRegisters((byte)Parameter.Slave, (ushort)address, data.ToArray());
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendUInt16s (int address, ushort[] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
master.WriteMultipleRegisters((byte)Parameter.Slave, (ushort)address, buffer.ToArray());
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendInt32s (int address, int [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
var data = new List<ushort>();
foreach (int d in buffer)
data.AddRange(ModBusUtil.IntToUShortArray(d));
master.WriteMultipleRegisters((byte)Parameter.Slave, (ushort)address, data.ToArray());
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendUInt32s (int address, uint [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
var data = new List<ushort>();
foreach (uint d in buffer)
data.AddRange(ModBusUtil.UIntToUShortArray(d));
master.WriteMultipleRegisters((byte)Parameter.Slave, (ushort)address, data.ToArray());
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendInt64s (int address, long [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
var data = new List<ushort>();
foreach (long d in buffer)
data.AddRange(ModBusUtil.LongToUShortArray(d));
master.WriteMultipleRegisters((byte)Parameter.Slave, (ushort)address, data.ToArray());
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendUInt64s (int address, ulong [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
var data = new List<ushort>();
foreach (ulong d in buffer)
data.AddRange(ModBusUtil.ULongToUShortArray(d));
master.WriteMultipleRegisters((byte)Parameter.Slave, (ushort)address, data.ToArray());
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
public int SendFloats (int address, float [] buffer)
{
int isWarning = Settings.RECODE_FAILURE;
try
{
if (!IsAvailable)
ReOpen();
if (IsAvailable)
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(Manager);
var data = new List<ushort>();
foreach (float d in buffer)
data.AddRange(ModBusUtil.FloatToUShortArray(d));
master.WriteMultipleRegisters((byte)Parameter.Slave, (ushort)address, data.ToArray());
isWarning = Settings.RECODE_SUCCEED;
}
}
catch (Exception E) { System.Console.WriteLine($"{E.Message}"); }
return isWarning;
}
private TcpClient Manager = null;
private YQLModBusContext Parameter = null;
public YQLModBus()
{
initialization("YQLModBus");
}
~YQLModBus() {
deinitialize();
}
public void Dispose()
{
deinitialize();
}
public override void initValue()
{
initParameter ();
initManager ();
}
public override void deleValue()
{
deleManager ();
deleParameter ();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A0F785BA-92CC-431A-8ADA-93A77DA926BE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ModBusAPI</RootNamespace>
<AssemblyName>ModBusAPI</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="NModbus, Version=3.0.81.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NModbus.3.0.81\lib\net46\NModbus.dll</HintPath>
</Reference>
<Reference Include="NModbus4, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NModbus4.2.1.0\lib\net40\NModbus4.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Sockets, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Controllers\YQLMController.cs" />
<Compile Include="Controllers\YQLModBus.cs" />
<Compile Include="YQLInterfaces\IYQLModBus.cs" />
<Compile Include="YQLInterfaces\IYQLModBusController.cs" />
<Compile Include="YQLInterfaces\YQLInterface.cs" />
<Compile Include="YQLInterfaces\IYQLContext.cs" />
<Compile Include="Contexts\YQLModBusContext.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="YQLUtils\ModBusUtil.cs" />
<Compile Include="YQLUtils\Settings.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("ModBusAPI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ModBusAPI")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("a0f785ba-92cc-431a-8ada-93a77da926be")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YQLInterfaces
{
public class IYQLContext : YQLInterface
{
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YQLInterfaces
{
public interface IYQLModBus: IDisposable
{
IYQLModBus Instance();
bool hasManager { get; }
bool hasParameter { get; }
bool IsOpen { get; }
bool IsValid { get; }
bool IsAvailable { get; }
bool IsConnected { get; }
int Open ();
int Close ();
int ReOpen ();
void initManager ();
void deleManager ();
void initParameter ();
void deleParameter ();
void setParameter(string addr, int port, int readtime = 1000, int sendtime = 1000, int slave = 1);
bool ReadBool (int address );
short ReadInt16 (int address );
ushort ReadUInt16 (int address );
int ReadInt32 (int address );
uint ReadUInt32 (int address );
long ReadInt64 (int address );
ulong ReadUInt64 (int address );
float ReadFloat (int address );
int SendBool (int address, bool buffer);
int SendInt16 (int address, short buffer);
int SendUInt16 (int address, ushort buffer);
int SendInt32 (int address, int buffer);
int SendUInt32 (int address, uint buffer);
int SendInt64 (int address, long buffer);
int SendUInt64 (int address, ulong buffer);
int SendFloat (int address, float buffer);
bool [] ReadBools (int address, int count);
short [] ReadInt16s (int address, int count);
ushort [] ReadUInt16s (int address, int count);
int [] ReadInt32s (int address, int count);
uint [] ReadUInt32s (int address, int count);
long [] ReadInt64s (int address, int count);
ulong [] ReadUInt64s (int address, int count);
float [] ReadFloats (int address, int count);
int SendBools (int address, bool [] buffer);
int SendInt16s (int address, short [] buffer);
int SendUInt16s (int address, ushort[] buffer);
int SendInt32s (int address, int [] buffer);
int SendUInt32s (int address, uint [] buffer);
int SendInt64s (int address, long [] buffer);
int SendUInt64s (int address, ulong [] buffer);
int SendFloats (int address, float [] buffer);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YQLInterfaces
{
public interface IYQLModBusController
{
IYQLModBus Instance();
IYQLModBus GetInstance(string addr, int port, int readtime = 1000, int sendtime = 1000, int slave = 1);
bool ReadBool (IYQLModBus Manager, int address);
short ReadInt16 (IYQLModBus Manager, int address);
ushort ReadUInt16 (IYQLModBus Manager, int address);
int ReadInt32 (IYQLModBus Manager, int address);
uint ReadUInt32 (IYQLModBus Manager, int address);
long ReadInt64 (IYQLModBus Manager, int address);
ulong ReadUInt64 (IYQLModBus Manager, int address);
float ReadFloat (IYQLModBus Manager, int address);
int SendBool (IYQLModBus Manager, int address, bool buffer);
int SendInt16 (IYQLModBus Manager, int address, short buffer);
int SendUInt16 (IYQLModBus Manager, int address, ushort buffer);
int SendInt32 (IYQLModBus Manager, int address, int buffer);
int SendUInt32 (IYQLModBus Manager, int address, uint buffer);
int SendInt64 (IYQLModBus Manager, int address, long buffer);
int SendUInt64 (IYQLModBus Manager, int address, ulong buffer);
int SendFloat (IYQLModBus Manager, int address, float buffer);
bool [] ReadBools (IYQLModBus Manager, int address, int count);
short [] ReadInt16s (IYQLModBus Manager, int address, int count);
ushort [] ReadUInt16s (IYQLModBus Manager, int address, int count);
int [] ReadInt32s (IYQLModBus Manager, int address, int count);
uint [] ReadUInt32s (IYQLModBus Manager, int address, int count);
long [] ReadInt64s (IYQLModBus Manager, int address, int count);
ulong [] ReadUInt64s (IYQLModBus Manager, int address, int count);
float [] ReadFloats (IYQLModBus Manager, int address, int count);
int SendBools (IYQLModBus Manager, int address, bool [] buffer);
int SendInt16s (IYQLModBus Manager, int address, short [] buffer);
int SendUInt16s (IYQLModBus Manager, int address, ushort[] buffer);
int SendInt32s (IYQLModBus Manager, int address, int [] buffer);
int SendUInt32s (IYQLModBus Manager, int address, uint [] buffer);
int SendInt64s (IYQLModBus Manager, int address, long [] buffer);
int SendUInt64s (IYQLModBus Manager, int address, ulong [] buffer);
int SendFloats (IYQLModBus Manager, int address, float [] buffer);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
namespace YQLInterfaces
{
public class YQLInterface
{
public string Information { get; set; }
public static bool has_Field(object src, string name, Type TYPE)
{
try
{
if (src == null) return false;
var propertyInfo = src.GetType().GetProperty(name);
if (propertyInfo != null && propertyInfo.GetValue(src, null) != null)
return propertyInfo.GetValue(src, null).GetType() == TYPE;
}
catch (Exception) { }
return false;
}
public static T GetField<T>(object src, string name)
{
try
{
if (src == null) return default(T);
var propertyInfo = src.GetType().GetProperty(name);
return (T)propertyInfo.GetValue(src, null);
}
catch (Exception) { }
return default(T);
}
public static void SetField<T>(object src, string name, T value)
{
try
{
if (src == null) return;
var propertyInfo = src.GetType().GetProperty(name);
propertyInfo.SetValue(src, value, null);
}
catch (Exception) { }
return;
}
public virtual bool hasProperty(string name, Type TYPE)
{
try
{
var propertyInfo = GetType().GetProperty(name);
if (propertyInfo != null && propertyInfo.GetValue(this, null) != null)
return propertyInfo.GetValue(this, null).GetType() == TYPE;
}
catch (Exception) { }
return false;
}
public virtual T getProperty<T>(string name)
{
try
{
var propertyInfo = GetType().GetProperty(name);
return (T)propertyInfo.GetValue(this, null);
}
catch (Exception) { }
return default(T);
}
public virtual void setProperty<T>(string name, T value)
{
try
{
var propertyInfo = GetType().GetProperty(name);
propertyInfo.SetValue(this, value, null);
}
catch (Exception) { }
return;
}
public virtual void initialization(string information)
{
Information = information;
initialize();
}
public virtual void initialize()
{
initData();
initValue();
initProperty();
initConnect();
}
public virtual void deinitialize()
{
deleConnect();
deleProperty();
deleValue();
deleData();
}
public virtual void initData() { }
public virtual void initValue() { }
public virtual void initProperty() { }
public virtual void initConnect() { }
public virtual void deleData() { }
public virtual void deleValue() { }
public virtual void deleProperty() { }
public virtual void deleConnect() { }
public void From(object source)
{
if (source == null)
return;
if (object.ReferenceEquals(this, source))
return;
Type type = source.GetType();
foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
{
if (!property.CanWrite) continue;
if (!hasProperty(property.Name, property.PropertyType)) continue;
object value = property.GetValue(source);
if (value == null || property.PropertyType.IsValueType || property.PropertyType == typeof(string))
{
property.SetValue(this, value);
}
else
{
property.SetValue(this, DeepCopy(value));
}
}
}
public object Copy()
{
Type type = GetType();
object target = DeepCopy(this);
return target;
}
public static object DeepCopy(object source)
{
if (source == null) return null;
Type type = source.GetType();
object target = Activator.CreateInstance(type);
// 遍历所有属性
foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
{
if (!property.CanWrite) continue;
object value = property.GetValue(source);
if (value == null || property.PropertyType.IsValueType || property.PropertyType == typeof(string))
{
property.SetValue(target, value);
}
else
{
property.SetValue(target, DeepCopy(value));
}
}
// 遍历所有字段
foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
{
object value = field.GetValue(source);
if (value == null || field.FieldType.IsValueType || field.FieldType == typeof(string))
{
field.SetValue(target, value);
}
else
{
field.SetValue(target, DeepCopy(value));
}
}
return target;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YQLUtils
{
public class ModBusUtil
{
public static int UShortToInt(ushort[] buffer)
{
if (buffer.Length < 2)
return default(int);
int high = buffer[0];
int low = buffer[1];
int value = (high << 16) + low;
return value;
}
public static uint UShortToUInt(ushort[] buffer)
{
if (buffer.Length < 2)
return default(int);
int high = buffer[0];
int low = buffer[1];
uint value = Convert.ToUInt32((high << 16) + low);
return value;
}
public static long UShortToLong(ushort[] array, bool isLower = true)
{
if (array.Length < 4)
return default(long);
long result = 0;
int maxElements = Math.Min(array.Length, 4);
for (int i = 0; i < array.Length && i < 4; i++) // long 最多容纳 4 个 ushort (64 位 / 16 位 = 4)
{
if (isLower)
result |= ((long)array[i]) << (i * 16);
else
result |= ((long)array[i]) << ((maxElements - 1 - i) * 16);
}
return result;
}
public static ulong UShortToULong(ushort[] array, bool isLower = true)
{
if (array.Length < 4)
return default(long);
ulong result = 0;
int maxElements = Math.Min(array.Length, 4);
for (int i = 0; i < array.Length && i < 4; i++) // long 最多容纳 4 个 ushort (64 位 / 16 位 = 4)
{
if (isLower)
result |= ((ulong)array[i]) << (i * 16);
else
result |= ((ulong)array[i]) << ((maxElements - 1 - i) * 16);
}
return result;
}
public static float UShortToFloat(ushort[] array)
{
if (array.Length < 2)
return default(float);
byte[] bytes = new byte[4];
Buffer.BlockCopy(array, 0, bytes, 0, 4);
// 将 byte 数组转换为 float
return BitConverter.ToSingle(bytes, 0);
}
public static ushort[] FloatToUShortArray(float buffer)
{
byte[] bytes = BitConverter.GetBytes(buffer);
// 将byte数组转换为ushort数组(每2个byte组成1个ushort)
ushort[] result = new ushort[2]; // float为32位,可拆分为2个ushort(2×16=32位)
for (int i = 0; i < 2; i++)
{
result[i] = BitConverter.ToUInt16(bytes, i * 2);
}
return result;
}
public static ushort[] Float2UShortArray(float value)
{
// 获取float的位表示
uint intValue = (uint)BitConverter.DoubleToInt64Bits(value);
ushort[] result = new ushort[2];
// 提取低16位
result[0] = (ushort)(intValue & 0xFFFF);
// 提取高16位
result[1] = (ushort)((intValue >> 16) & 0xFFFF);
return result;
}
public static ushort[] LongToUShortArray(long buffer)
{
ushort[] result = new ushort[4];
for (int i = 0; i < 4; i++)
{
result[i] = (ushort)((buffer >> (i * 16)) & 0xFFFF);
}
return result;
}
public static ushort[] ULongToUShortArray(ulong buffer)
{
ushort[] result = new ushort[4];
for (int i = 0; i < 4; i++)
{
result[i] = (ushort)((buffer >> (i * 16)) & 0xFFFF);
}
return result;
}
public static ushort[] IntToUShortArray(int buffer)
{
ushort ust1 = (ushort)(buffer >> 16);
ushort ust2 = (ushort)buffer;
return new ushort[] { ust1, ust2 };
}
public static ushort[] UIntToUShortArray(uint buffer)
{
ushort ust1 = (ushort)(buffer >> 16);
ushort ust2 = (ushort)buffer;
return new ushort[] { ust1, ust2 };
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YQLUtils
{
public class Settings
{
public const int RECODE_FAILURE = 0 ;
public const int RECODE_SUCCEED = 1 ;
public const int RECODE_WARNING = 2 ;
public const int RECODE_CHANGED = 3 ;
public const int RECODE_JUMPING = 4 ;
public const int CODE_SUCCESS = 200 ;
public const int CODE_FAILURE = 500 ;
public const int CODE_WARNING = 201 ;
public const int AXIS_STATUS_REGISTER_0 = 0 ;
public const int AXIS_STATUS_REGISTER_1 = 1 ;
public const int AXIS_STATUS_REGISTER_2 = 2 ;
public const int AXIS_STATUS_REGISTER_3 = 3 ;
public const int AXIS_STATUS_REGISTER_4 = 4 ;
public const int READONLY_AXIS_STATUS_REGISTER_0 = 0 ;
public const int READONLY_AXIS_STATUS_REGISTER_1 = 1 ;
public const int READONLY_AXIS_STATUS_REGISTER_2 = 2 ;
public const int READONLY_AXIS_STATUS_REGISTER_3 = 3 ;
public const int READONLY_AXIS_STATUS_REGISTER_4 = 4 ;
public const int READONLY_AXIS_STATUS_REGISTER_5 = 5 ;
public const string DEFAULT_STR = default(string );
public const bool DEFAULT_BOOL = default(bool );
public const short DEFAULT_SHORT = default(short );
public const ushort DEFAULT_USHORT = default(ushort );
public const int DEFAULT_INT = default(int );
public const uint DEFAULT_UINT = default(uint );
public const long DEFAULT_LONG = default(long );
public const ulong DEFAULT_ULONG = default(ulong );
public const float DEFAULT_FLOAT = default(float );
public const bool [] DEFAULT_BOOL_ARRAY = default(bool [] );
public const short [] DEFAULT_SHORT_ARRAY = default(short [] );
public const ushort [] DEFAULT_USHORT_ARRAY = default(ushort[] );
public const int [] DEFAULT_INT_ARRAY = default(int [] );
public const uint [] DEFAULT_UINT_ARRAY = default(uint [] );
public const long [] DEFAULT_LONG_ARRAY = default(long [] );
public const ulong [] DEFAULT_ULONG_ARRAY = default(ulong [] );
public const float [] DEFAULT_FLOAT_ARRAY = default(float [] );
public const byte [] DEFAULT_BIT = default(byte [] );
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NModbus" version="3.0.81" targetFramework="net48" />
<package id="NModbus4" version="2.1.0" targetFramework="net48" />
<package id="System.Net.Sockets" version="4.3.0" targetFramework="net48" />
</packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment