01-16-2017 04:00 PM
I backed up and simplified what I'm trying to do. Right now, without a for loop, I'm getting the first 2 bytes out of the array. Now I need to index through the array and possible loop it, plus be able to send a single pair of bytes from within the array. Does this look like a good starting point to get help on? You can ignore everything outside of the While Loop, it's just configuring communication with the Arduino board, and that works fine. I don't see a way to attach the vi, what am I missing?
01-16-2017 04:04 PM
01-16-2017 05:30 PM
What exactly is wrong with this code? I understand how it works and I can't find a better way.
01-17-2017 08:42 AM
There is nothing "wrong" with the code. But as your application grows in size, it will become unmanageable if you don't have a proper architecture established in the beginning. What you are doing here is polling the buttons waiting for them to change. The proper method is to use an event structure and register the value change event for the button. Inside the event, you could send a message to a second parallel loop that does the processing of the event, while your event loop goes back to looking for additional events to occur. For even more functionality, your event loop might even be embedded in a state machine that would handle the initialization of your hardware, application startup, shutdown, etc.
01-17-2017 09:07 AM
This is a program that we use and was written by an outside firm. The highlighted square in the middle of the picture is what I can view on my 23" monitor. This program has zero thought put into the architecture and uses a lot of case structures for button polling, local variables, and sequence structures. It is one HUGE while loop. The program works (I'm not sure how) but it is all kinds of wrong. This is what your code will end up looking like if you don't develop the architecture now while the application still fits on one screen.
01-17-2017 09:10 AM
@aputman wrote:
There is nothing "wrong" with the code. But as your application grows in size, it will become unmanageable if you don't have a proper architecture established in the beginning.
This is the correct answer. I reread my message from the other day and it was a bit... meaner than I intended.
Look at it this way - right now you have two buttons you want to use to control and it is working. What happens if you want a button to reset the connection to your arduino? What about a 3rd option where you run in the loop but only for 10 seconds?
Your application is working right now but small changes will cause the complexity to grow exponentially. If this continues at some point in time it will become easier to just rewrite the application than make a small change. I've seen it before 🙂
01-17-2017 09:40 AM - edited 01-17-2017 09:41 AM
To contrast that, here is a progrom that I wrote that, IMHO, has a proper architecture. It accomplishes a much larger task than my previous example, but fits in a much smaller block diagram. The top loop is a DAQ loop that continuously acquires data and sends data via queue to other areas of the diagram. The middle highlighted area (where most of the coding is done) is a state machine. I prefer the JKI state machine which is string-based rather than enum based. This state machine has approximately 75 different states from handling UI events to running test routines. The lower left section is my event structure that monitors my UI and sends messages into my state machine. And the lower right is error handling loop.
Some might say that the block diagram shouldn't take up more than one screen and generally, that is a good rule of thumb. In my case, I do most of the coding in the center state machine area so I don't mind if I have to scroll down to add another event. Navigation is very easy because the diagram is organized. Adding additional test routines is a cinch because it's just a matter of adding the additional states, pulling data from the queue and updating the UI as necessary.
01-19-2017 09:45 AM
I don't see a JKI state machine in my Trial version. Is it only in the pro version?
01-19-2017 09:48 AM
01-19-2017 02:05 PM
Yes but I forgot about it until you mentioned it. I installed JKI State Machine but haven't gotten too far with it yet.