12-27-2019 03:43 PM - edited 12-27-2019 03:44 PM
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
Solved! Go to Solution.
12-27-2019 04:12 PM
If you have the value in an ASCII format, then use Fract/Ext String To Number to convert it to a floating point value.
12-28-2019 01:54 PM
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
12-29-2019 01:39 PM
Hi crossrulz
That's it, many thanks.
Best regards
cpalka
12-29-2019 01:54 PM
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
12-30-2019 05:51 PM - edited 12-30-2019 05:52 PM
Hi cpalka,
Hopefully your problem is solved now, but I'd like to point out the following. You might find it helpful (or not!).
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.
01-02-2020 03:36 PM - edited 01-02-2020 03:37 PM
Hi cbutcher
Of course it will help.
Many thanks for the good tips and it increase my knowledge in labview
Best regards
cpalka
01-03-2020 06:19 AM
@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.
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?
01-03-2020 02:48 PM
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.
01-06-2020 02:58 AM
@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.