03-01-2021 05:55 PM
Hi everyone!
I am developing a PID on labview where I read 4 values from the arduino by serial port, and process one of these values into a PID.
My problem is: I think the VI is running or refresing every second, it's too slow! And I'd like it to run faster.
What should I do?
I attached the VI.
03-02-2021 03:17 AM
Your VI is simply reading values that the Arduino spits out.
The speed is limited by the Wait for Multiple function, and the speed of the data coming from the Arduino.
So, increate the speed of the data coming form the Arduino.
Also, that's not really considered good programming. Wires are bended, sequence structures, duplicate code... You're making all the rooky mistakes. I hope you're doing some (free) courses while you're making this.
03-02-2021 11:26 AM
wiebe@CARYA wrote:
duplicate code... You're making all the rooky mistakes. I hope you're doing some (free) courses while you're making this.
For example, the following could probably replaced by one single "scan from string". How does the incoming string look like?
The way you are coding this is full of booby traps and completely unnecessary operations (e.g. replacing the period with a comma then scan it using the system decimal point seems pointless and dangerous because it makes assumptions about localization. 🐵
03-02-2021 12:13 PM - edited 03-02-2021 12:13 PM
@altenbach wrote:For example, the following could probably replaced by one single "scan from string". How does the incoming string look like?
Just as a direct replacement...
03-02-2021 12:27 PM
Yes, that's what I had in mind, but it will of course not solve the speed problem. 😉
(For an even simpler drop-in replacement, we can connect the various indicators directly to the scan outputs. No need to bundle. Still, the cluster is a good idea in general)
03-02-2021 01:22 PM
@altenbach wrote:
(For an even simpler drop-in replacement, we can connect the various indicators directly to the scan outputs. No need to bundle. Still, the cluster is a good idea in general)
I started writing that code to act as a subVI. Based on that, the cluster makes a lot more sense.
03-02-2021 08:28 PM
Thanks for answering!
Actually I was learning by my owm and couldn't take any course, sorry for the crepy programming.....sad!
03-03-2021 03:43 AM
@crossrulz wrote:
@altenbach wrote:For example, the following could probably replaced by one single "scan from string". How does the incoming string look like?
Just as a direct replacement...
Careful!
No, it's not an exact replacement!
The original solution works for inputs regardless the used separator. So both 1,5 and 1.5 get parsed correctly. The replacement fails when commas are used.
Not that you should depend on that, but I've seen this replacement go wrong in inherited projects. It's was direct consequence of not having a good strategy for decimal points.
03-03-2021 10:35 AM - edited 03-03-2021 10:37 AM
wiebe@CARYA wrote:
The original solution works for inputs regardless the used separator. So both 1,5 and 1.5 get parsed correctly. The replacement fails when commas are used.
No, the instrument string is not localized and always has a period as decimal delimiter.
The original solution replaces all periods with comma and then parses it forcing a localized delimiter, which will not correctly work if the localization is a period. It will fail and drop all decimals in most parts of the world!
Tim's solution correctly parses the input irrespective of decimal delimiter localization. It will correctly work everywhere!
03-03-2021 11:34 AM - edited 03-03-2021 11:46 AM
@altenbach wrote:
wiebe@CARYA wrote:
The original solution works for inputs regardless the used separator. So both 1,5 and 1.5 get parsed correctly. The replacement fails when commas are used.No, the instrument string is not localized and always has a period as decimal delimiter.
The instrument string?
I missed the part where that strings comes from an instrument. It could be somewhere, I skimmed over most text.
EDIT: Ah, the Arduino... But that means custom code, which means anything goes. But probably '.''s are used, as OP replaces them.
@altenbach wrote:
The original solution replaces all periods with comma and then parses it forcing a localized delimiter, which will not correctly work if the localization is a period. It will fail and drop all decimals in most parts of the world!
Ah, yes, my reasoning would have been correct if it was replacing ',' with '.', and then didn't use the system setting.
Still, be very careful with replacements like that. Better yet, avoid being in that situation.
@altenbach wrote:
Tim's solution correctly parses the input irrespective of decimal delimiter localization.
Only if you're sure that the strings use '.' separators. Not sure how you can see that from the code.
Now of course one should make sure that at least a known separator is used. But with customers, you can't always make sure.
@altenbach wrote:
It will correctly work everywhere!
Not if the input uses ',' as separator.
Anyway, I'll find some other yaks to shave.