Hi, I am writing an application that receives data from a Siemens PLC and writes it to the database. I can’t figure out how to correctly write Exception's catch so that the program does not crash when there is no connection with the PLC and works correctly when there is a connection with it.
Exception in thread "main" java.lang.NullPointerException at com.sourceforge.snap7.moka7.S7Client.SendPacket(S7Client.java:417) at com.sourceforge.snap7.moka7.S7Client.SendPacket(S7Client.java:425) at com.sourceforge.snap7.moka7.S7Client.GetAgBlockInfo(S7Client.java:816) at com.sourceforge.snap7.moka7.S7Client.DBGet(S7Client.java:846) at app.DispatcherPLC.getDB(DispatcherPLC.java:31) at app.DispatcherPLC.resultConnection(DispatcherPLC.java:62) at app.DispatcherPLC.getIntData(DispatcherPLC.java:45) at app.Main.dispatcherPLC(Main.java:52) at app.Main.startApp(Main.java:36) at app.Main.main(Main.java:27) github link: https://github.com/nOy39/S7DataToMySQL
The application will work around the clock on a PC that is connected via TCP / IP with an industrial controller Siemens S7-314, and receive certain data from the PLC, the equipment is switched off at night and turned on at 8 am, respectively, when the equipment is turned off, the application crashes via NullPointerException and when it starts not yet running, I would like the application to hang in the standby mode of turning on the PLC, work in normal mode when the PLC is on, and go off into the standby mode.
if(соединение == null) {ожидать соединения}- not a Programmer