项目初始化

This commit is contained in:
liuhanqing
2025-12-10 10:01:24 +08:00
commit af63c05a97
346 changed files with 54556 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
package com.intelligt.modbus.jlibmodbus.data.comm;
/*
* Copyright (C) 2016 "Invertor" Factory", JSC
* [http://www.sbp-invertor.ru]
*
* This file is part of JLibModbus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors: Vladislav Y. Kochedykov, software engineer.
* email: vladislav.kochedykov@gmail.com
*/
abstract public class ModbusCommEvent {
final private Type type;
private int event = 0;
public ModbusCommEvent(Type type, int event) {
this.type = type;
this.event = type.getCode() | event;
}
static public ModbusCommEvent getEvent(int event) {
for (Type t : Type.values()) {
if ((t.getCode() & event) == t.getCode()) {
switch (t) {
case SEND:
return new ModbusCommEventSend(event);
case RECEIVE:
return new ModbusCommEventReceive(event);
case INITIATED_COMMUNICATION_RESTART:
return new ModbusCommEventInitiatedCommunicationRestart(event);
case ENTER_LISTEN_ONLY_MODE:
return new ModbusCommEventEnterListenOnlyMode(event);
}
}
}
throw new IllegalArgumentException();
}
public Type getType() {
return type;
}
protected boolean isBitsSet(int bits) {
return (event & bits) == bits;
}
public int getEvent() {
return event;
}
public enum Type {
SEND(0x80),
RECEIVE(0x40),
INITIATED_COMMUNICATION_RESTART(0x0),
ENTER_LISTEN_ONLY_MODE(0x10);
final private int code;
Type(int code) {
this.code = code;
}
public int getCode() {
return code;
}
}
}

View File

@@ -0,0 +1,32 @@
package com.intelligt.modbus.jlibmodbus.data.comm;
/*
* Copyright (C) 2016 "Invertor" Factory", JSC
* [http://www.sbp-invertor.ru]
*
* This file is part of JLibModbus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors: Vladislav Y. Kochedykov, software engineer.
* email: vladislav.kochedykov@gmail.com
*/
public class ModbusCommEventEnterListenOnlyMode extends ModbusCommEvent {
public ModbusCommEventEnterListenOnlyMode() {
super(Type.ENTER_LISTEN_ONLY_MODE, 0);
}
public ModbusCommEventEnterListenOnlyMode(int event) {
super(Type.ENTER_LISTEN_ONLY_MODE, event);
}
}

View File

@@ -0,0 +1,33 @@
package com.intelligt.modbus.jlibmodbus.data.comm;
/*
* Copyright (C) 2016 "Invertor" Factory", JSC
* [http://www.sbp-invertor.ru]
*
* This file is part of JLibModbus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors: Vladislav Y. Kochedykov, software engineer.
* email: vladislav.kochedykov@gmail.com
*/
public class ModbusCommEventInitiatedCommunicationRestart extends ModbusCommEvent {
public ModbusCommEventInitiatedCommunicationRestart() {
this(0);
}
protected ModbusCommEventInitiatedCommunicationRestart(int event) {
super(Type.INITIATED_COMMUNICATION_RESTART, event);
}
}

View File

@@ -0,0 +1,65 @@
package com.intelligt.modbus.jlibmodbus.data.comm;
/*
* Copyright (C) 2016 "Invertor" Factory", JSC
* [http://www.sbp-invertor.ru]
*
* This file is part of JLibModbus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors: Vladislav Y. Kochedykov, software engineer.
* email: vladislav.kochedykov@gmail.com
*/
public class ModbusCommEventReceive extends ModbusCommEvent {
final static private int BIT_COMMUNICATION_ERROR = 0x1;
final static private int BIT_CHARACTER_OVERRUN = 0x10;
final static private int BIT_CURRENTLY_IN_LISTEN_ONLY_MODE = 0x20;
final static private int BIT_BROADCAST_RECEIVED = 0x40;
protected ModbusCommEventReceive(int event) {
super(Type.RECEIVE, event);
}
static public ModbusCommEventReceive createCommunicationError() {
return new ModbusCommEventReceive(BIT_COMMUNICATION_ERROR);
}
static public ModbusCommEventReceive createCharacterOverrun() {
return new ModbusCommEventReceive(BIT_CHARACTER_OVERRUN);
}
static public ModbusCommEventReceive createCurrentlyInListenOnlyMode() {
return new ModbusCommEventReceive(BIT_CURRENTLY_IN_LISTEN_ONLY_MODE);
}
static public ModbusCommEventReceive createBroadcastReceived() {
return new ModbusCommEventReceive(BIT_BROADCAST_RECEIVED);
}
public boolean isCurrentlyInListenOnlyMode() {
return isBitsSet(BIT_CURRENTLY_IN_LISTEN_ONLY_MODE);
}
public boolean isCharacterOverrun() {
return isBitsSet(BIT_CHARACTER_OVERRUN);
}
public boolean isCommunicationError() {
return isBitsSet(BIT_COMMUNICATION_ERROR);
}
public boolean isBroadcastReceived() {
return isBitsSet(BIT_BROADCAST_RECEIVED);
}
}

View File

@@ -0,0 +1,83 @@
package com.intelligt.modbus.jlibmodbus.data.comm;
/*
* Copyright (C) 2016 "Invertor" Factory", JSC
* [http://www.sbp-invertor.ru]
*
* This file is part of JLibModbus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors: Vladislav Y. Kochedykov, software engineer.
* email: vladislav.kochedykov@gmail.com
*/
public class ModbusCommEventSend extends ModbusCommEvent {
final static private int BIT_READ_EXCEPTION_SENT = 0x1;
final static private int BIT_SLAVE_ABORT_EXCEPTION_SENT = 0x2;
final static private int BIT_SLAVE_BUSY_EXCEPTION_SENT = 0x4;
final static private int BIT_SLAVE_PROGRAM_NAK_EXCEPTION_SENT = 0x8;
final static private int BIT_WRITE_TIMEOUT_ERROR_OCCURRED = 0x10;
final static private int BIT_CURRENTLY_IN_LISTEN_ONLY_MODE = 0x20;
protected ModbusCommEventSend(int event) {
super(Type.SEND, event);
}
static public ModbusCommEventSend createExceptionSentRead() {
return new ModbusCommEventSend(BIT_READ_EXCEPTION_SENT);
}
static public ModbusCommEventSend createExceptionSlaveSentAbort() {
return new ModbusCommEventSend(BIT_SLAVE_ABORT_EXCEPTION_SENT);
}
static public ModbusCommEventSend createExceptionSlaveSentBusy() {
return new ModbusCommEventSend(BIT_SLAVE_BUSY_EXCEPTION_SENT);
}
static public ModbusCommEventSend createExceptionSentSlaveProgramNAK() {
return new ModbusCommEventSend(BIT_SLAVE_PROGRAM_NAK_EXCEPTION_SENT);
}
static public ModbusCommEventSend createWriteTimeoutErrorOccurred() {
return new ModbusCommEventSend(BIT_WRITE_TIMEOUT_ERROR_OCCURRED);
}
static public ModbusCommEventSend createCurrentlyInListenOnlyMode() {
return new ModbusCommEventSend(BIT_CURRENTLY_IN_LISTEN_ONLY_MODE);
}
public boolean isCurrentlyInListenOnlyMode() {
return isBitsSet(BIT_CURRENTLY_IN_LISTEN_ONLY_MODE);
}
public boolean isExceptionSentRead() {
return isBitsSet(BIT_READ_EXCEPTION_SENT);
}
public boolean isExceptionSlaveSentAbort() {
return isBitsSet(BIT_SLAVE_ABORT_EXCEPTION_SENT);
}
public boolean isExceptionSlaveSentBusy() {
return isBitsSet(BIT_SLAVE_BUSY_EXCEPTION_SENT);
}
public boolean isExceptionSentSlaveProgramNAK() {
return isBitsSet(BIT_SLAVE_PROGRAM_NAK_EXCEPTION_SENT);
}
public boolean isWriteTimeoutErrorOccurred() {
return isBitsSet(BIT_WRITE_TIMEOUT_ERROR_OCCURRED);
}
}