From e775e1a5b9fb110a2be136d1eb4e85d66f8c2cee Mon Sep 17 00:00:00 2001 From: Jeffrey_Li <412100639@qq.com> Date: Mon, 12 Jun 2023 00:08:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=BC=8F=E4=BC=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cigarette/PLC/PLCDevice.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Cigarette/PLC/PLCDevice.cpp b/Cigarette/PLC/PLCDevice.cpp index 661f147..20d95aa 100644 --- a/Cigarette/PLC/PLCDevice.cpp +++ b/Cigarette/PLC/PLCDevice.cpp @@ -7,7 +7,7 @@ extern SysConf g_sys_conf; -modbus_t * g_modbus; //Modbus TCP +modbus_t * g_modbus = NULL; //Modbus TCP bool PLCDevice::init_plc(PLCDevice* PLCptr) { @@ -29,8 +29,11 @@ bool PLCDevice::init_plc(PLCDevice* PLCptr) } bool PLCDevice::disconnect_plc(void) { - modbus_close(g_modbus); - modbus_free(g_modbus); + if(g_modbus) + { + modbus_close(g_modbus); + modbus_free(g_modbus); + } return true; } int PLCDevice::write_bit_2_plc(int addr, int value)