-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: 1# modify tutorial (完善相关教程); 2# upgrade to v1.3.0 (版本升级到v1.3.0);
- Loading branch information
1 parent
a0ded65
commit 27ee4d8
Showing
13 changed files
with
439 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/com/github/xingshuangs/iot/protocol/s7/service/DemoS7Custom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.github.xingshuangs.iot.protocol.s7.service; | ||
|
||
|
||
import com.github.xingshuangs.iot.protocol.s7.enums.*; | ||
import com.github.xingshuangs.iot.protocol.s7.model.*; | ||
|
||
/** | ||
* @author xingshuang | ||
*/ | ||
public class DemoS7Custom { | ||
|
||
public static void main(String[] args) { | ||
S7PLC s7PLC = new S7PLC(EPlcType.S1200, "127.0.0.1"); | ||
|
||
// bit数据读写 | ||
byte[] expect = new byte[]{(byte) 0x00}; | ||
s7PLC.writeRaw(EParamVariableType.BIT, 1, EArea.DATA_BLOCKS, 1, 0, 3, | ||
EDataVariableType.BIT, expect); | ||
byte[] actual = s7PLC.readRaw(EParamVariableType.BIT, 1, EArea.DATA_BLOCKS, 1, 0, 3); | ||
|
||
// byte数据读写 | ||
expect = new byte[]{(byte) 0x02, (byte) 0x03}; | ||
s7PLC.writeRaw(EParamVariableType.BYTE, 2, EArea.DATA_BLOCKS, 1, 1, 0, | ||
EDataVariableType.BYTE_WORD_DWORD, expect); | ||
byte[] actual1 = s7PLC.readRaw(EParamVariableType.BYTE, 2, EArea.DATA_BLOCKS, 1, 1, 0); | ||
|
||
// 对象形式发送 | ||
RequestNckItem item = new RequestNckItem(ENckArea.C_CHANNEL, 1, 23, 1, ENckModule.S, 1); | ||
S7Data s7Data = NckRequestBuilder.creatNckRequest(item); | ||
S7Data ackData = s7PLC.readFromServerByPersistence(s7Data); | ||
|
||
// 裸报文发送 | ||
byte[] sendByteArray = new byte[]{ | ||
// tpkt | ||
(byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x1D, | ||
// cotp DT Data | ||
(byte) 0x02, (byte) 0xF0, (byte) 0x80, | ||
// header | ||
(byte) 0x32, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x13, (byte) 0x00, (byte) 0x0C, (byte) 0x00, (byte) 0x00, | ||
// parameter | ||
(byte) 0x04, (byte) 0x01, | ||
// request item | ||
(byte) 0x12, (byte) 0x08, (byte) 0x82, (byte) 0x41, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x7f, (byte) 0x01 | ||
}; | ||
byte[] recByteArray = s7PLC.readFromServerByPersistence(sendByteArray); | ||
|
||
s7PLC.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.