7/29/2010 10:57 PM | |
Joined: 7/7/2010 Last visit: 4/24/2024 Posts: 14624 Rating: (2348) |
Ok, as I develop an application with RS485 communications using a simple ASCII protocol with some networked drives. Some of the capabilities are quite nice, while others are annoying in the way they simply are not there or obvious, or worse where the documentation differs from the actual program entry. I have a case where I need tosearch for a character (received via RS485) within a 'valid string'. Specificaly, each drive sends ASCII messages with their address as the first character. As part of parsing and validating the received message, grab the first character from the buffer, copy it to a FC/FB input parameter, then inside the FC/FB try to compare it to a string, say '23456'. The character MUST be a string for the FIND function to work despite the documentation stating it allows for a CHAR for the comparison. Since there is no native CHAR -> STRING conversion, I had to create a FC/FB to accept the char, and return a STRING[1]. Don't get me started on how to copy an array of CHAR to a STRING.... That's also annoying in how it must be accomplished. I cannot even create an array index from a tag. For example, it would be nice to walk through an array (a loop), grab the value and append to a string. #temp_array[#counter] That doesn't appear to be allowed inside the FC/FB. </rant> SO, how do you convert ARRAY[1..n] of CHAR to STRING? I know a work-around but why does it have to be so hard? --- well I thought I had a work-around.... --- Splitted from bugs in S7 1200. |
Last edited by: O_Moderator at: 7/30/2010 10:27 AMnew subject after splitting Last edited by: huggy_d1 at: 7/29/2010 11:34 PMscience guy |
|
8/2/2010 10:29 AM | |
Joined: 5/28/2008 Last visit: 4/24/2024 Posts: 1343 Rating: (141)
|
Hi, you can use FieldRead and FieldWrite instructions. With FieldRead you can read char by char from your array and with FieldWrite you can fill up your string also char by char. With Label and Jump instruction you can build up the loop to read/write x-times. How do you program the "FieldRead" and "FieldWrite" instructions in STEP 7 Basic V10.5? Hope it hels regards |
6/8/2012 3:10 PM | |
Joined: 7/7/2010 Last visit: 4/24/2024 Posts: 14624 Rating: (2348)
|
My original problem was solved with this: https://support.automation.siemens.com/WW/llisapi.dll?query=char+string+s7-1200+faq&func=cslib.cssearch&content=adsearch%2Fadsearch.aspx%3Ftab%3D2&lang=en&siteid=csius&objaction=cssearch&searchinprim=_searchinprim_&nodeid=99&x=16&y=8&cssearchengine=NEW Also, with the AT overlay construct, the conversion is much easier. With anSCL FB, it is much easier to loop through things. The combo of AT overlay and SCL FBs, it is pretty straightforward now compared to 2010. |
science guy |
|
This contribution was helpful to1 thankful Users |
Follow us on