Jump to content
Sign in to follow this  
dhazelman

C Function to convert string to upper case

Recommended Posts

Trying to create C function to convert a String ASCII to upper case.

This is what I tried and it does not work:

static void PrefixToUpper(volatile char* Prefix, int PrefixLen)
{
    // User code starts below this comment
    for (int i  = 0; Prefix[i] != '\0' ; i++)
        {
        if(Prefix[i] >= 'a' && Prefix[i] <= 'z')
                {
                    Prefix[i] = Prefix[i] - 32;
                }
        }
    // User code ends above this comment
}

// User code starts below this comment

Tested the code in C compiler and it runs correctly:

static void PrefixToUpper(volatile char* Prefix)
{
    // User code starts below this comment
    for (int i  = 0; Prefix != '\0' ; i++)
        {
        if(Prefix >= 'a' && Prefix <= 'z')
                {
                    Prefix = Prefix - 32;
                }
        }
    // User code ends above this comment
}

int main() 
   {
   char str[] = "hmh00234";
    
   printf("String input: %s\n", str);
   PrefixToUpper(str);
   printf("String output: %s\n", str);
   }
 

 

Share this post


Link to post
Share on other sites

I tested your code, in a c function downloaded to the PLC, and it works.  Can you send your sample project, or at least a screen capture of the ladder call to that function?

Share this post


Link to post
Share on other sites

image.thumb.png.37262b1ba609ca28c1e1dbcf83d08d71.png

 

image.png.71c1e286043b0ff2272e734cbd48b4c1.png

image.png.4d03edd4c43f994e0f870589b0c4b642.png

image.png.909299c9a652b9e5c3a2745b352f8611.png

 

The ladder logic was working with out the PrefixToUpper call, just would fail the table lookup if the user entered lower case prefix. The table has all the prefixes stored as upper case.

Share this post


Link to post
Share on other sites

OK, if you are sure that the ladder code that you've shown me is being executed, then I have no idea why it doesn't work.

I could debug it better if I had the project.

You can also debug it by putting in increment after the PrefixToUpper, so you can see with Online debug (or with HMI element) that the number is being incremented (and it should increment only once). You can also store Prefix Tractor Serial No into another string tag, so you could see its value after the function was called.

 

Share this post


Link to post
Share on other sites

Dear dhazelman

the position "D" in the UDFB "find DTI colum value" is the starting row of the column where to search...and the position "E" is how many rows must be checked...you setted this last as "0".

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...