Skip to content

Commit

Permalink
Implement EtherNetIP#readTags()
Browse files Browse the repository at this point in the history
  • Loading branch information
kasemir committed May 25, 2017
1 parent ab321c6 commit 8b75cac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGE_LOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changes
Version number is in EtherNetIP.version

* 1.2 - 2017/05/25
Fix: Support reading and writing STRING tags (#12)
Fix: Support reading and writing STRING tags (#12).
Implement EtherNetIP#readTags()

* 1.1 - 2016/12/15
Fix: Handle path tags like "array[2].element" (#8)
Expand Down
11 changes: 7 additions & 4 deletions src/etherip/EtherNetIP.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ public CIPData readTag(final String tag, short count) throws Exception

/** Read multiple scalar tags in one network transaction
* @param tags Tag names
* @return Current value of the tag
* @return Current values of the tags
* @throws Exception on error
*/
public CIPData readTags(final String... tags) throws Exception
public CIPData[] readTags(final String... tags) throws Exception
{
final MRChipReadProtocol[] reads = new MRChipReadProtocol[tags.length];
for (int i=0; i<reads.length; ++i)
Expand All @@ -196,8 +196,11 @@ public CIPData readTags(final String... tags) throws Exception
new CIPMultiRequestProtocol(reads)))));
connection.execute(encap);

// TODO Nothing decodes the individual responses
throw new Exception("Decoding of response to CIP_MultiRequest has not been implemented");
final CIPData[] results = new CIPData[reads.length];
for (int i=0; i<results.length; ++i)
results[i] = reads[i].getData();

return results;
}

/** Write a tag
Expand Down
19 changes: 13 additions & 6 deletions test/etherip/EtherIPDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.logging.Logger;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import etherip.types.CIPData;
Expand All @@ -31,7 +30,7 @@ public void setup()
{
TestSettings.logAll();
Logger.getLogger("").setLevel(Level.ALL);
Logger.getLogger("").setLevel(Level.WARNING);
//Logger.getLogger("").setLevel(Level.WARNING);
}

@Test
Expand Down Expand Up @@ -148,7 +147,6 @@ public void testString() throws Exception
}

@Test
@Ignore
public void testMultiRead() throws Exception
{
try
Expand All @@ -159,9 +157,18 @@ public void testMultiRead() throws Exception
plc.connect();

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

for (int i=0; i<results.length; ++i)
System.out.println(tags[i] + " = " + results[i]);
}
}
}

0 comments on commit 8b75cac

Please sign in to comment.