09-03-2015 06:58 AM
Hi!
I have a very simple labview server with only one client connected to it. I also have an Arduino UNO card connected and one single digital input from a push button.
Port nr. is OK, COMport is OK and sometimes my labview program is OK.
The first thing I do when I start up my server is to update the Adurino firmware. I then run the server and open my client and run this as well. My program is now working, when I hit the push button on my Arduino card a led goes on in the clients front panel.
When I stop the client program and start it up again (server still running), nothing happens. I then have to restart bort the client and server, update the firmware on Arduino card and run as descriped abowe. Now the led goes on as I push the button. Im using the newest version of LINX to establish connection between arduino and labview.
Can anyone help me with this, it`s very anoing to have to do this every time. Programs attaced below
With kind regards
Espen Olsen
09-03-2015 07:21 AM
Your server listens for a connection outside the while loop indefintiely. So, the first time a connection comes in, it works. Once the user disconnects, you will get an error on your TCP functions, but since you ignore errors, you are not seeing it.
The connection is dead at that point, and your client can no longer reconnect. You need to movethe listen ofr connection into the loop and make a state machine. Wait for the listener with a timeout, so you can still stop the server (right now you cannot stop the server app if no connection has come in). If the connection comes in, switch your state to connected and look for incoming data. If you get an error that the connection was closed or reset, then close the connection and retrun to the Wait for connection state. Please note that you will get an error on the TCP Read if nothign comes in (don't even see a reason to be doing it).
09-04-2015 02:20 AM
Hi.
This dident solved the problem, arduino now dosent work. Still have to update firmware everytime, now i even have to update the firmware twice before anything happens.
09-04-2015 08:02 AM
You should post your new code for review. You didn't say whether it fixed your problem of the client being able to connect without restarting the server.
Did you leave the LINX initialize and cleanup outside of the while loop? You could basically have the same issue in your Arduino code where the Arduino will only accept a connection once, and you need a state machine there as well so that when the server shuts down, the Ardunio goes back to a state where it can be initialized.
09-04-2015 09:16 AM
Thanks!
Will try a little more first and post my new code. But when you mention state machine, im not quite sure what you mean.
Is it the Case Structure in labveiw I should use?
With kind regard
Espen
09-04-2015 09:27 AM - edited 09-04-2015 09:27 AM
Yes, use an enum as your state (although you could do it with a number, too, if you don't want to use an enum).
Have the enum in a shift register on the while loop and the selector for your case statement. There is a LabVIEW example called State Machine Fundamentals that you may wish to look at.
Basically, I see you having the following states:
You start in State 1 as the initial value for the shift register. State 1 immediately goes to State 2. In State 2, you need to see if you got a timeout/error. If so, you stay in the same state. Otherwise, you go to the State 3. You stay in State 3 until you get an error. No error, stay in State 3. An error means the client connection is lost, so go to State 4. State 4 just goes back to State 2. When the stop button is pressed, go to State 5, and have State 5 stop the while loop.
You should be passing errors around, too, so you can catch any issues, so you would want to add some checks for errors into your state machine, but what I list above is where you should start. I belive the only errors you should see on a client connection failure would be 60 and 66, but for now, just assume any error is a failed connection.
In state 5, the TCP connection may no longer be valid, so ignore any errors coming out of it.
09-04-2015 09:32 AM
Great!
Thank you so much for your promt reply!
I will try to work through you suggestions over the weekend and get back to you with results on monday.
Thanks again and have a nice weekend.
Espen
09-04-2015 04:26 PM
Are you using a Mac?