S7: String Output from FC

pethoek

Member
Join Date
Apr 2009
Location
Järbo
Posts
105
I Need to write a function that takes a 2 digit number and converts this to a string. Yes i could use the I_STRNG function for this. But as i need to display the result with preceeding zero's they will dissapear with the I_STRNG function.

So here is what i have done so far. A 2 digit number is passed, and converted to a word consisting of the char code representation for the number in question.

This is the code i have so far in my FC10, i need to pass a string to an output of this FC.

Code:
      L     #In1                        // Decimaltal
      ITB                               // Omvandla till BCD
      AW    W#16#F0                     // maska bort LSB
      SLW   4                           // Skifta vänster 4 bitar
      T     #L_TEMP                     // Mellanlagra MSW
      L     #In1                        // Decimaltal
      ITB                               // Omvandla till BCD
      AW    W#16#F                      // Maska bort MSB
      L     #L_TEMP                     // Ladda MSW
      OW                                // Slå ihop med LSW
      L     W#16#3030                   // 0x3030 = "00"
      +I                                // Addera -> chr koder
      OD    DW#16#2020000               // Edit: added 2 lines of code to create a DW, which could be copied to the Str:Output
      T     #L_TEMP

Example: Decimal 29 is passed, this is converted to 0x3239 which is "29" in string format. ascii kodes 0x32 = "2" and 0x39 = "9". So far no problems. But now i need to construct a valid S7 string. And now i'm not sure how to continue the function.

I do now S7 string format is Actual Length + 2 bytes, and the extra bytes tells the maximum and the actual length of the string. I'm also familiar with the any pointer but still i don't manage to solve this one.

I need to see some similar constructs to learn how to do it. Any one out here with some examples ?

best regards
/pethoek
 
Last edited:
You did want leading zeros, and not spaces ?

Code:
FUNCTION FC 10 : STRING [254]
TITLE =
VERSION : 0.1

VAR_INPUT
  In1 : INT ; 
END_VAR
VAR_TEMP
  L_Temp : DWORD ; 
  iDB : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =
      L     #In1; // Decimaltal
      ITB   ; // Omvandla till BCD
      AW    W#16#F0; // maska bort LSB
      SLW   4; // Skifta vänster 4 bitar
      T     #L_Temp; // Mellanlagra MSW
      L     #In1; // Decimaltal
      ITB   ; // Omvandla till BCD
      AW    W#16#F; // Maska bort MSB
      L     #L_Temp; // Ladda MSW
      OW    ; // Slå ihop med LSW
      L     W#16#3030; // 0x3030 = "00"
      +I    ; // Addera -> chr koder
      T     #L_Temp; // Edit: added 3 lines of code to create a DW, which could be copied to the Str:Output
      OD    DW#16#30300000; 
      T     #L_Temp; 
//..
      L     P##RET_VAL; 
      LAR2  ; 
      L     W [AR2,P#0.0]; 
      T     #iDB; 
      OPN   DB [#iDB]; 
      L     D [AR2,P#2.0]; 
      LAR2  ; 
      LAR1  P##L_Temp; 
      L     4; 
      T     B [AR2,P#0.0]; 
      T     B [AR2,P#1.0]; 
      L     D [AR1,P#0.0]; 
      T     D [AR2,P#2.0]; 
 
END_FUNCTION
 

Similar Topics

Hello, I have a scanner connected to my Allen Bradley PLC and i can receive the scanned barcode in my plc as a String. Now i need to transfer...
Replies
9
Views
1,944
Hello everyone, I'm working in RSLogix 5000. I have an ASCII string of letters & numbers (call it String_3) which I have used INSERT to add a...
Replies
3
Views
2,322
I am creating a global object in FTView SE 13. I want to have a string read from the PLC and display (in this case the tagname). So lets say...
Replies
4
Views
167
So I had an odd request from a customer for the above. I have written the logic and tested it all in one PLC with only using 7 outputs and 7...
Replies
15
Views
427
Hello Inside a FB, I´m trying to transfer a string from a DB to a IN_OUT var that was define as a UDT. The problem is that i can´t determine the...
Replies
4
Views
128
Back
Top Bottom