snertmetworst Posted August 9, 2013 Report Posted August 9, 2013 Hi everyone! Does anybody have experience with extracting numerical values from SCAN FB? Im communicating between controller and V350 over serial cable. And receive messages like: R+400<CR><LF> R-3000<CR><LF> Using <LF> as ETX. In the SCAN FB i have tried configuring this message in many different ways. But did not have succes. It alwas returns -1 in "Index of received message". Simple fixed length message without variables i can receive just fine. Any ideas? or pointers? Greets Tom
MVP 2023 Joe Tauser Posted August 13, 2013 MVP 2023 Report Posted August 13, 2013 The SCAN block can not automatically extract and convert numbers of different lengths - I spent a lot of time on this myself. In the end I created stream variables and wrote string manipulation logic to find the beginning of the numerical part, determine the length, extract it, and convert it with the ASCII->NUM block. Once I was resigned to take this approach it was fairly straightforward. For extra fun, throw decimals of unknown location in. Joe T.
MVP 2014 Simon Posted August 13, 2013 MVP 2014 Report Posted August 13, 2013 It depends how many variations you are looking for. If you have for example a range of 1 digit to 5 digits you can create 5 fixed-length strings, and the PLC will match the incomig message with the appropriate string. You should be able to catch the +/- sign as part of the number. R+n<CR><LF> . . . R-nnnnn<CR><LF>
snertmetworst Posted August 14, 2013 Author Report Posted August 14, 2013 Joe and Simon, Thank you for you'r replies. I will play around with the range sollution Simon suggested, because i want to keep the cycle time as low as possible. As i assume this will be less resource consuming then string manipulation logic. Or is this assumtion incorrect? Cheers, Tom
MVP 2023 Joe Tauser Posted August 18, 2013 MVP 2023 Report Posted August 18, 2013 If you will never encounter wandering decimals in your numeric strings then Simon's answer is the right and easy way to do it. The application I was working on involved extracting a part number and two numbers separated by commas from a barcode. The length of each field was not fixed, so I had to locate the comma positions and gather information indirectly. Thank God for all the string commands we have. Joe T.
MVP 2014 Simon Posted August 19, 2013 MVP 2014 Report Posted August 19, 2013 I can't say for sure, but I would not expect the string manipulation logic to significantly increase scan time. That is based on the example strings you have shown above. String manipulation is usually just simple searches and block data moves. This usually happens pretty quickly. As Joe suggests, if the string has no floating point decimals, and generally can be captured by a relatively small number of different length templates, then using the method I suggest should save you lots of time on writing and debugging the program. String manipulation is more universal, but also requires more effort to write and test.
snertmetworst Posted August 19, 2013 Author Report Posted August 19, 2013 Hey guys, Here is a small update, i thought might be interesting for other people struggeling with this. I found that the numeric decimal veriable length does work. But only in certain situations. For example it is possilbe to construct a receive msg like this: R[11111111111] Here [11111111111] is the variable and "R" is static ascii, can be any ascii As ETX I used 0x0A. It only seems to work when ETX 1 byte long. And there can be nothing else behind the variable. I dont know why this is. But it seems to work for me.
MVP 2014 Simon Posted August 19, 2013 MVP 2014 Report Posted August 19, 2013 Now you mention it, I have also encountered that effect. If the variable-length field is at the end, the situation is very simple, the system only needs to look for the ETX character in order to complete the scan. If the variable-length field is in the middle of the string, if affects the relative position of everything that follows. So the system needs to track much more information and the string decoding becomes more complex. That's my understanding...
snertmetworst Posted August 20, 2013 Author Report Posted August 20, 2013 Yes, That would be my assumption also. Very strange, that this is not clearly documented in the help documentation suplied with visilogics.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now