Hello Guys,
Some time ago I wrote an ASCII protocol in C++ on a master PC which is sending a char string to a partner PC. The string contains a lot a formatted integer and floating point values.
A part of the code:
static char outStr[256] , TotalStr[256]
// Declaration of a 256 char String
sprintf(outStr,"%04d%02d%02d\t%02d%02d%02d\t%d\t", wYear, wMonth, wDay, wHour, wMinute, wSecond, StateValue);
// variable outStr is filled with the values behind de format (“… “ )
// place holder.
// so %04d will be filled with the decimal value of wYear and has a fix length
// of 4 positions. Between every value an ASCII <TAB> is added (\t).
strcat(TotalStr,outStr);
// add outStr to TotalStr
sprintf(outStr,"%.2f\t%.2f\t%.2f\t%.2f\t%.1f\t%.2f\t", FloatVal1, FloatVal2, FloatVal3, FloatVal4, FloatVal5, FloatVal6);
// %.2f = floating point value with 2 decimals, no fixed length.
strcat(TotalStr,outStr)
// etc……..
As you see C++ is very powerful of building those kinds of strings.
Now I have to do the same project with a S7 315-2DP CPU including a CP341.
After a few days of studying this stuff, I did not find a solution to build such a string in step7. Probably I’m trying to hard to find the short way which isn’t there.
Does anybody know how to ad formatted integers and floating points to a char string?
If not, how can I make a floating point to string (char) conversion with 1 or two decimals? I have enough experience with programming in step7, so you can leave the basics away.
Thanks for any help.
Some time ago I wrote an ASCII protocol in C++ on a master PC which is sending a char string to a partner PC. The string contains a lot a formatted integer and floating point values.
A part of the code:
static char outStr[256] , TotalStr[256]
// Declaration of a 256 char String
sprintf(outStr,"%04d%02d%02d\t%02d%02d%02d\t%d\t", wYear, wMonth, wDay, wHour, wMinute, wSecond, StateValue);
// variable outStr is filled with the values behind de format (“… “ )
// place holder.
// so %04d will be filled with the decimal value of wYear and has a fix length
// of 4 positions. Between every value an ASCII <TAB> is added (\t).
strcat(TotalStr,outStr);
// add outStr to TotalStr
sprintf(outStr,"%.2f\t%.2f\t%.2f\t%.2f\t%.1f\t%.2f\t", FloatVal1, FloatVal2, FloatVal3, FloatVal4, FloatVal5, FloatVal6);
// %.2f = floating point value with 2 decimals, no fixed length.
strcat(TotalStr,outStr)
// etc……..
As you see C++ is very powerful of building those kinds of strings.
Now I have to do the same project with a S7 315-2DP CPU including a CP341.
After a few days of studying this stuff, I did not find a solution to build such a string in step7. Probably I’m trying to hard to find the short way which isn’t there.
Does anybody know how to ad formatted integers and floating points to a char string?
If not, how can I make a floating point to string (char) conversion with 1 or two decimals? I have enough experience with programming in step7, so you can leave the basics away.
Thanks for any help.