 shantanu@india
		
			shantanu@india
		
		
		
		
		
		
		
		
	
			09-17-2024 11:02 AM
Hi,
Attached is a simple VI which communicates to a Ethernet-to-RS485 converter that is gathering data from a PLC. Static IP has been assigned to the converter & all is well if there is no power outage or looseness of the network cable.
If either of the above two conditions occur then Windows assigns a fresh connection ID resulting in communication failure.
How to take care of this situation?
Thanks.
Solved! Go to Solution.
 crossrulz
		
			crossrulz
		
		
		 
		
		
		
		
		
	
			09-17-2024 12:01 PM
A very basic State Machine is what you need. You start with a "Connect" state, which connects to the device. Once a connection has been established, you can move on to the "Read" state. This is the state you already have programmed up, trying to read data from your device. When you want to stop the application, you move on to the "Close" state and stop your loop. This is where your connection reference is closed.
Now if you detect an error during the read, often error code 66 for a closed network connection, you need to transition to the Close and then back to the Connect states. This will allow you to attempt to reconnect to your device when there is an error.
 Kyle97330
		
			Kyle97330
		
		
		
		
		
		
		
		
	
			09-17-2024 12:41 PM
In addition to code changes as suggested, don't forget adding robustness to the physical setup as well.
Power failures? Add a UPS.
Loose cables? Buy better ones and/or use tie wraps to secure the ones you have in place better.
09-17-2024 01:12 PM
Thanks for the inputs.
Yes state machines have to be used I understand.
Crossrultz do I use simple case structures to build the state machines? Can you please provide an example?
Thanks again.
 crossrulz
		
			crossrulz
		
		
		 
		
		
		
		
		
	
			
			
    
	
		
		
		09-17-2024
	
		
		02:32 PM
	
	
	
	
	
	
	
	
	
	
	
	
	
	
 - last edited on 
    
	
		
		
		10-09-2025
	
		
		03:24 PM
	
	
	
	
	
	
	
	
	
	
	
	
	
	
 by 
				
		 Content Cleaner
		
			Content Cleaner
		
		
		
		
		
		
		
		
	
			
		
shantanu@india wrote:
Crossrulz do I use simple case structures to build the state machines? Can you please provide an example?
A simple state machine is based on a While Loop, Case Structure, and a Shift Register. You may need an additional shift register so the Close state knows where to go next (Connect or Stop).
09-19-2024 09:42 AM
Designed the same using state machines.
Absolutely bulletproof now!!
Thanks Crossrultz.
 rolfk
		
			rolfk
		
		
		 
		
		
		
		
		
	
			09-20-2024 04:08 AM
shantanu@india wrote:
Absolutely bulletproof now!!
Thanks Crossrultz.
Are you sure it will survive something like this?
09-20-2024 04:55 AM
Ha ha!
If that's a Desktop design then it gives me creeps... silent assassin lurking behind me