Home AMX User Forum AMX Technical Discussion
Options

Help with string parsing

Using NetLinx I have a buffer set up to receive ASCII strings for activating events. The buffer and the process works fine. I need to know how to take in a number in ASCII form and convert it to a form that can be used to pulse an IR device. I have tried ATOI, ATOL, ATOF, etc.

For example if I have a "5" come into the buffer, I would like to PULSE[dvCD,5].

I have tried int_number = ATOI (incomming_buffer) PULSE [dvCD,int_number] and every other variation you can think of. It will not pulse that channel. **Yes I have used LEFT_STRING to grab just the 5 and not the carriage return. I can send the 5 or whatever number to a label on the touchpanel, so I know it is coming through fine.

Please try it prior to responding to see if your idea works.

Any help would be GREATLY appreciated.

Scott

Comments

  • Options
    HedbergHedberg Posts: 671
    ATOI is your friend and it will work.

    Try this:

    pulse[dvCD,5]

    if that works, so will this:

    pulse[dvCD,ATOI('5')]

    You should see a report in your device notifications in either case.

    Also, ATOI requires a string as an argument and not just a single character. This can be tricky, but if you enclose your argument in double quotes, it will be a string. So try:

    pulse[dvCD,ATOI("incoming_buffer")]

    the difference between a string with just one character in it and a single character variable is not always obvious. It's confusing. This problem appears going the other way too. get_buffer_character() returns a single character and if you try to assign the return value to a string, it won't work. If you search the forum for 'atoi' or 'get_buffer_char' you will see that this is not an uncommon problem.

    If the string/character conundrum is not causing your problem, check to make sure that the IR port has something loaded for channel 5. The port light won't light if the channel you're aiming at is empty.
  • Options
    DHawthorneDHawthorne Posts: 4,584
    It's also worth noting that ATOI will happily ignore any CR or whitespace (unless they are between numbers, in which case it just stops on them), you don't have to worry about stripping them. It will find the first character it can interpret as a number, and go right up until the next character it can't interpret as a number, and build your number from that. So, ATOI("'I am thinking of the number 533 and 2 left over'") will return 533. ATOI("'53', <CRLF>, '3'") will return 53.
  • Options
    ericmedleyericmedley Posts: 4,177
    Perhaps you could post the hunk of code in question. I'd be willing to bet that your premise is just fine. But somewhere else in the routine the value is getting horsed up. That might help us help you.
    eric
Sign In or Register to comment.