Home AMX User Forum AMX General Discussion

SEND_STRING issue

Alright, so I do AMX from time to time, and this time it was after really really long break, had an issu about this:
DEFINE_CONSTANT
CHAR MitsubishiON232[] =  "'00vP 1',$0D" 
// ...
// And after some code
SEND_STRING dvVidWall232, MitsubishiON232
doesn't work. But this:
SEND_STRING dvVidWall232, "'00vP 1',$0D" 
works just fine. Unfortunatelly I didn't screencap the notification messages, but strings sent to device were the same. The result is totally different though. Point me where I'm wrong here please

Comments

  • Joe HebertJoe Hebert Posts: 2,159
    ubernyako wrote: »
    I didn't screencap the notification messages, but strings sent to device were the same. The result is totally different though.

    Take a closer look at the Notifications and you’ll see that the strings sent to the device were not the same.

    You’re first example:
    Line 1 (05:14:02):: String To [5001:1:111]-

    You’re second example
    Line 3 (05:14:02):: String To [5001:1:111]-[00vP 1$0D]

    Drop you constant into debug and you’ll see that it has a length of 12 and not the 7 characters you are expecting.
  • DHawthorneDHawthorne Posts: 4,584
    NetLinx does some strange things when handling strings ... they don't have an actual string variable type, it's a char array, but some, and only some, of their functions treat it like a string, and some like an array.

    Try this:

    SEND_STRING dvVidWall232, "MitsubishiON232"

    Putting quotes around your variable tells the command explicitly that it's a string, and will be handled that way in terms of glyph translation, etc. I think what's happening is without the quotes it's handling the imbedded ' marks as literal characters, not as 'whatever is inside these is ASCII'.
  • Joe HebertJoe Hebert Posts: 2,159
    If you change this:
    CHAR MitsubishiON232[] = "'00vP 1',$0D"

    To this:
    CHAR MitsubishiON232[] = {'0','0','v','P',' ','1',$0D}

    it will work the way you intended.
  • HedbergHedberg Posts: 671
    The basic problem is that he's trying to define a constant using a string expression. Look at this:
    DEFINE_CONSTANT
    CHAR MitsubishiON232[] =  "'00vP 1',$0D" 
    

    the RHS of the declaration/definition IS NOT a constant, it's a string expression. Apparently, the compiler interprets everything inside the double quotes as a string literal.
  • Joe HebertJoe Hebert Posts: 2,159
    Tech Note 531

    How to Initialize Character Strings in the DEFINE_CONSTANT and DEFINE_VARIABLE Sections

    http://amx.com/techsupport/techNote.asp?id=531
  • viningvining Posts: 4,368
    If you're a dumb a$$ like me it might be helpful to create another DEFINE_CONSTANT section before all the other CONSTANT sections ( if you're into multiples too) and place a commented out version of the technote in it. Despite how many times I do these I always find myself going back to a previously written sections of code to see how I did it last time.

    This post reminded me that I always struggle with this question so I just added it to my current system and it will become part of all future systems like I do with this:
    PROGRAM_NAME= 'VAV_Xxxxxxxxxx'
    DEFINE_DEVICE   //#WARN 'TELNET MASTER & set udp bc rate 0'.......ETC.......
    
    #WARN 'TELNET MASTER & set udp bc rate 0'
    #WARN 'TELNET MASTER & set zeroconf disable'
    #WARN 'TELNET MASTER & set duet memory 18m'
    #WARN 'TELNET MASTER & set ssh port 0'
    #WARN 'TELNET MASTER & set ethernet mode 10 full'
    
    in all systems. The more reminders for me the better!

    Folded & Unfolded screenshots....
Sign In or Register to comment.