When I try to use the following block copied from the forum I get an error:
"Cannot cast type: {Type=Byte,Rank=1,RemoteObject=True} to: {Type=Object,Rank=1, RemoteObject=True}"
Given that astream is probably an AsyncStreams and thus probably sending bytes over a communication channel, perhaps this is where you were headed:
B4X:
'''astream.write(ser.ConvertArrayToBytes(Array(0x55,0x1A,0x00,0x91)))
astream.Write(Array As Byte(0x55, 0x1A, 0x00, 0x91))
The .Write2 method lets you send part of the array, rather than all of it. This is useful when you have a fixed size buffer for constructing packets to send, and the packet is smaller than the buffer, eg:
B4X:
'global vars
Dim TxBuffer(100) As Byte
Dim TxLength As UInt = 0
Sub AddTx(B As Byte)
If TxLength < TxBuffer.Length Then
TxBuffer(TxLength) = B
TxLength = TxLength + 1
End If
End Sub
AddTx(0x55) 'U
AddTx(0x1A) 'Ctrl+Z aka EOF (?)
AddTx(0x00)
AddTx(0x91) 'a
astream.Write2(TxBuffer, 0, TxLength) 'only writes 4 byte packet, not the entire 100 byte array
TxLength = 0 'clear buffer for next packet