TCP Driver Expected ByteString Error

Hello!

Trying to use the TCP driver to talk to a machine.

Currently getting a "Expected ByteString, received xxx" error message when writing to the /WritableBytes field.

The tag is written to via script, see below:

test = chr(2) + 'CurrentStats?' + chr(3) + chr(207)
values = [ord(i) for i in test]
tagPath = '[Test]zzLP_TESTING/SG01/Data/WriteableBytes' #writes to /Writable no 'e'
system.tag.writeBlocking([tagPath], [values])

Pasted image 20241206144548

I have tried several different ways of specifying value:

value = b'\x02\x43\x75\x72\x72\x65\x6E\x74\x53\x74\x61\x74\x73\x3F\x03\xCF'
value = b'\x02CurrentStats?\x03\xcf'
value = [2, 67, 117, 114, 114, 101, 110, 116, 83, 116, 97, 116, 115, 63, 3, 207]
value = array('b', [2, 67, 117, 114, 114, 101, 110, 116, 83, 116, 97, 116, 115, 63, 3, -49])

but each gives me the same error message "Expected ByteStream...".

Any hints on the right way to specify?

Thank you kindly!

I have used this code before to convert a python array into a byte stream.
I have added your values there into the value variable, maybe this could work?
Hard to test without your system.
I was using it for image data coming via various sources.

value = array('b', [2, 67, 117, 114, 114, 101, 110, 116, 83, 116, 97, 116, 115, 63, 3, -49])
imageBytes = ''.join(map(lambda x: chr(x % 256), value)) #convert the image to a stream of bytes

Use the java.io.ByteArrayOutputStream to create the ByteStream

from java.io import DataOutputStream, ByteArrayOutputStream
output = ByteArrayOutputStream()
outputStream = DataOutputStream(output)
outputStream.writeBytes(chr(2) + 'CurrentStats?' + chr(3) + chr(207))
output.toByteArray()

Output:

>>> 
array('b', [2, 67, 117, 114, 114, 101, 110, 116, 83, 116, 97, 116, 115, 63, 3, -49])
>>>

I belive if you just do something like:

system.tag.writeBlocking(['[Test]zzLP_TESTING/SG01/Data/WriteableBytes'],[output])

It will work, but I don't have anything to test that with.

1 Like

Thanks for the ideas. Tried:

from org.python.core.util import StringUtil

test = chr(2) + 'CurrentStats?' + chr(3) + chr(207)
values = [ord(i) for i in test]

imageBytes_1 = ''.join(map(lambda x: chr(x % 256), values))
imageBytes_1

system.tag.writeBlocking(['[Test]zzLP_TESTING/BN07/Data/WriteableBytes'],[imageBytes_1])

valueArray = StringUtil.toBytes(test)
imageBytes_2 = ''.join(map(lambda x: chr(x % 256), valueArray))
imageBytes_2

system.tag.writeBlocking(['[Test]zzLP_TESTING/BN07/Data/WriteableBytes'],[imageBytes_2])
>>> 
'\x02CurrentStats?\x03\xcf'
[Bad]
'\x02CurrentStats?\x03\xcf'

And in the driver logs:
image

And for reference:

Thanks for the ideas - looks promising with the right type conversion but I get a

java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Error serializing parameters.

Error message when attempting the writeBlocking

Code:

from java.io import DataOutputStream, ByteArrayOutputStream
output = ByteArrayOutputStream()
outputStream = DataOutputStream(output)
outputStream.writeBytes(chr(2) + 'CurrentStats?' + chr(3) + chr(207))
output.toByteArray()

type(output)
output

system.tag.writeBlocking(['[Test]zzLP_TESTING/BN07/Data/WriteableBytes'],[output])

Output:

array('b', [2, 67, 117, 114, 114, 101, 110, 116, 83, 116, 97, 116, 115, 63, 3, -49])
<type 'java.io.ByteArrayOutputStream'>
CurrentStats?Ï
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 67, in <module>
	at java.base/java.util.concurrent.CompletableFuture.reportGet(Unknown Source)

	at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source)

	at com.inductiveautomation.ignition.client.script.ClientTagUtilities.writeBlockingImpl(ClientTagUtilities.java:200)

	at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.writeBlocking(AbstractTagUtilities.java:547)

	at jdk.internal.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Error serializing parameters.


	at org.python.core.Py.JavaError(Py.java:545)

	at com.inductiveautomation.ignition.client.script.ClientTagUtilities.writeBlockingImpl(ClientTagUtilities.java:206)

	at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.writeBlocking(AbstractTagUtilities.java:547)

	at jdk.internal.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)

	at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:553)

	at org.python.core.PyObject.__call__(PyObject.java:477)

	at org.python.core.PyObject.__call__(PyObject.java:481)

	at org.python.pycode._pyx173.f$0(<input>:67)

	at org.python.pycode._pyx173.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:173)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1703)

	at org.python.core.Py.exec(Py.java:1747)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:628)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:616)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

Caused by: java.util.concurrent.ExecutionException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Error serializing parameters.

	at java.base/java.util.concurrent.CompletableFuture.reportGet(Unknown Source)

	at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source)

	at com.inductiveautomation.ignition.client.script.ClientTagUtilities.writeBlockingImpl(ClientTagUtilities.java:200)

	... 24 more

Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Error serializing parameters.

	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:360)

	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.invoke(GatewayInterface.java:965)

	at com.inductiveautomation.ignition.client.tags.impl.GatewayTagInterface$GatewayProviderProxy.lambda$writeAsync$1(GatewayTagInterface.java:358)

	at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(Unknown Source)

	at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(Unknown Source)

	at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)

	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)

	at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)

	at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)

Caused by: java.io.NotSerializableException: java.io.ByteArrayOutputStream

	at java.base/java.io.ObjectOutputStream.writeObject0(Unknown Source)

	at java.base/java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)

	at java.base/java.io.ObjectOutputStream.writeSerialData(Unknown Source)

	at java.base/java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)

	at java.base/java.io.ObjectOutputStream.writeObject0(Unknown Source)

	at java.base/java.io.ObjectOutputStream.writeObject(Unknown Source)

	at java.base/java.util.ArrayList.writeObject(Unknown Source)

	at java.base/jdk.internal.reflect.GeneratedMethodAccessor34.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

	at java.base/java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)

	at java.base/java.io.ObjectOutputStream.writeSerialData(Unknown Source)

	at java.base/java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)

	at java.base/java.io.ObjectOutputStream.writeObject0(Unknown Source)

	at java.base/java.io.ObjectOutputStream.writeObject(Unknown Source)

	at com.inductiveautomation.ignition.common.Base64.encodeObject(Base64.java:496)

	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface$InvokeMessage.setArgs(GatewayInterface.java:1382)

	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.invoke(GatewayInterface.java:963)

	... 8 more

Traceback (most recent call last):
  File "<input>", line 67, in <module>
	at java.base/java.util.concurrent.CompletableFuture.reportGet(Unknown Source)

	at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source)

	at com.inductiveautomation.ignition.client.script.ClientTagUtilities.writeBlockingImpl(ClientTagUtilities.java:200)

	at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.writeBlocking(AbstractTagUtilities.java:547)

	at jdk.internal.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Error serializing parameters.

Update: the data type of WritableBytes needed to be updated to be Short Array

The datatype is OPC UA ByteString, which is basically equivalent to an array of unsigned bytes.

Ignition's tag system doesn't have unsigned types (nor does Java natively... :sob: ), so it's always a sized up signed type instead. When you write short array to a ByteString tag there's some logic in our OPC UA client layer to handle that conversion.

1 Like