Here is a list of issues that I noticed at a glance (the first 3 items are just about best programming practice - they won't prevent your code from working):
Rung 1 - Use the Power up with the operand instead of SB 2.
Rungs 7-10 - ALWAYS use a transition contact to load an HMI display (I recognize that your code would have the power flow on for only 1 PLC cycle, which is why it works). Also, don't add any code in the same ladder rung after an HMI call FB.
Rung 11 - Just use SB 2 for all your comm initializations. I'm finding it surprising that your tap machine (or whatever the MODBUS slave is) takes that much longer than the PLC to boot up, but if so, then I suppose you have to do it the way you are. However, use SB 2 to initialize everything, then place your delay on the connect only. The PLC doesn't care, but it's better programming practice.
Rungs 19-22 - You need to SET a bit for your read and write, then RESET the bit at the end of the MODBUS read & write (similar to what you correctly do for the connect & close functions) to allow for the busy bit to be on. This may be why you were seeing unpredictable results without the timers.
I now have my Remote I/O module connected and communicating correctly but I now have an issue with the Analog Input module. I have some 4-20mA transmitters wired up to the inputs but the LEDs are all blinking. The manual suggests that it is because the field power is no connected. This is correct as the device is powered from another 24V supply.
Any ideas? Any helps is greatly appreciated.
@DanT Hey, I've been checking as you said connecting a 3.3k resistor pull up to my V+ and the scope ground to CM4.
Results are that the signal is powered up but I have the 50Hz frequency...
I didn't put any load before the scope and I don't know yet the type of inverter that I will command.
Thanks for your quick answer.
Disclaimer- Im self taught PLC programmer so some of the ways I have done things may be unorthodox and I am open to suggestions and always willing to learn.
I had a machine build were the scope of the project changed and I needed more IO. I had already installed the SAMBA and needed more IO. I ordered a 16 pt input module and an 8 point out module of the automation direct PROTOS X modbus tcp remote IO.
I have the io working and it suits the needs of the application. What I am wondering is if you guys could take a look at my code and tell me if it could be optimized. I had to use a 20ms delay on the read write to get this to work without it having unpredictable behavior. This 20ms delay makes my total turnaround time to read an input and update and output somewhere around 45ms. This is acceptable for this application but I would like to do better if it is just a matter of optimizing my way of handling the modbus messaging or something. I also could use this combo more often if i can make it faster as this combo is cheaper than buying a vision plc and using unitronics IO, just currently it is slower.
I have changed my ip so it may appear that it wouldnt work the way it is but the code works. I dont know enough about network security to go posting the IP on the forum. Im sure that not enough to do anything but I changed them. I also removed all the subroutines so you may see some stuff called that doesnt exist.
Again, I am looking for ways to optimize my modbus messaging! Thanks!
redacted forum program.vlp