forked from steveohara/j2mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Steve O'Hara
committed
Apr 20, 2018
1 parent
7ddaff0
commit 1f7e4f9
Showing
5 changed files
with
107 additions
and
36 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
37 changes: 37 additions & 0 deletions
37
src/test/java/com/ghgande/j2mod/modbus/cmd/MasterReadTest.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,37 @@ | ||
/* | ||
* | ||
* Copyright (c) 2018, 4ng and/or its affiliates. All rights reserved. | ||
* 4ENERGY PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. | ||
* | ||
*/ | ||
package com.ghgande.j2mod.modbus.cmd; | ||
|
||
import com.ghgande.j2mod.modbus.facade.ModbusTCPMaster; | ||
import com.ghgande.j2mod.modbus.procimg.Register; | ||
|
||
/** | ||
* | ||
*/ | ||
public class MasterReadTest { | ||
|
||
public static void main(String[] args) { | ||
ModbusTCPMaster master = new ModbusTCPMaster("localhost", 502, 1000, true); | ||
try { | ||
master.connect(true); | ||
for (int i = 0; i < 10; i++) { | ||
int ref = 100; | ||
Register[] regs = master.readMultipleRegisters(1, ref, 10); | ||
for (Register reg : regs) { | ||
System.out.printf("Reg: %d Val: %d\n", ref, reg.getValue()); | ||
ref++; | ||
} | ||
} | ||
} | ||
catch (Exception e) { | ||
System.out.printf("ERROR - %s\n", e.getMessage()); | ||
} | ||
finally { | ||
master.disconnect(); | ||
} | ||
} | ||
} |