Home AMX User Forum NetLinx Studio

Parsing Hex Responses

I'm working through my first module for a TOA 9000 series Mixer/Amp. I've setup a buffer in DEFINE_START to catch responses from the device.

Will each individual element in my CHAR array buffer be able to carry any HEX value from 00 to FF?

To illustrate this...let's say the device were to return 91H, 03H, 00H, FFH, 00H. Let's just say nothing else is in the buffer. Would it look like this?

MyBuffer[1] = $91
MyBuffer[2] = $03
MyBuffer[3] = $00
MyBuffer[4] = $FF
MyBuffer[5] = $00

Cheers,
Matthew

Comments

  • TurnipTruckTurnipTruck Posts: 1,485
    MyBuffer[1] = "$91"
    
    and you may say:
    If (MyBuffer[1]="$91")
      //Do Something
    
  • Joe HebertJoe Hebert Posts: 2,159
    Will each individual element in my CHAR array buffer be able to carry any HEX value from 00 to FF?
    Yes.
    To illustrate this...let's say the device were to return 91H, 03H, 00H, FFH, 00H. Let's just say nothing else is in the buffer. Would it look like this?

    MyBuffer[1] = $91
    MyBuffer[2] = $03
    MyBuffer[3] = $00
    MyBuffer[4] = $FF
    MyBuffer[5] = $00
    Yes.
  • travtrav Posts: 188
    I want to be a mongoose.
  • Thanks guys! I really appreciate the help.

    Cheers,
    Matthew
  • AMXJeffAMXJeff Posts: 450
    Parsing Help

    This is how I would parse this...
    DEFINE_DEVICE
    dvTOA = 5001:1:0
    DEFINE_VARIABLE
    
    CHAR cBuffer[255];
    CHAR cCMD;
    CHAR cDataLength;
    CHAR cData[100];
    
    
    DEFINE_FUNCTION ParseMessage(CHAR cCmd, CHAR cData[])
    {
    	SWITCH (cCmd)
    	{
    		// Channel Fader Gain (Position)
    		CASE $91:
    		{
    		}
    		// Channel Fader Gain (Step)
    		CASE $93:
    		{
    		}
    		// Crosspoint Gain
    		CASE $95:
    		{
    		}
    		// Preset Memory Recall
    		CASE $f1:
    		{
    		}
    	}
    }
    
    DEFINE_START
    
    CREATE_BUFFER dvTOA,cBuffer;
    
    DEFINE_EVENT
    
    DATA_EVENT[dvTOA]
    {
    	STRING:
    	{
    		// Buffer Trash Cleaning
    		// Just for Sanity sake, do not expect this code to run.
    		// FIRST BYTE IS NOT A COMMAND BYTE ($80 - $FF)
    		WHILE (LENGTH_STRING(cBuffer) > 0 && cBuffer[1] < $80)
    			GET_BUFFER_CHAR(cBuffer);
    			
    		// MAKE SURE WE STILL HAVE LENGTH
    		IF (LENGTH_STRING(cBuffer) > 1)
    		{
    			// GET COMMAND BYTE
    			cCMD = GET_BUFFER_CHAR(cBuffer);
    			
    			// GET LENGTH BYTE
    			cDataLength = GET_BUFFER_CHAR(cBuffer);
    			
    			// Check to make sure we have length
    			IF (cDataLength > 0 && LENGTH_STRING(cBuffer) >= cDataLength)
    			{
    				// Get the data
    				cData = GET_BUFFER_STRING(cBuffer, cDataLength);
    				
    				// Parse the message
    				ParseMessage(cCMD, cData);
    			}
    			// Not enough data, put humpty back together
    			ELSE
    			{
    				cBuffer = "cCMD, cDataLength, cBuffer";
    			}	
    		}
    	}
    }
    
  • That's perfect, Jeff! Thanks so much for your code. That just saved me oodles of time banging my head against a wall trying to figure out how to work the buffer!

    Thanks again!

    Cheers,
    Matthew
  • a_riot42a_riot42 Posts: 1,624
    It is easy to forget that even though it looks like you are packing three characters into one array element, $FF is still just a character, or an integer, however you decide to look at it.
    $41 <==> 65 <==> 'A' <==> 0100 0001
    Paul
  • Definitely. It is a bit of a shift for me to start working with Hex values. Even though I get what is going on from a representational perspective, I am just learning how that plays out when communicating back and forth with the device.

    Cheers,
    Matthew
Sign In or Register to comment.