LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Laser range ascii to decimal

Solved!
Go to solution

Dear All

 

I will continue an old project, and now changing the distance measurement from a sharp IR sensor for a new one laser range sensor

This is the laser

https://www.aliexpress.com/item/32803776703.html?spm=a2g0s.8937460.0.0.35f22e0eWUqmsK

 

and this is ttl usb

https://www.aliexpress.com/item/32694152202.html?spm=a2g0s.8937460.0.0.16272e0e8WeBsy

 

I make the firs example and  I get an output string with the distance and some special characters...

I concatenate the string and I get a correct string with the distance, for example 000.194  meters.

My problem now is converting this string to a decimal number.

I had some experience in hexadecimal strings when I controlled an inverter, but seems not working for this example. I tried some functions but seems not result.

 

Best regards

cpalka

 

0 Kudos
Message 1 of 10
(4,955 Views)
Solution
Accepted by cpalka

If you have the value in an ASCII format, then use Fract/Ext String To Number to convert it to a floating point value.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 10
(4,924 Views)

Your code is very strange, and if the data you are showing in "Read String" is an example of the data you get from this device, something is very strange, as it does not seem to be numbers (for example, 123.456 would show, as the data sheet indicates, "31 32 33 2E 34 35 36".  Your string has lots of 00 (Nul) characters and other data that don't make sense.

 

Your code is also messy.  Do you really want to push a button and send a command to the Laser once a second?  Shouldn't you send the laser a series of commands that get it started, then read data until you want to shut it off, when you send another series?

 

And why is your block diagram so huge, with lots of wasted blank space (making it difficult to see the code on a laptop screen)?

 

Bob Schor

0 Kudos
Message 3 of 10
(4,762 Views)

Hi crossrulz

 

That's it, many thanks.

 

Best regards

cpalka

 

 

0 Kudos
Message 4 of 10
(4,656 Views)

Hi Bob

 

You are right.

I suppose you know that in this forun we have  specialists in labview like you and begginners like me 

Só let me thanks any help you could give me.

This project is only for test the   laser.

In fact my project is a 3m ruller with an encoder and now the laser that Will   moves on the ruller and Will measure the surface of the ground if it os plan ir not.

Só I will need the laser in continous reading, or a reading each encoder pulse. But shoul d be in continous mode and save actual reading each pulse.

I am starting have problems in the sub string in continous mode, seems the time in loop are not the same in visa porta.

 

Best regards

Cpalka 

0 Kudos
Message 5 of 10
(4,650 Views)

Hi cpalka,

 

Hopefully your problem is solved now, but I'd like to point out the following. You might find it helpful (or not!).

cbutcher_0-1577749368262.png

Here I build an array of the possible "command strings" (conceptually before the loop starts) then only have to Index Array to get the correct value to pass to VISA Write. This would allow you to remove the Case Structure and simplify reading through your code. Note that this still doesn't link readable commands, like "Single reading" to the command string though.

This is a simple change and would allow the use of an Event Structure if you desired, but to continuously read you'd also want to set a finite (perhaps controlled by "Sampling time") value to the timeout of the Event Structure. (As an aside, you've got time in seconds *100 for time in ms, you have a typo and need 1000 instead 🙂  )

 

If you wanted to go a bit further, you could use something like an array of clusters of Enum and String (command and cmd string) and then do a lookup. This would be better using either Variant Attribute tables or the new Map type in LabVIEW 2019 (both of which will be easier to lookup values in). It might not be necessary in your opinion, depending on the size of your application and how much work it is worth.

 

cbutcher_1-1577749888069.png


GCentral
Message 6 of 10
(4,367 Views)

Hi cbutcher

 

Of course it will help.

 

Many thanks for the good tips and it increase my knowledge in  labview

 

Best regards

cpalka

0 Kudos
Message 7 of 10
(3,210 Views)

@cbutcher wrote:

If you wanted to go a bit further, you could use something like an array of clusters of Enum and String (command and cmd string) and then do a lookup. This would be better using either Variant Attribute tables or the new Map type in LabVIEW 2019 (both of which will be easier to lookup values in). It might not be necessary in your opinion, depending on the size of your application and how much work it is worth.

 

cbutcher_1-1577749888069.png


Although maps are fast (, faster than an array search), they're slower than indexing an array element.

 

A map is more complex, more work, and slower... Why is a map better?

Message 8 of 10
(3,185 Views)

I suppose for me the advantage of a Map or searching an array (certainly slower than indexing) is that I can add intermediate values to an enum - the principle control remains the enum rather than a coerced integer value. With the array of strings, I'd have to be careful that the strings passed to Build Array or in the array constant are always in the same order as the elements of the enum/typedef.

 

I can also add them in any order to the Map or Array, but that's perhaps a less significant benefit.


GCentral
Message 9 of 10
(3,152 Views)

@cbutcher wrote:

I suppose for me the advantage of a Map or searching an array (certainly slower than indexing) is that I can add intermediate values to an enum - the principle control remains the enum rather than a coerced integer value. With the array of strings, I'd have to be careful that the strings passed to Build Array or in the array constant are always in the same order as the elements of the enum/typedef.

 

I can also add them in any order to the Map or Array, but that's perhaps a less significant benefit.


That's valid reasoning.

 

I'd still prefer the index array in a sub VI and the enum in a type def. Mainly because it's so simple, the speed benefit will almost never be relevant.

0 Kudos
Message 10 of 10
(3,084 Views)