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

Link to comment
Share on other sites

  • MVP 2023

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.

Link to comment
Share on other sites

  • MVP 2014

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>

Link to comment
Share on other sites

  • MVP 2023

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.

Link to comment
Share on other sites

  • MVP 2014

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.

Link to comment
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.

Link to comment
Share on other sites

  • MVP 2014

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Confirm to continue.