ecujak
February 4, 2020, 8:29pm
1
If I read a value from OPC into newValue I get array(java.lang.Long, [1L])
oldQualifiedValue = system.opc.readValue(server, path)
newValue = oldQualifiedValue.getValue()
print str(newValue) gives me array(java.lang.Long, [1L])
someNumber = 1
myValue = []
myValue.append(long(someNumber))
print str(myValue) gives me [1L]
How do initialize myLongArray as array(java.lang.Long, [myLongValue])
It is poorly documented, but you need jython’s jarray module . Keep in mind that java arrays are not appendable–the jarray module lets you turn a list into a fixed-length java array.
2 Likes
FWIW, Jython is really good at auto-converting lists into java arrays for methods when its signature is unambiguous. That’s why jarray is rarely needed.
1 Like
ecujak
February 5, 2020, 3:09pm
4
The jarray module exports two functions:
array(sequence, type)
zeros(length, type)
What readValue returned was array(type, sequence)
Also, how do I use this in the ignition scripting. I get the exception array not defined.
import jarray
arrayOfBytes = jarray.array([1,2,5,8,9,10], 'b')
print repr(arrayOfBytes)
3 Likes
This seems to be what I need too.
I have a base64 string that I decoded:
message_bytes = base64.b64decode(base64_str)
And made into a bytearray:
bytes_array = list(bytearray(message_bytes))
And then I wish to make it into a Java bytes array:
jarray_version = jarray.array(bytes_array, "b")
However I get error:
OverflowError: value too large for byte
Do you know how to avoid this? Or an alternative way to turn bse64 str into Java byte array
from com.inductiveautomation.ignition.common import Base64
bytes = Base64.decode(string)
No muss, no fuss.
2 Likes