REAL to ASCII

f117

Member
Join Date
Oct 2007
Location
ath
Posts
26
Hello, can you tell me please how i can convert REAL to ASCII?
with an example if it is possible.
Thank you
 
Last edited:
Your question is not very clear. If you are trying to convert a REAL number to ASCII text, then the PLC you are using may have a function block for it.

But you really need to be more descriptive in your form of questioning to get a good answer.
 
i am sorry.......i am a bit hurry :/ sorry...my fault....its on Siemens with S7-300

@L D[AR2,P#0.0] yes i have try with this but no luck :S can you give me an example? with ret_val or with a STL code?
 
You have to ensure that the string variable is long enough for the string.

I believe it has to be 14 acharacters long.

The BIR is zero at return if the above is not met or the real number is invalid.
 
Here's some example code using FC30. Note that if you declare a string variable in temp local data, you must populate the max size and actual size bytes with program - I use a general purpose FC to initialise string variables (FC2 below). Create a symbol for DB1 called "dbStrings" in your symbol table, paste this code into a source block and compile it. It will produce DB1, FC1 and FC2

Call FC1 from OB1. Monitor DB1 to check the results.

Code:
DATA_BLOCK "dbStrings"
TITLE =
VERSION : 0.1

  STRUCT  
   sString : STRING  [14 ] := '+0.1234567e+00'; //initialised string (note it occupies 16 bytes and cannot be monitored in DB)
   acString1 : STRUCT  //string made from chars for monitoring
	byMaxLength : BYTE ; 
	byLength : BYTE ; 
	acString : ARRAY  [1 .. 14 ] OF CHAR ; 
   END_STRUCT ; 
   acString2 : STRUCT  //string made from chars for monitoring
	byMaxLength : BYTE ; 
	byLength : BYTE ; 
	acString : ARRAY  [1 .. 14 ] OF CHAR ; 
   END_STRUCT ; 
  END_STRUCT ; 
BEGIN
   sString := '+0.1234567e+00'; 
   acString1.byMaxLength := B#16#0; 
   acString1.byLength := B#16#0; 
   acString1.acString[1] := ' '; 
   acString1.acString[2] := ' '; 
   acString1.acString[3] := ' '; 
   acString1.acString[4] := ' '; 
   acString1.acString[5] := ' '; 
   acString1.acString[6] := ' '; 
   acString1.acString[7] := ' '; 
   acString1.acString[8] := ' '; 
   acString1.acString[9] := ' '; 
   acString1.acString[10] := ' '; 
   acString1.acString[11] := ' '; 
   acString1.acString[12] := ' '; 
   acString1.acString[13] := ' '; 
   acString1.acString[14] := ' '; 
   acString2.byMaxLength := B#16#0; 
   acString2.byLength := B#16#0; 
   acString2.acString[1] := ' '; 
   acString2.acString[2] := ' '; 
   acString2.acString[3] := ' '; 
   acString2.acString[4] := ' '; 
   acString2.acString[5] := ' '; 
   acString2.acString[6] := ' '; 
   acString2.acString[7] := ' '; 
   acString2.acString[8] := ' '; 
   acString2.acString[9] := ' '; 
   acString2.acString[10] := ' '; 
   acString2.acString[11] := ' '; 
   acString2.acString[12] := ' '; 
   acString2.acString[13] := ' '; 
   acString2.acString[14] := ' '; 
END_DATA_BLOCK
FUNCTION FC 2 : VOID
TITLE =Initialise a string
VERSION : 0.1

VAR_INPUT
  sAny : ANY ; 
  cInit : CHAR ; 
END_VAR
VAR_TEMP
  iLoopCount : INT ; 
  iDBNo : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =init a string
	  L	 P##sAny; 
	  LAR1  ; 
	  L	 W [AR1,P#2.0]; 
	  T	 #iLoopCount; 
	  L	 W [AR1,P#4.0]; 
	  T	 #iDBNo; 
	  L	 D [AR1,P#6.0]; 
	  LAR1  ; 
	  OPN   DB [#iDBNo]; 
	  L	 #iLoopCount; 
	  +	 -2; 
	  T	 B [AR1,P#0.0]; 
	  T	 B [AR1,P#1.0]; 
Loop: T	 #iLoopCount; 
	  L	 #cInit; 
	  T	 B [AR1,P#2.0]; 
	  +AR1  P#1.0; 
	  L	 #iLoopCount; 
	  LOOP  Loop; 
	  SET   ; 
	  SAVE  ; 
END_FUNCTION
FUNCTION FC 1 : VOID
TITLE =R_String demo
VERSION : 0.1

VAR_TEMP
  sTempString : STRING  [14 ]; 
END_VAR
BEGIN
NETWORK
TITLE =Initialise a string in temp local data
 
	  CALL FC	 2 (
		   sAny					 := #sTempString,
		   cInit					:= '_');
	  NOP   0; 
NETWORK
TITLE =convert Real to string to temp area
	  CALL FC30 (
		   IN					   := 9.000000e-001,
		   RET_VAL				  := #sTempString);
	  NOP   0; 
NETWORK
TITLE =copy temp result to displayable string variable in DB
	  CALL SFC20 (
		   SRCBLK				   := #sTempString,
		   RET_VAL				  := MW	 0,
		   DSTBLK				   := "dbStrings".acString1);
	  NOP   0; 
NETWORK
TITLE =convert Real to string to DB
	  CALL FC30 (
		   IN					   := 9.876543e+000,
		   RET_VAL				  := "dbStrings".sString);
	  NOP   0; 
NETWORK
TITLE =copy string in DB to displayable string variable in DB
	  CALL SFC20 (
		   SRCBLK				   := "dbStrings".sString,
		   RET_VAL				  := MW	 0,
		   DSTBLK				   := "dbStrings".acString2);
	  NOP   0; 
END_FUNCTION
 
Wow.
I am really glad I do not like Siemens and refuse to use it.
The AB method in structured text.

RTOS(Source,Dest);

Regards Alan
 
I agree, unless it is easier than it looks the Siemens stuff seems horrific, Schneider\Modicon:

Ladder:

string.jpg


Structured Text:

%MB20:14:=REAL_TO_STRING(%MF30);


End of Story !!
 
Alan Case said:
Wow.
I am really glad I do not like Siemens and refuse to use it.
The AB method in structured text.

RTOS(Source,Dest);

Regards Alan


That's the trouble with Simon at times, he can go overboard :ROFLMAO:

This bit

Code:
CALL FC30 (
		   IN					   := 9.000000e-001,
		   RET_VAL				  := #sTempString);


is equivalent to what you wrote, it is also NOT COMPILED, which means it is in text format, once compiled it will show in LADDER.

None of the code is compiled, it would look more readable if compiled.

He included a Data Block with the ASCII data area set up, he also included a block to initialise the ASCII data area. Not necesary, he's just showing a method.

Siemens Step 7 is undoubtably the best PLC out there, shame people get frightened off because it looks different and too hard, when all it takes is a bit of experience.
 
you mean i put this to a new STL "file" at source and compile it? it gives errors........if i put it to like text after changing the view from ladder to stl view it all becomes red :-S something is going wrong.... i also tryied to add the function FC30 from the libraries but when at RET_VAT write #sTempString is not acceptable :S

if it is easy for you can you guide me step by step so that the function works properly? thanks
 
f117 said:
you mean i put this to a new STL "file" at source and compile it? it gives errors........if i put it to like text after changing the view from ladder to stl view it all becomes red :-S something is going wrong.... i also tryied to add the function FC30 from the libraries but when at RET_VAT write #sTempString is not acceptable :S

if it is easy for you can you guide me step by step so that the function works properly? thanks

To compile Simons code, you must create a new Source block in the source folder, then cut and paste Simon's text into it.

To enable it to compile you need to create a single Symbol in your Symbol list. Use any spare DB and call it "dbStrings".

No need to create the DB, just the symbol as Simon's code creates the DB when compiled.

Once that is done, the source block can be compiled, it will create one DB and two FC's (FC1 an FC2).

FC1 will have to remain STL, but FC2 will convert to Ladder by changing the view.


EDIT:

Not sure of this (I don't have S7 at the mo, I'm stuck with Control Logix) but you may need to have FC30 and SFC20 already in your blocks folder, which can be done by opening a temp block and pulling both into the block, they get moved from the library into the project then.
 
Last edited:
Equivilant in Siemens SCL:

Code:
myTempString:=R_STRNG(rData);

or in ladder:
rtostring.JPG
 
Last edited:

Similar Topics

Hello all, We need to convert ASCII data into Real Raw data, here we use Trimble GPS and need to get the position data. We use SCADAPack 357...
Replies
4
Views
2,843
I have a SINT[500] array that is pulling data from a scale. The maximum number of characters that can be sent by the scale is 6, and there are two...
Replies
7
Views
1,606
Dear Experts. I have a CPU 315-2dp Siemens PLC which is communication between mistubishi fX-3U Series mistubishi is giving me AScii String data...
Replies
2
Views
5,943
Hi guys I have a big work cell that has 2 turntables and 4 fixtures, we have the Alpha signs(like you see in the restaurants the scrolling ones)...
Replies
8
Views
6,495
Has anyone had any experience or written any code to convert a real (F file) to an ASCII (ST file) for a AB SLC/Micro, in this case I am using a...
Replies
13
Views
6,935
Back
Top Bottom