import dotNet;
import util.metaProperty;
import console;
namespace enet;
class easymodbus {
ctor(...) {
//var appDomain = ..dotNet.clr().createAppDomain()
var _dll = ..dotNet.loadFile($"~\lib\enet\easymodbus\.res\EasyModbus.dll");
this.客户端 = _dll.new("ModbusClient",...);
this.客户端.ReceiveDataChanged = function(...){
if(this.onRxData){
this.onRxData(...);
}
};
this.客户端.SendDataChanged = function(...)
{
if(this.onTxData){
this.onTxData(...);
}
}
};
@_metaProperty; //modbus的属性元表
}
easymodbus._metaProperty = ..util.metaProperty(
连接 = function() {
owner.客户端.Connect();
};
断开 = function() {
owner.客户端.Disconnect();
};
检查网络状态 = function() {
return owner.客户端.Available(1000/*超时时间*/)
};
//01功能码,读取线圈状态
读线圈输出状态 = function(.../*@1开始地址, @2线圈数量*/) {
return owner.客户端.ReadCoils(...);
};
//02功能码,读取离散输入状态
读离散输入状态 = function(.../*@1开始地址, @2线圈数量*/) {
return owner.客户端.ReadDiscreteInputs(...);
};
//05功能码,写入单个线圈状态
写单个线圈 = function(.../*@1开始地址, @2布尔值*/) {
owner.客户端.WriteSingleCoil(...);
};
//15功能码,写入多个线圈状态
写多个线圈 = function(.../*@1开始地址, @2{布尔值,布尔值,布尔值,布尔值}*/) {
owner.客户端. WriteMultipleCoils(...);
};
//03功能码,读取保持寄存器
读保持寄存器 = function(.../*@1开始地址, @2寄存器数量*/) {
return owner.客户端.ReadHoldingRegisters(...);
};
//04功能码,读取输入寄存器
读输入寄存器 = function(.../*@1开始地址, @2寄存器数量*/) {
return owner.客户端.ReadInputRegisters(...);
};
//06功能码,写入单个保持寄存器
写单个保持寄存器 = function(.../*@1开始地址, @2值*/) {
owner.客户端.WriteSingleRegister(...);
};
//16功能码,写入多个保持寄存器
写多个保持寄存器 = function(.../*@1开始地址, @2{值1,值2,...}*/) {
owner.客户端.WriteMultipleRegisters(...);
};
连接状态 = {
_get = function() {
return owner.客户端.Connected;
}
};
ip地址 = {
_get = function() {
return owner.客户端.IPAddress;
}
_set = function(...) {
owner.客户端.IPAddress = ...;
}
};
端口 = {
_get = function() {
return owner.客户端.Port;
}
_set = function(...) {
owner.客户端.Port = ...;
}
};
从站地址 = {
_get = function() {
return owner.客户端.UnitIdentifier;
}
_set = function(...) {
owner.客户端.UnitIdentifier = ...;
}
};
串口号 = {
_get = function() {
return owner.客户端.SerialPort;
}
_set = function(...) {
owner.客户端.SerialPort = ...;
}
};
停止位 = {
_get = function() {
return owner.客户端.StopBits;
}
_set = function(...) {
owner.客户端.StopBits = ...;
}
};
奇偶校验 = {
_get = function() {
return owner.客户端.Parity;
}
_set = function(...) {
owner.客户端.Parity = ...;
}
};
波特率 = {
_get = function() {
return owner.客户端.Baudrate;
}
_set = function(...) {
owner.客户端.Baudrate = ...;
}
};
连接超时 = {
_get = function() {
return owner.客户端.ConnectionTimeout;
}
_set = function(...) {
owner.客户端.ConnectionTimeout = ...;
}
};
日志文件文件名 = {
_get = function() {
return owner.客户端.LogFileFilename;
}
_set = function(...) {
owner.客户端.LogFileFilename = ...;
}
};
);