Home AMX User Forum NetLinx Studio

"LENGTH' keyword

Hello everyone,

I made some tests on my office - using my old NI-700 - before being on site. I need to control a BSS device so I'm checking out the related module from the web site ( HPro_BSS_Gateway_v1_0_12_dr1_0_0 ).

On this module, there are "char" constants where the code checks out their length using the "length_string" or "length_array" keyword. During my tests, I realized that something is going wrong with that.

I noticed that the returned value of a "char" constant length, is 43009 !!

For example :

DEFINE_CONSTANT

   char CMD_FB_SMX_PREFIX[ ] = 'FB_SMX_';

The "length_string(CMD_FB_SMX_PREFIX)" or "length_array(CMD_FB_SMX_PREFIX)" returns a value of 43009 while the
"max_length_string(CMD_FB_SMX_PREFIX)" or "max_length_array(CMD_FB_SMX_PREFIX)" returns a value of 0.

If I define the above as a variable :

DEFINE_VARIABLE

volatile char CMD_FB_SMX_PREFIX[ ] = 'FB_SMX_';

The "length_string(CMD_FB_SMX_PREFIX)" or "length_array(CMD_FB_SMX_PREFIX)" or
"max_length_string(CMD_FB_SMX_PREFIX)" or "max_length_array(CMD_FB_SMX_PREFIX)" returns a value of 7 which is the correct.

Again, some of the "HPro_BSS_Gateway_v1_0_12_dr1_0_0 " files, are using the above as CONSTANTS and it is supposed working. But I don't know which master AMX programmers has tested it with.

Does this have to do with the master that the code has been uploaded to ?
Does a new NX master handle "LENGTH" keywords in different way than an older master ?

Thanks,
George

Comments

  • Did a quick test on a NX with the latest firmware:

     DEFINE_CONSTANT
    
     char string1[] = 'abc123'
    
     DEFINE_VARIABLE
    
     char string2[] = 'def456'
    
     DEFINE_START
    
     wait 200
     {
         SEND_STRING 0, "'length string1 :', ITOA(LENGTH_STRING(string1))"  
         SEND_STRING 0, "'max length string1 :',ITOA(MAX_LENGTH_STRING(string1))"
    
         SEND_STRING 0, "'length string2 :', ITOA(LENGTH_STRING(string2))"
         SEND_STRING 0, "'max length string2 :',ITOA(MAX_LENGTH_STRING(string2))"
     }
    

    result:

    Line 4 2020-07-12 (22:06:01.580):: length string1 :687865856
    Line 5 2020-07-12 (22:06:01.586):: max length string1 :0
    Line 6 2020-07-12 (22:06:01.587):: length string2 :6
    Line 7 2020-07-12 (22:06:01.587):: max length string2 :6

  • John NagyJohn Nagy Posts: 1,734

    String1=red pill
    String2=blue pill
    whoa

  • Joe HebertJoe Hebert Posts: 2,159
    DEFINE_CONSTANT
    
    char string1[] = {'r','e','d',' ','p','i','l','l'}
    
    DEFINE_VARIABLE
    
    char string2[] = 'blue pill'
    
    DEFINE_START
    
    wait 200
    {
         SEND_STRING 0, "'length string1 :', ITOA(LENGTH_STRING(string1))"  
         SEND_STRING 0, "'max length string1 :',ITOA(MAX_LENGTH_STRING(string1))"
    
         SEND_STRING 0, "'length string2 :', ITOA(LENGTH_STRING(string2))"
         SEND_STRING 0, "'max length string2 :',ITOA(MAX_LENGTH_STRING(string2))"
    
    }
    

    result:

    Line 33 2020-07-12 (17:37:03):: length string1 :8
    Line 35 2020-07-12 (17:37:03):: max length string1 :8
    Line 36 2020-07-12 (17:37:03):: length string2 :9
    Line 37 2020-07-12 (17:37:03):: max length string2 :9

  • So, Still gotta ask..

    I would say the behaviour of the compiler is wrong here or did anyone expect this?

  • Joe HebertJoe Hebert Posts: 2,159

    The compiler is not wrong, it's just the way it is. You have to take the red pill and face the unpleasant truth.

    Constant char arrays have been this way in Netlinx for as long as I can remember. It might have been the same way in Access as well but those memory brain cells have died off long ago so I can't say for sure.

    Tech note 531 explains it. - How to Initialize Character Strings in the DEFINE_CONSTANT and DEFINE_VARIABLE Sections.

    Unfortunately Tech Notes are still MIA so I can't paste a link to it but I can point you to just a couple of threads from the Wayback Machine where it's discussed.

    https://proforums.harman.com/amx/discussion/9481/questions-about-char-arrays-as-constants

    https://proforums.harman.com/amx/discussion/9623/send-string-issue

    HTH

  • That's kinda funny. I just looked at some 50 projects I did and I never initialized character arrays in the define_constant section. But I don't think it was because of this. But maybe it was. My memory cells aren't what they used to be either... :)

    You can access the technotes at:

    https://trade.amx.com/legacy/techsupport/

  • Joe HebertJoe Hebert Posts: 2,159

    Cool, thanks for the tech notes link. Didn't know they were back.

  • @Joe Hebert said:
    Cool, thanks for the tech notes link. Didn't know they were back.

    Not back per say, but at least there is a path. The replacement will be https://help.harmanpro.com/ - unsure if that is open to the public just yet.

  • Joe HebertJoe Hebert Posts: 2,159

    Thanks @HARMAN_Chris

Sign In or Register to comment.