-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tag string writing #18
Comments
The method names in Java are setString() and write(). If you are using standard string types, this should work. It is tested and works with Control/CompactLogix, PLC-5 and Micrologix PLCs. Can you please give more information about what happens when this does not work for you? |
this event is executed by pressing a button. Private Sub Button1_Click
End Sub when pressing the button I write in tag4 the value of an editext. and clean the editext to enter new text. |
Can you please capture debugging output and attach that to this issue? You can use tag.setDebugLevel(Tag.PLCTAG_DEBUG_DETAIL) to set the debug level. This will output a lot of information on stdout. If you are using Windows or a Unix-like system, you can use
That will redirect all the output to the text file There may be extra characters in the buffer, but the length field should be correct. Is the string of the standard system type |
This is what you need? |
Thanks, I will look at this today. |
Sorry, work has been busy. I see that you are using the previous release, 2.3.4. That is almost a year old. Can you please update to the newest version? It uses version 2.4.9 of the C DLL. I see some strange values being written to the PLC:
The string you are sending to the C DLL is not valid ASCII. It is not valid UTF-8 encoded UNICODE. Please check the value you are setting the string to. It is not valid ASCII or UTF-8 data. |
Did you find out what is causing your string data to be damaged? |
No, I did the same test with the JAVA wrapper in itenjiJ and the same problem, I don't know what can happen. Is there any way to force the LEN value of the string after writing it? |
You can force the length after calling setString(), but the fact that the data shows the string to be the wrong length means that you are passing an incorrect string to the library. Are you using a String or a byte[]? |
I am using a string, how can I force the length? |
This is the code in the itenlliJ project, with the libplctag4J container, version 2-4-12. I work with compactLogix 5380. It has the same problem when writing the tag string: package com.company; import io.github.libplctag.Tag; import java.util.Scanner; public class Main {
// PRUEBA_TAG4.
} |
There are a few things that are incorrect in this code. First, when you read or write a tag, you need to wait for the operation to be sent to the PLC and the response to come back to the PC. You can do that in two ways:
// start the write operation
int status = tag.write(0);
// now wait in a loop for operation to finish.
while(status == tag.PLCTAG_STATUS_PENDING) {
Thread.sleep(20); // sleep 20 milliseconds
status = tag.getStatus();
}
// below here you should check the status to make sure the operation succeeded. Second, you need to explicitly read and write tag values. You are calling write(), but I do not see calls to read() after you change a value. Calling read() sends a request to the PLC to get the value of the tag. When the PLC responds, that value is loaded into the tag's internal buffer in memory in the PC. When you call write(), the value in the tag's memory in the PC is sent to the PLC. To help debugging, please output the length of the string as well as the value. |
This is better?: `package com.company; import io.github.libplctag.Tag; import java.util.Scanner; public class Main {
// PRUEBA_TAG4.
}` This is my Main: C:\Java\jdk-11.0.1\jdk-11.0.1\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.2\lib\idea_rt.jar=52168:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\rafab\IdeaProjects\PLCDemo\out\production\PLCDemo;C:\Users\rafab\Downloads\libplctag4j-0.9.17-2.4.12\libplctag4j-0.9.17-2.4.12.jar com.company.Main abr. 12, 2022 4:10:26 A. M. com.sun.jna.NativeLibrary loadLibrary abr. 12, 2022 4:10:26 A. M. com.sun.jna.NativeLibrary loadLibrary abr. 12, 2022 4:10:26 A. M. com.sun.jna.Native extractFromResourcePath Process finished with exit code 0 Where I read the value, write it and read it again. |
I use the libplctrag4j library. I would like to know the correct way to write on a tag of type string, because sometimes the result is not the desired one
is this correct?
tag4.SetString(0,"value")
tag4.Write(TIMEOUT)
The text was updated successfully, but these errors were encountered: