Skip to content

Commit

Permalink
Add 'int' test
Browse files Browse the repository at this point in the history
  • Loading branch information
kasemir committed Jun 16, 2017
1 parent 1c5e701 commit 040c4c4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 18 deletions.
3 changes: 2 additions & 1 deletion test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plc=192.168.200.82
slot=0
write_tag=Body1HFlow
float_tag=Body1HFlow
bool_tag=Body1HFlow
int_tag=Limits6[3]
bool_tag=Bool1
string_tag=String1
invalid_tag=bogus_tag_name
86 changes: 69 additions & 17 deletions test/etherip/EtherIPDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ public void setup()
@Test
public void testConnectTcp() throws Exception
{
try (EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));)
try
(
EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));
)
{
plc.connectTcp();

Expand All @@ -67,8 +70,11 @@ public void testConnectUdp() throws Exception
Logger.getLogger("").setLevel(Level.INFO);

TestSettings.logAll();
try (EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));)
try
(
EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));
)
{
plc.connectUdp();

Expand Down Expand Up @@ -98,8 +104,11 @@ public void testConnectUdp() throws Exception
@Test
public void testFloat() throws Exception
{
try (EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));)
try
(
EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));
)
{
plc.connectTcp();

Expand Down Expand Up @@ -127,11 +136,49 @@ public void testFloat() throws Exception
}
}

@Test
public void testInt() throws Exception
{
try
(
EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));
)
{
plc.connectTcp();

final String tag = TestSettings.get("int_tag");

System.out.println("\n*\n* int '" + tag + "':\n*\n");
CIPData value = plc.readTag(tag);
System.out.println(value);
assertThat(value, not(nullValue()));
value.set(0, 42);
plc.writeTag(tag, value);

value = plc.readTag(tag);
assertThat(value, not(nullValue()));
System.out.println("Changed to " + value);
assertThat(value.getNumber(0).intValue(), equalTo(42));

value.set(0, 47);
plc.writeTag(tag, value);

value = plc.readTag(tag);
assertThat(value, not(nullValue()));
System.out.println("Changed to " + value);
assertThat(value.getNumber(0).intValue(), equalTo(47));
}
}

@Test
public void testBool() throws Exception
{
try (EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));)
try
(
EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));
)
{
plc.connectTcp();

Expand All @@ -140,7 +187,9 @@ public void testBool() throws Exception

CIPData value = plc.readTag(tag);
System.out.println("Original Value: " + value);

System.out.flush();
System.err.flush();

value = new CIPData(Type.BOOL, 1);

value.set(0, 1);
Expand Down Expand Up @@ -169,8 +218,11 @@ public void testBool() throws Exception
@Test
public void testString() throws Exception
{
try (EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));)
try
(
EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));
)
{
plc.connectTcp();

Expand All @@ -183,13 +235,9 @@ public void testString() throws Exception
assertThat(value.isNumeric(), equalTo(false));
String new_value = value.getString();
if (new_value.equals("test"))
{
new_value = "Testing!";
}
else
{
new_value = "test";
}
System.out.println("Writing '" + new_value + "'");
value.setString(new_value);
plc.writeTag(tag, value);
Expand All @@ -203,14 +251,18 @@ public void testString() throws Exception
@Test
public void testMultiRead() throws Exception
{
try (EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));)
try
(
EtherNetIP plc = new EtherNetIP(TestSettings.get("plc"),
TestSettings.getInt("slot"));
)
{
plc.connectTcp();

System.out.println("\n*\n* Multi read:\n*\n");
final String[] tags = new String[] { TestSettings.get("float_tag"),
TestSettings.get("bool_tag"),
TestSettings.get("int_tag"),
TestSettings.get("string_tag") };
final CIPData[] results = plc.readTags(tags);
assertThat(results, not(nullValue()));
Expand Down

0 comments on commit 040c4c4

Please sign in to comment.