0 votes

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.

in Engine by (219 points)

1 Answer

+1 vote
Best answer

Hi Gamemap!

If you want to debug your Artnet trame I recomand you to use Wireshark.

enter image description here

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

If you want to get all the 512 dmx values, use:

DMX = packet.subarray(18,529) # Packet.size() = 530 bytes

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():
    if (artnetRX.listen(ARTNET_PORT) != OK):
        print("Error listening to port: ", ARTNET_PORT)
        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.

This example will print:

Receive Artnet trame, len: 530
OPCodes: 50
CH1 = 255, CH2 = 255, CH7 = 255, CH8 = 0

Regards, Foreman21.

by (56 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.