public class ModbusTcpNet extends NetworkDeviceBase implements IModbus
WordLengthAlienSession, isPersistentConn, IsSocketError, isUseAccountCertificate, LogMsgFormatBinary, simpleHybirdLockCoreSocket, fileCacheSize, LogNet, TokenLogNet| 构造器和说明 |
|---|
ModbusTcpNet()
实例化一个Modbus-Tcp协议的客户端对象
Instantiate a client object of the Modbus-Tcp protocol |
ModbusTcpNet(String ipAddress,
int port,
byte station)
指定服务器地址,端口号,客户端自己的站号来初始化
Specify the server address, port number, and client's own station number to initialize |
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
getAddressStartWithZero()
获取起始地址是否从0开始
|
DataFormat |
getDataFormat()
获取多字节数据的反转类型,适用于int,float,double,long类型的数据
|
protected INetMessage |
GetNewNetMessage()
获取一个新的消息对象的方法,需要在继承类里面进行重写
The method to get a new message object needs to be overridden in the inheritance class |
byte |
getStation()
获取站号
|
boolean |
isStringReverse()
字符串数据是否发生反转
|
protected byte[] |
PackCommandWithHeader(byte[] command)
对当前的命令进行打包处理,通常是携带命令头内容,标记当前的命令的长度信息,需要进行重写,否则默认不打包
|
OperateResultExOne<byte[]> |
Read(String address,
short length)
从Modbus服务器批量读取寄存器的信息,需要指定起始地址,读取长度,如果富文本地址不指定,默认使用的功能码是 0x03,如果需要使用04功能码,那么地址就写成 "x=4;100"
To read the register information from the Modbus server in batches, you need to specify the start address and read length. |
OperateResultExOne<boolean[]> |
ReadBool(String address,
short length)
批量读取线圈或是离散的数据信息,需要指定地址和长度,具体的结果取决于实现,如果富文本地址不指定,默认使用的功能码是 0x01
To read coils or discrete data in batches, you need to specify the address and length. |
OperateResultExOne<Boolean> |
ReadCoil(String address)
读取线圈,需要指定起始地址,如果富文本地址不指定,默认使用的功能码是 0x01
To read the coil, you need to specify the start address. |
OperateResultExOne<boolean[]> |
ReadCoil(String address,
short length)
批量的读取线圈,需要指定起始地址,读取长度,如果富文本地址不指定,默认使用的功能码是 0x01
For batch reading coils, you need to specify the start address and read length. |
OperateResultExOne<Boolean> |
ReadDiscrete(String address)
读取输入线圈,需要指定起始地址,如果富文本地址不指定,默认使用的功能码是 0x02
To read the input coil, you need to specify the start address. |
OperateResultExOne<boolean[]> |
ReadDiscrete(String address,
short length)
批量的读取输入点,需要指定起始地址,读取长度,如果富文本地址不指定,默认使用的功能码是 0x02
To read input points in batches, you need to specify the start address and read length. |
void |
setAddressStartWithZero(boolean addressStartWithZero)
设置起始地址是否从0开始
|
void |
setDataFormat(DataFormat dataFormat)
设置多字节数据的反转类型,适用于int,float,double,long类型的数据
|
void |
setStation(byte station)
设置站号
|
void |
setStringReverse(boolean stringReverse)
设置字符串数据是否反转
|
String |
toString()
返回表示当前对象的字符串
|
OperateResultExOne<String> |
TranslateToModbusAddress(String address,
byte modbusCode)
将当前的地址信息转换成Modbus格式的地址,如果转换失败,返回失败的消息。
|
protected OperateResultExOne<byte[]> |
UnpackResponseContent(byte[] send,
byte[] response)
根据对方返回的报文命令,对命令进行基本的拆包,例如各种Modbus协议拆包为统一的核心报文,还支持对报文的验证
|
OperateResult |
Write(String address,
boolean value)
向线圈中写入bool数值,返回是否写入成功,如果富文本地址不指定,默认使用的功能码是 0x05
Write bool value to the coil and return whether the writing is successful. |
OperateResult |
Write(String address,
boolean[] values)
向线圈中写入bool数组,返回是否写入成功,如果富文本地址不指定,默认使用的功能码是 0x0F
Write the bool array to the coil, and return whether the writing is successful. |
OperateResult |
Write(String address,
byte[] value)
将数据写入到Modbus的寄存器上去,需要指定起始地址和数据内容,如果富文本地址不指定,默认使用的功能码是 0x10
To write data to Modbus registers, you need to specify the start address and data content. |
OperateResult |
Write(String address,
short value)
将数据写入到Modbus的单个寄存器上去,需要指定起始地址和数据值,如果富文本地址不指定,默认使用的功能码是 0x06
To write data to a single register of Modbus, you need to specify the start address and data value. |
OperateResult |
WriteMask(String address,
short andMask,
short orMask)
向设备写入掩码数据,使用0x16功能码,需要确认对方是否支持相关的操作,掩码数据的操作主要针对寄存器。
|
OperateResult |
WriteOneRegister(String address,
short value)
将数据写入到Modbus的单个寄存器上去,需要指定起始地址和数据值,如果富文本地址不指定,默认使用的功能码是 0x06
To write data to a single register of Modbus, you need to specify the start address and data value. |
ReadBool, ReadCustomer, ReadDouble, ReadDouble, ReadFloat, ReadFloat, ReadInt16, ReadInt16, ReadInt32, ReadInt32, ReadInt64, ReadInt64, ReadString, ReadString, ReadUInt16, ReadUInt16, ReadUInt32, ReadUInt32, Write, Write, Write, Write, Write, Write, Write, Write, Write, Write, Write, Write, Write, WriteCustomer, WriteUnicodeString, WriteUnicodeStringAccountCertificate, ConnectClose, ConnectServer, ConnectServer, ExtraAfterReadFromCoreServer, ExtraOnDisconnect, GetAvailableSocket, getByteTransform, getConnectionId, getConnectTimeOut, getIpAddress, getPort, getReceiveTimeOut, getSleepTime, InitializationOnConnect, IpAddressPing, ReadFromCoreServer, ReadFromCoreServer, ReadFromCoreServer, setByteTransform, setConnectionId, setConnectTimeOut, setIpAddress, SetLoginAccount, SetPersistentConnection, setPort, setReceiveTimeOut, setSleepTimeCheckRemoteToken, CloseSocket, CreateSocketAndConnect, CreateSocketAndConnect, CreateSocketAndConnect, ReadStream, Receive, Receive, Receive, ReceiveAndCheckBytes, ReceiveByMessage, ReceiveByMessage, ReceiveBytesContentFromSocket, ReceiveBytesContentFromSocket, ReceiveCommandLineFromSocket, ReceiveCommandLineFromSocket, ReceiveCommandLineFromSocket, ReceiveCommandLineFromSocket, ReceiveFrameWebSocketPayload, ReceiveHslMessage, ReceiveMqttMessage, ReceiveRedisCommand, ReceiveRedisCommandString, ReceiveStringArrayContentFromSocket, ReceiveStringArrayContentFromSocket, ReceiveStringContentFromSocket, ReceiveStringContentFromSocket, ReceiveWebSocketPayload, Send, Send, SendAccountAndCheckReceive, SendBaseAndCheckReceive, SendBytesAndCheckReceive, SendStreamToSocket, SendStringAndCheckReceive, SendStringAndCheckReceive, ThreadPoolCheckTimeOut, WriteStream, WriteStreamFromSocketclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitReadFromCoreServerConnectClose, getConnectionId, ReadBool, ReadCustomer, ReadDouble, ReadDouble, ReadFloat, ReadFloat, ReadInt16, ReadInt16, ReadInt32, ReadInt32, ReadInt64, ReadInt64, ReadString, ReadString, ReadUInt16, ReadUInt16, ReadUInt32, ReadUInt32, setConnectionId, Write, Write, Write, Write, Write, Write, Write, Write, Write, Write, Write, Write, Write, WriteCustomerpublic ModbusTcpNet()
public ModbusTcpNet(String ipAddress, int port, byte station)
ipAddress - 服务器的Ip地址port - 服务器的端口号station - 客户端自身的站号,可以在读取的时候动态配置protected INetMessage GetNewNetMessage()
NetworkDoubleBaseGetNewNetMessage 在类中 NetworkDoubleBasepublic boolean getAddressStartWithZero()
IModbusgetAddressStartWithZero 在接口中 IModbuspublic void setAddressStartWithZero(boolean addressStartWithZero)
IModbussetAddressStartWithZero 在接口中 IModbusaddressStartWithZero - true代表从0开始,false代表从1开始public byte getStation()
IModbusgetStation 在接口中 IModbuspublic void setStation(byte station)
IModbussetStation 在接口中 IModbusstation - 站号public void setDataFormat(DataFormat dataFormat)
IModbussetDataFormat 在接口中 IModbusdataFormat - 数据类型public DataFormat getDataFormat()
IModbusgetDataFormat 在接口中 IModbuspublic boolean isStringReverse()
IModbusisStringReverse 在接口中 IModbuspublic void setStringReverse(boolean stringReverse)
IModbussetStringReverse 在接口中 IModbusstringReverse - bool值protected byte[] PackCommandWithHeader(byte[] command)
NetworkDoubleBasePackCommandWithHeader 在类中 NetworkDoubleBasecommand - 发送的数据命令内容protected OperateResultExOne<byte[]> UnpackResponseContent(byte[] send, byte[] response)
NetworkDoubleBaseUnpackResponseContent 在类中 NetworkDoubleBasesend - 发送的原始报文数据response - 设备方反馈的原始报文内容public OperateResultExOne<String> TranslateToModbusAddress(String address, byte modbusCode)
IModbusTranslateToModbusAddress 在接口中 IModbusaddress - 传入的地址modbusCode - Modbus的功能码public OperateResultExOne<Boolean> ReadCoil(String address)
address - 起始地址,格式为"1234"public OperateResultExOne<boolean[]> ReadCoil(String address, short length)
address - 起始地址,格式为"1234"length - 读取长度public OperateResultExOne<Boolean> ReadDiscrete(String address)
address - 起始地址,格式为"1234"public OperateResultExOne<boolean[]> ReadDiscrete(String address, short length)
address - 起始地址,格式为"1234"length - 读取长度public OperateResultExOne<byte[]> Read(String address, short length)
Read 在接口中 IReadWriteNetRead 在类中 NetworkDeviceBaseaddress - 起始地址,比如"100","x=4;100","s=1;100","s=1;x=4;100"length - 读取的数量public OperateResult Write(String address, byte[] value)
Write 在接口中 IReadWriteNetWrite 在类中 NetworkDeviceBaseaddress - 起始地址,比如"100","x=4;100","s=1;100","s=1;x=4;100"value - 写入的数据,长度根据data的长度来指示public OperateResult Write(String address, short value)
Write 在接口中 IReadWriteNetWrite 在类中 NetworkDeviceBaseaddress - 起始地址,比如"100","x=4;100","s=1;100","s=1;x=4;100"value - 写入的short数据public OperateResult WriteMask(String address, short andMask, short orMask)
address - 起始地址,比如"100","x=4;100","s=1;100","s=1;x=4;100"andMask - 等待与操作的掩码数据orMask - 等待或操作的掩码数据public OperateResult WriteOneRegister(String address, short value)
address - 起始地址,比如"100","x=4;100","s=1;100","s=1;x=4;100"value - 写入的short数据public OperateResultExOne<boolean[]> ReadBool(String address, short length)
ReadBool 在接口中 IReadWriteNetReadBool 在类中 NetworkDeviceBaseaddress - 数据地址length - 数据长度public OperateResult Write(String address, boolean[] values)
Write 在接口中 IReadWriteNetWrite 在类中 NetworkDeviceBaseaddress - 要写入的数据地址values - 要写入的实际数组public OperateResult Write(String address, boolean value)
Write 在接口中 IReadWriteNetWrite 在类中 NetworkDeviceBaseaddress - 要写入的数据地址value - 要写入的实际数据public String toString()
toString 在类中 NetworkDeviceBaseCopyright © 2022. All rights reserved.