03-02-2010 09:40 AM - edited 03-02-2010 09:41 AM
Good day, everyone.
Although I have dabbled a (tiny) bit with LabView in the past, I am quite new with the concept of graphical programming. After testing and trying for a period, I've made my first attempt on a "serious VI". Given that I have not seen a FAQ saying that such requests are unwanted, I wondered if someone could take a minute or two to check out my VI and see if they can spot any major disadvantages with my method of doing stuff. After seeing the "Grumpy Old Men" thread, I know I might be taking a risk here, but I hope you'll be gentle.
There are especially a couple of points that I wonder about:
- The VI is obviously meant to send a command to a recipient over an RS232 interface, in this case a TV set. I'm using a byte array to set up the command constants and command length, and changing the initially zeroed bytes afterward according to the TV protocol. Is this a good or bad method? If bad, why? And how else should I do it?
- I'm using quite a bit of data type converters, to avoid this automatic data type conversion that else would be taking place (identified by a red dot on the symbol input). Is it really necessary to keep such a rigid control over the data types (like you would when programming in e.g. C), or is overflow never going to happen and I'm just making more work for myself?
Thanks a lot for any pointers!
03-02-2010 10:00 AM
Well, I'm sometimes grumpy, and some people would probably say I'm old, but I'll take a shot at being nice. Hey, it's been known to happen!
Overall, a pretty good start. Much better than some of the code we've seen on these boards from those new to LabVIEW.
General comments/questions:
Well, hopefully that wasn't too grumpy. Have to get back to work now, so I have to stop. Others can chime in as well.
03-02-2010 12:13 PM - edited 03-02-2010 12:15 PM
I agree with SMercurio, (although he's grumpier than usual today.. 😄 )
I would actually create a sub-vi where you convert the inputs to a string. That way, you can fit all your code within a nice small area of a single screen.
When programming, stay away from the Stacked Sequences. Otherwise, anyone (including you) will be cursing lijke crazy in the future. Also, the nasty Stacked Sequences make you write code where the wire runs from right to left, which is a huge "NO-NO".
Adding a simple STOP button would be a good start to control that while loop.
Question: the 10 ms delay, did you actually want 10ms? Or was it a nice round number? You can use 1 ms as a typical minimum. 0ms is still valid, but may push the CPU usage up the percentage scale, but it will allow other tasks to take CPU time, which is good. I simply mention it because it is a good trick to know when looping as fast as possible is cruicial.
Good start.
Below is the code for the sub-vi should you go that route.
(I should have posted as jpg or bmp, just to get smercurio even more grumpy 😉 )
03-02-2010 12:42 PM
03-02-2010 01:13 PM
oj-
So there are some things you did right.
Some bad habits too.
Overall C+ and do read the style guide I linked. You'll do fine with some practice.
03-02-2010 03:04 PM
Looks like a very good start to me.
Just skip the sequence, there's no hurt in having to scroll a little sideways in the code (it can be quite annoying if you have to scroll alot in both directions though).
03-05-2010 03:58 AM - edited 03-05-2010 03:58 AM
Thanks a lot for the replies! And I appologize for the late reply.
The feedback was great, with a lot I didn't know or hadn't thought about. I've attached a new version of the VI, where I've tried to incorporate much of the feedback from you. It would be great if you could take a 2nd look!
Some individual comments:
@smercurio_fc:
@Ray.R:
@Yamaeda:
03-05-2010 04:45 AM - edited 03-05-2010 04:46 AM
1) The constsnts like the array constant (0E 00 06) along with the "Byte Array To String" must be kept outside the while loop. Since for every iteration the same conversion is happenning so its a waste of the resource
2) same thing with constant connected to "Wait (ms)"
3) Wire appropriate data type to the "Wait (ms)" to take off that coercion data.
Guru
03-05-2010 07:09 AM
Some "additional" esthetics comments.
1. Do not view terminals (controls . indicators) as icons. They are big and simply waste real-estate.
You can go to the Tools menu, select Options, and to the left select Block Diagram and remove the checkmark next to "Place Front Panel Terminals as icon".
2. Avoid wiring in or out of the Structure (While Loop in this case) from the top or bottom.
3. Try to keep wiring line straight. You've done a fairly good job.
03-05-2010 07:56 AM
oj-
MUCH better. You are correct that you have a potential timing issue. If the ms Timer is near roll over (about every 27 days) When you add Timeout to Tick you will have a Small number in the u32 that feeds your read loop timeout condition. The first itteration of the loop terminates on timeout in this condition. Use "Get Date Time.vi" to avoid this infrequent problem (which has a frequency so low you'll never trace it down if you even ever see it). The infrequency of the issue is why few programmers worry. I got bit ONCE by a wait during ms rollover in 10 years (caused an infinate loop so I was able to debug and probe and understand why my vi hung)
You did a good job incorporating most of the suggestions. Why did you avoid Documentation?