Topic was automatically imported from the old Question2Answer platform.
Asked By
Gamemap
I want to decode the Art-Net protocol (Page 25) but have a problem with the OpCodes.
They should be like “0x5000” but I don’t know how I can get such a data from a PoolByteArray [65, 114, 116, 45, 78, 101, 116, 0, 0, 33, 192, 168, 0, 111, 54, 25, 0, ...] the first 8 values are in the ascii format and writes “Art-Net” with an null character (0x00 (but not shown)). I think the next two characters (0,33) have to build the number (or one from the other values on page 25-26).
If I forgot any details please write a comment.
I hope someone can help me.
If you want to get a from an poolbytearray do like for an array
var OPCodes = packet[9] # In reality it is two bytes, number 8 (0x00) & 9( 0x50)
print("OPCodes: %x" % OPCodes) # Use "%x" % to print ax hexadecimal
# OPCodes: 50
Here is an complete example. I don’t check Artnet version or univers. It is not really complex to do.
extends Node
const ARTNET_PORT = 6454
var artnetRX: PacketPeerUDP = PacketPeerUDP.new()
var DMX = []
# Set the PacketPeerUDP to listener the ARTNET_PORT (6454)
func _ready():
print("start")
if (artnetRX.listen(ARTNET_PORT) != OK):
print("Error listening to port: ", ARTNET_PORT)
else:
print("Listening to port: " , ARTNET_PORT)
# Check at each frame if received a udp ARTNET packet at ARTNET_PORT
# You can set physics process at 40 Hz or use _process()
func _physics_process(delta):
if artnetRX.get_available_packet_count() > 0:
var packet = artnetRX.get_packet()
print("Receive Artnet trame, len: ", packet.size())
# Should be 530, 18 bytes of Artnet identifier and 512 bytes of values.
var OPCodes = packet[9] # In reality it is two bytes,
#number 8 & 9
print("OPCodes: %x" % OPCodes) # Use "%x" % to print ax hexadecimal
DMX = packet.subarray(18,529) # See PoolByteArray class
print("CH1 = ", DMX[0],", CH2 = ", DMX[1],", CH7 = ", DMX[6],", CH8 = ", DMX[7])
# Here to get your values as an array.