Announcement

Collapse
No announcement yet.

This method crashes my chip every time

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • This method crashes my chip every time

    If I run this method nothing happens and my chip no longer communicates with Portal. I have to remove power and re-start for it to show up again


    I have tried running the method with test data from portal with the parameters

    "5118&5119&5120"
    "&"
    1

    Here is the code -- It is supposed to give you the string between two separators (5 and 6 for example) based on the parameter sepNum

    === I ATTACHED A SCREEN SHOT OF THE CODE SO YOU CAN SEE THE INDENTATION ====

    Notice my first line of code just prints out the parameters so I at least know I am entering the function and with what parameters the print statement never makes out the serial port nothing happens.

    def sepToken(string, separator, sepNum):
    # return string at specified num of 'seperators'
    print 'sepToken entered with ' + string + ' ' + separator + ' ' + str(sepNum) + '@'
    strlen=len(string)
    count = 0
    x=0
    begIndex = 3
    endIndex = 4
    while x<strlen:
    if string[x]==separator:
    if count == sepNum:
    begIndex = x

    elif count == sepNum + 1:
    endIndex = x

    else:
    count += 1

    else:
    x += 1

    print 'begIndex = ' + begIndex + ' ' + endIndex + '@'
    return string[begIndex:endIndex]



    Any help would be appreciated

  • #2
    found one flaw in my logic each of the if's and elif if count == sepNum must also increment count. One question if an if and an elif are true will both execute or only one will execute.

    Because now if I increment count in the first if it causes the second if to be correct I thought only one would execute I could reverse the order checked I think that should fix the problem.

    I re wrote the method trying to find the problem new method below

    def sepToken(string, separator, sepNum):
    # return string at specified num of 'seperators'
    print 'sepToken entered with ' + string + ' ' + separator + ' ' + str(sepNum) + '@'
    strlen=len(string)
    count = 0
    x=0
    begIndex = 3
    endIndex = 4

    while x < strlen:
    print 'count = ' + str(count) + '@'
    if string[x] == separator:
    if count == sepNum:
    print 'beg index = ' + str(x) + '@'
    count += 1
    elif count == sepNum + 1:
    print 'end index = ' + str(x) + '@'
    count += 1
    else:
    count += 1

    else:
    x += 1



    This just prints the index's to the serial port and I get some info but chip still crashes

    I know it's probably something stupid I just need it solved

    Thanks

    Comment


    • #3
      fixed the crashing wasn't incrementing x in the if's it doesn't crash now but the logic doesn't seem to be working. I kinda wish I could erase this but oh well
      Attached Files
      Last edited by mtalent; 11-28-2017, 06:04 PM. Reason: Added non crashing code

      Comment

      Working...
      X