Steps to reproduce:
Hello!
I tried to add a URScript to a URCap in generateScript(ScriptWriter writer)
by using this.getClass().getResourceAsStream("/com/my/resources/path/file.script");
but it’s failing when using
writer.appendRaw()
My input stream reading:
public static final String readFromInputStream(InputStream input, int bufferSize) throws IOException {
char[] buffer = new char[bufferSize];
StringBuilder out = new StringBuilder();
Reader in = new InputStreamReader(input, StandardCharsets.UTF_8);
for (int numRead; in.ready() && (numRead = in.read(buffer, 0, buffer.length)) > 0; ) {
out.append(buffer, 0, numRead);
}
return out.toString();
}
Expected Behavior:
Should load without error, as I can load the script I’m using as a file with the Script
node.
Actual Behavior:
I’ve change the name of my functions and variables, what’s interesting is that it’s saying its not my URCap but another URCap installed on the robot, even though the lines displayed are the lines for my script.
The error I got, from the logs:
3.5 :: 0063d00h46m20.851s :: 2024-06-10 12:16:52.513 :: -5 :: C0A0:7 :: null :: 1 :: :: Program <unnamed> starting... (Unsaved) :: null
3.5 :: 0063d00h46m20.851s :: 2024-06-10 12:16:52.684 :: -3 :: C0A0:10 :: null :: 1 :: syntax_error_on_line:87:end: :: :: <html><table ><tr ><td valign='top'>Installation node:</td><td valign='top'>AnotherURCap</td></
tr></table><br/><p><b>Script Code</b></p><div style="padding-top:8px;padding-left:15px;padding-bottom:0px;padding-right:0px;"><p>Error position: line 87, column 1</p><pre>... ;; global MY_VARIABLE = 1.23456
;; ;; def myFunction(): ;; return floor((read_port_register(MY_VARIABLE_2)/MY_VARIABLE)+0.5)/10 ;; <b><font color=red>end</font></b> ;; def myFunction2(): ;; local speed = read_port_register(
MY_VARIABLE_3) ;; ... ;; </pre></div><br/><hr color=java.awt.Color[r=0,g=0,b=0]><br/><table ><tr ><td valign='top'>URCap name:</td><td valign='top'><b>SOMEOTHER URCAP</b></td></tr><tr ><td valign='top'>Version:</td><td
valign='top'><b>2.0.1</b></td></tr><tr ><td valign='top'>Developer:</td><td valign='top'><b>Some other company</b></td></tr><tr ><td valign='top'>Contact Info:</td><td valign='top'><b>Some other address</b></td></tr></table><br/></html>
3.5 :: 0063d00h46m20.851s :: 2024-06-10 12:16:52.698 :: -3 :: C0A0:10 :: null :: 1 :: compile_error_name_not_found:MY_VARIABLE_3: :: ::
3.5 :: 0063d00h46m20.851s :: 2024-06-10 12:16:52.705 :: -3 :: C0A0:10 :: null :: 1 :: compile_error_name_not_found:MY_VARIABLE_4: :: ::
3.5 :: 0063d00h46m20.851s :: 2024-06-10 12:16:52.711 :: -3 :: C0A0:10 :: null :: 1 :: syntax_error_on_line:1:def myFunction3(myParameter)\:: :: ::
...
Workaround Suggestion:
When instead splitting the string and writing line by line it works:
for (String line : script.split("\n")) {
writer.appendLine(line);
}
Robot Serial Number:
20195500846
Affected Version(s):
5.14.5
Is this something known or? I haven’t tested with any other script than the one I have and not on any other version of URs