Home AMX User Forum NetLinx Studio

Working around with HEX

Hi guys,

So I'm having some kind of a problem while working with HEX values.
I'm sure it's something that I'm doing wrong, and am not fully understanding how it works.

So I need to control a device thru HEX strings in RS-232.
I am able to control it, and actually have the device up and working already, but I need to do some changes and this implies to change the way that I made the main code.



So just as an introduction, in the following case I can send an HEX command that will work:


Working Scenario:
SEND_STRING Device, "$5E,$20,$00,$02,$02,$09,$01,$60,$93"

In the notifications tab I'll get:
Line 5 (12:19:17):: String To [5001:5:4]-[^ $00$02$02$09$01`$93]

(getting some of the Hex symbols being translated to ASCII, since the notifications read each Hex value individually)



Scenario 2: (doesn't work)

char command_Arm_Area1[] = "$5E,$20,$00,$02,$02,$09,$01,$60,$93"
...
SEND_STRING Device, command_Arm_Area1

In the notifications tab I'll get:
Line 3 (12:26:38):: String To [5001:5:4]-[$5E,$20,$00,$02,$02,$09,$01,$60,$93]
(The HEX symbols aren't getting translated to ASCII anymore, I suppose the String is being treated as whole String maybe?)



Scenario 3: (The way I need it working)

char command_Arm_Area1[] = "$5E,$20,$00,$02,$02,$09,$01,$60,$93"
char command_Arm_Area2[] = "$5E,$20,$00,$02,$02,$09,$02,$20,$92"
char command_Arm_Area3[] = "$5E,$20,$00,$02,$02,$09,$03,$E1,$52"
char command_Arm_Area4[] = "$5E,$20,$00,$02,$02,$09,$04,$A0,$90"
char command_Arm_Area5[] = "$5E,$20,$00,$02,$02,$09,$05,$61,$50"

CHAR aCommand_Arm_Area[5][] ={
{command_Arm_Area1},
{command_Arm_Area2},
{command_Arm_Area3},
{command_Arm_Area4},
{command_Arm_Area5}
}
...

send_string device, aCommand_Arm_Area[1]

In the notifications tab I'll get:
Line 13 (12:10:47):: String To [5001:5:4]-[$00]
(I completely don't understand where I'm going wrong here)

Comments

  • ericmedleyericmedley Posts: 4,177
    Prodigal wrote: »
    Hi
    Scenario 2: (doesn't work)

    char command_Arm_Area1[] = "$5E,$20,$00,$02,$02,$09,$01,$60,$93"

    If doing this in the define_var section put curly braces around the hex string. Also, I don't think the 'char' is needed. But, it shouldn't matter.
    char command_Arm_Area1[] = {"$5E,$20,$00,$02,$02,$09,$01,$60,$93"}

    Hope that helps.
  • ProdigalProdigal Posts: 90
    I added the curly braces but with no difference on the output.

    Here's how it is atm:

    DEFINE_CONSTANT
    char command_Arm_Area1[] = {"$5E,$20,$00,$02,$02,$09,$01,$60,$93"}
    char command_Arm_Area2[] = {"$5E,$20,$00,$02,$02,$09,$02,$20,$92"}
    char command_Arm_Area3[] = {"$5E,$20,$00,$02,$02,$09,$03,$E1,$52"}
    char command_Arm_Area4[] = {"$5E,$20,$00,$02,$02,$09,$04,$A0,$90"}
    char command_Arm_Area5[] = {"$5E,$20,$00,$02,$02,$09,$05,$61,$50"}

    CHAR aCommand_Arm_Area[15][] ={
    {command_Arm_Area1},
    {command_Arm_Area2},
    {command_Arm_Area3},
    {command_Arm_Area4},
    {command_Arm_Area5}
    }



    Tests:

    1- SEND_STRING Device, acommand_Arm_Area[1]
    Notifications:
    Line 3 (14:34:42):: String To [5001:5:4]-[$00]


    2- SEND_STRING Device, command_Arm_Area1
    Notifications:
    Line 5 (14:34:42):: String To [5001:5:4]-[$5E,$20,$00,$02,$02,$09,$01,$60,$93]


    3- SEND_STRING Device, "$5E,$20,$00,$02,$02,$09,$01,$60,$93"
    Notifications:
    Line 4 (14:34:42):: String To [5001:5:4]-[^ $00$02$02$09$01`$93]


    I get the same results, meaning that only the output of test #3 works. But I would need the #1 test working, since I need to output the strings being chosen out of an Array.
    The strings are defined inside define_constant section.

    Indeed you are right it's not actually needed. I'm just using Char just for my own logic.
  • viningvining Posts: 4,368
    I think you need to loose the double quotes. This is how I've been doing this:
    DEFINE_CONSTANT //TELNET COMMANDS  (NOT CISCO COMMANDS BUT SESSION STUFF!)    "$FF$FB$01$FF$FB$03$FF$FD$18$FF$FD$1F" 
    
    CHAR TELNET_IAC[1]    		= {$FF}				   
    CHAR TELNET_NEG_RX[12]    	= {$FF,$FB,$01,$FF,$FB,$03,$FF,$FD,$18,$FF,$FD,$1F}
    CHAR TELNET_NEG_RESPONSE[12]   	= {$FF,$FE,$01,$FF,$FC,$03,$FF,$FC,$18,$FF,$FC,$1F}
    CHAR TELNET_DONT_ECHO[3]   	= {$FF,$FE,$01}
    CHAR TELNET_WONT_ECHO[3]	= {$FF,$FC,$01}
    CHAR TELNET_END_SUBNEG[2]   	= {$FF,$F0}
    CHAR TELNET_DO_SUPP_GOAHEAD[3]  = {$FF,$FD,$03}
    CHAR TELNET_WILL_TERMTYPE[3]    = {$FF,$FB,$18}
    CHAR TELNET_WONT_WINDSIZE[3]    = {$FF,$FC,$1F}
    

    I think the double quotes concantenate the individual HEX values into a single string value.
  • ProdigalProdigal Posts: 90
    You were right Vining, thank you.

    The double quotes actually concatenated the individual Hex Values in to 1 String value.
    This partially solves my enigma, but it still doesn't work.

    Here goes the results:


    DEFINE_CONSTANT
    char command_Arm_Area1[] = {$5E,$20,$00,$02,$02,$09,$01,$60,$93}
    char command_Arm_Area2[] = {$5E,$20,$00,$02,$02,$09,$02,$20,$92}
    char command_Arm_Area3[] = {$5E,$20,$00,$02,$02,$09,$03,$E1,$52}
    char command_Arm_Area4[] = {$5E,$20,$00,$02,$02,$09,$04,$A0,$90}
    char command_Arm_Area5[] = {$5E,$20,$00,$02,$02,$09,$05,$61,$50}

    CHAR aCommand_Arm_Area[5][] ={
    {command_Arm_Area1},
    {command_Arm_Area2},
    {command_Arm_Area3},
    {command_Arm_Area4},
    {command_Arm_Area5}
    }



    Tests:

    1- SEND_STRING Device, aCommand_Arm_Area[1]
    Notifications:
    Line 19 (15:46:20):: String To [5001:5:4]-[$00]



    2- SEND_STRING Device, command_Arm_Area1
    Notifications:
    Line 41 (15:46:49):: String To [5001:5:4]-[^ $00$02$02$09$01`$93]



    3- SEND_STRING Device, "$5E,$20,$00,$02,$02,$09,$01,$60,$93"
    Notifications:
    Line 72 (15:47:28):: String To [5001:5:4]-[^ $00$02$02$09$01`$93]


    So taking the double quotes out fixes the problem on sending the Hex values thru a constant array, however, I still can't send this constant array values, when calling it from the double dimension array.
    Can't really figure out why.
  • DHawthorneDHawthorne Posts: 4,584
    Prodigal wrote: »
    So taking the double quotes out fixes the problem on sending the Hex values thru a constant array, however, I still can't send this constant array values, when calling it from the double dimension array.
    Can't really figure out why.

    Put a dimension on the second level of the array. I don't know why, but the compiler doesn't seem to recognize strings on a multi-dimensional array unless the dimension that actually holds the string has a value, not depending on the initialization.
  • AMXJeffAMXJeff Posts: 450
    Prodigal wrote: »
    You were right Vining, thank you.

    The double quotes actually concatenated the individual Hex Values in to 1 String value.
    This partially solves my enigma, but it still doesn't work.

    Here goes the results:


    DEFINE_CONSTANT
    char command_Arm_Area1[] = {"$5E,$20,$00,$02,$02,$09,$01,$60,$93"}
    char command_Arm_Area2[] = {"$5E,$20,$00,$02,$02,$09,$02,$20,$92"}
    char command_Arm_Area3[] = {"$5E,$20,$00,$02,$02,$09,$03,$E1,$52"}
    char command_Arm_Area4[] = {"$5E,$20,$00,$02,$02,$09,$04,$A0,$90"}
    char command_Arm_Area5[] = {"$5E,$20,$00,$02,$02,$09,$05,$61,$50"}

    CHAR aCommand_Arm_Area[5][] ={
    {command_Arm_Area1},
    {command_Arm_Area2},
    {command_Arm_Area3},
    {command_Arm_Area4},
    {command_Arm_Area5}
    }



    Tests:

    1- SEND_STRING Device, aCommand_Arm_Area[1]
    Notifications:
    Line 19 (15:46:20):: String To [5001:5:4]-[$00]



    2- SEND_STRING Device, command_Arm_Area1
    Notifications:
    Line 41 (15:46:49):: String To [5001:5:4]-[^ $00$02$02$09$01`$93]



    3- SEND_STRING Device, "$5E,$20,$00,$02,$02,$09,$01,$60,$93"
    Notifications:
    Line 72 (15:47:28):: String To [5001:5:4]-[^ $00$02$02$09$01`$93]


    So taking the double quotes out fixes the problem on sending the Hex values thru a constant array, however, I still can't send this constant array values, when calling it from the double dimension array.
    Can't really figure out why.

    This works...
    DEFINE_CONSTANT
    
    CHAR aCommand_Arm_Area[5][10] =
    { 
    	{$5E,$20,$00,$02,$02,$09,$01,$60,$93},
    	{$5E,$20,$00,$02,$02,$09,$02,$20,$92},
    	{$5E,$20,$00,$02,$02,$09,$03,$E1,$52},
    	{$5E,$20,$00,$02,$02,$09,$04,$A0,$90},
    	{$5E,$20,$00,$02,$02,$09,$05,$61,$50}
    }
    
  • ProdigalProdigal Posts: 90
    Thank you people, it ended up working like this:

    DEFINE_CONSTANT

    CHAR aCommand_Arm_Area[5][9] =
    {
    {$5E,$20,$00,$02,$02,$09,$01,$60,$93},
    {$5E,$20,$00,$02,$02,$09,$02,$20,$92},
    {$5E,$20,$00,$02,$02,$09,$03,$E1,$52},
    {$5E,$20,$00,$02,$02,$09,$04,$A0,$90},
    {$5E,$20,$00,$02,$02,$09,$05,$61,$50}
    }


    @DHawthorne
    Putting the dimension on the second level didn't fixed the situation, if I kept having the Constants inside the Array.
    Need to put the HEX values directly inside the double dimension array and put the actual dimension on both the brackets or else it doesn't like it.

    Thanks!
  • ericmedleyericmedley Posts: 4,177
    ericmedley wrote: »
    If doing this in the define_var section put curly braces around the hex string. Also, I don't think the 'char' is needed. But, it shouldn't matter.
    char command_Arm_Area1[] = {"$5E,$20,$00,$02,$02,$09,$01,$60,$93"}

    Hope that helps.

    I didn't see DEFINE_Constatnt in your original post. sorry about that.
  • ProdigalProdigal Posts: 90
    ericmedley wrote: »
    I didn't see DEFINE_Constatnt in your original post. sorry about that.

    I didn't see it, cause I failed on pointing that out.

    Thanks for the help!
Sign In or Register to comment.