[ 
https://issues.apache.org/jira/browse/PLC4X-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17536410#comment-17536410
 ] 

Andy Grebe commented on PLC4X-341:
----------------------------------

Hi Chris,

I was able to get the LINTs working without an issue.  However, the STRING 
seems to be an issue.  When I read a string, I get the following in the command 
specific data:

a002ce0f040000007465737400000000...(the 0s at the end are due to the fact that 
strings are a set size of 82 BYTEs)

So the 0x02a0, is specifying a string, or structured data type, I can't get 
clarification on that with the CIP/EIP documentation I've come across.  Then 
there are the next two bytes, which I'm hoping designate the structured data 
type as string, followed by the actual size of the string.  I was able to use 
this to get the string read from the response.

So when writing, I used both the current code and modified code based on the 
above format[^eipcipstringwrite1.pcapng] to write a string:

a0020100544553540000000000000000... for the current code in plc4x

and

a002ce0f0400000054455354000000000...modified to resemble the packet sent on a 
read.

However, both give me a status of 0xFF and extended status of 0x2107, which 
from Allen Bradley specifies  {_}0x2107{_}. General {_}Error{_}: Data type used 
in request does not match the data type of the target tag.  The tag name is the 
same.  I did reach out to support to see if there is an issue with the data, or 
if they don't actually support STRING writes.  I did attach a wireshark dump 
from when I was testing.

 

Also, what other data types are missing?

 

Andy

 

> PLC4J GIP/CIP Read STRING tag returns null w/error
> --------------------------------------------------
>
>                 Key: PLC4X-341
>                 URL: https://issues.apache.org/jira/browse/PLC4X-341
>             Project: Apache PLC4X
>          Issue Type: Bug
>          Components: Driver-Ethernet/IP, PLC4J
>    Affects Versions: 0.9.1
>            Reporter: Andy Grebe
>            Priority: Major
>         Attachments: eipcipstringread.pcapng, eipcipstringwrite1.pcapng
>
>
> STRING tag reads in plc4j using eip are not returning the string.  The error 
> returned is:
> java.lang.NullPointerException: Cannot invoke 
> "org.apache.plc4x.java.api.value.PlcValue.getString()" because the return 
> value of 
> "org.apache.plc4x.java.api.messages.PlcReadResponse.getPlcValue(String)" is 
> null
> It looks like plc4j is considering it a structure or array.  If I read with 
> {code:java}
> %MyString[{index}]:STRING:1 {code}
> I can get the individual characters in the string by placing the actual index 
> in \{index}.  So it knows where to start reading the data from. 
> When running a wireshark cap, I can see the returned string in the response 
> from the PLC.  Attached is a pcap of the transaction.
>  
> Code Snippet:
> {code:java}
> try (PlcConnection plcConnection = new 
> PlcDriverManager().getConnection("eip://127.0.0.1")) {
>     if (!plcConnection.getMetadata().canRead()) {
>         logger.error("PLC connection doesn't support reading.");
>         return;
>     }
>     logger.info("PLC connector connected");    // Create a new read request:
>     PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
>     logger.info("Created Builder");
>     builder.addItem("value-1", "%MyString:STRING:1");
>     PlcReadRequest readRequest = builder.build();    // Register a callback 
> executed as soon as a response arrives.
>     logger.info("Make sync request for PLC data");
>     PlcReadResponse readResponse = readRequest.execute().get(5000, 
> TimeUnit.MILLISECONDS);
>     if (readResponse != null) {
>         printPlcResponse(readResponse);
>     } else {
>         logger.error("An error reading PLC, response is NULL");
>     }
>     for (String field : readResponse.getFieldNames()){
>         rtnArray.add(new PlcReadResponseData(field,
>             readResponse.getPlcValue(field).getString()) );  // Exception is 
> thrown here
>     }
> } catch (PlcConnectionException e) {
>     e.printStackTrace();    
> } {code}
>  



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to