This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C167 reading/scanning input from GSM module from RS232

Hello,
I am a novice in C language and have been trying to find a method of reading/scanning input from GSM, then comparing it against a text (e.g OK or ERROR). Then if true set a break.

I have tried scanf with no avail. I have also tried reading string which works but am unsure how to compare with my text.Has anyone any advice with what function would be useful?

Any replies greatly appreciated.

Andy

Parents Reply Children
  • Interfacing to GSM can be a pain. You may find the code below useful - I certainly did - it is a string compare function with a limited wildcard facility.

    /*****************************************************************************
     *
     *  String Compare
     *
     *  Trigger:    Local call.
     *
     *  Input:      Pointers to the 'expected' and 'search' strings.
     *
     *  Output:     Returns TRUE to indicate a match and FALSE otherwise.
     *
     *  Function:   Compares two strings and returns TRUE if identical.
     *
     *  Notes:      Allows the use of character (?) and string (~) wildcards in
     *              the specification of the expected string.
     *
     *              THE ORDER OF EXPECTED AND ACTUAL POINTERS IS IMPORTANT
     *              WHEN THE WILDCARDS ARE USED.
     *
     *              THE EXPECTED STRING MUST BE IN CODE MEMORY AND THE
     *              ACTUAL STRING MUST BE IN XDATA.
     *
     *****************************************************************************/
    
    bit user_strcmp(unsigned char code *er, unsigned char xdata *ar) large
    {                                                   // ar = actual_string
                                                        // er = expected_string
        bit    match = TRUE;                            //
                                                        //
        do                                              // String compare loop
        {                                               //
            if( *er == '?' )                            // If a character wildcard is
            {                                           // in the expected string:
                er++;                                   // don't test this actual char
            }                                           //
            else if( *er == '~' )                       // If a string wildcard:
            {                                           //
                er++;                                   // Start the inner loop
                                                        // looking for the next
                                                        // char after the ~.
                while( (*ar != *er ) && ( *ar != '\0')) // Inner loop searches
                {                                       // through the actual string
                                                        // until either a match with
                                                        // the char after the expected
                    ar++;                               // or the end of the actual
                }                                       // string.
                                                        //
                                                        // If the loop terminated due
                                                        // to the actual \0 char
                if( *er != *ar )                        // but we were expecting
                {                                       // something else
                    match = FALSE;                      // we need to test again to
                }                                       // catch this condition.
                if( *er != '\0' )                       //
                {                                       //
                    er++;                               //
                }                                       //
            }                                           //
            else                                        // Normal test (No wildcard)
            {                                           //
                if( *er != *ar )                        //
                {                                       //
                    match = FALSE;                      //
                }                                       //
                if( *er != '\0' )                       //
                {                                       //
                    er++;                               //
                }                                       //
            }                                           //
        }                                               //
        while( ( *ar++ != '\0') && (match) );           //
                                                        //
        if( *er != '\0' )                               //
        {                                               //
            match = FALSE;                              //
        }                                               //
                                                        //
        return( match );                                //
    }                                                   //
    
    

  • "You may find the code below useful ...

    Input:      Pointers to the 'expected' and 'search' strings."

    But his previous post demonstrates a fundamental problem in his understanding of strings & pointers (and other aspects of the 'C' programming language) - that needs t be addressed before this code can be of any use!