Jump to content

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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>

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...