diff --git a/APP_Framework/Applications/control_app/plc_demo/Makefile b/APP_Framework/Applications/control_app/plc_demo/Makefile index afa145fbc..723d7c32c 100755 --- a/APP_Framework/Applications/control_app/plc_demo/Makefile +++ b/APP_Framework/Applications/control_app/plc_demo/Makefile @@ -1,3 +1,3 @@ -SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens +SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Applications/control_app/plc_demo/delta/Makefile b/APP_Framework/Applications/control_app/plc_demo/delta/Makefile index d5d7a1d22..ff5e50962 100755 --- a/APP_Framework/Applications/control_app/plc_demo/delta/Makefile +++ b/APP_Framework/Applications/control_app/plc_demo/delta/Makefile @@ -1,3 +1,3 @@ -SRC_FILES := delta_as228t.c +SRC_FILES := delta_as228t.c delta_as332t.c delta_dvp.c include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Applications/control_app/plc_demo/delta/delta_dvp.c b/APP_Framework/Applications/control_app/plc_demo/delta/delta_dvp.c new file mode 100644 index 000000000..61378ab0e --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/delta/delta_dvp.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/** + * @file delta_dvp.c + * @brief PLC DELTA DVP app + * @version 3.0 + * @author AIIT XUOS Lab + * @date 2022.9.27 + */ + +#include + +extern int Adapter4GActive(void); + +void ControlDeltadvpTest(void) +{ + int i, j = 0; + int read_data_length = 0; + uint8_t read_data[128] = {0}; + +#ifdef CONNECTION_ADAPTER_4G + Adapter4GActive(); +#endif + + ControlProtocolType modbus_tcp_protocol = ControlProtocolFind(); + if (NULL == modbus_tcp_protocol) { + printf("%s get modbus tcp protocol %p failed\n", __func__, modbus_tcp_protocol); + return; + } + + printf("%s get modbus tcp protocol %p successfull\n", __func__, modbus_tcp_protocol); + + if (CONTROL_REGISTERED == modbus_tcp_protocol->protocol_status) { + ControlProtocolOpen(modbus_tcp_protocol); + + for (;;) { + read_data_length = ControlProtocolRead(modbus_tcp_protocol, read_data, sizeof(read_data)); + printf("%s read [%d] modbus tcp data %d using receipe file\n", __func__, i, read_data_length); + if (read_data_length) { + for (j = 0; j < read_data_length; j ++) { + printf("j %d data 0x%x\n", j, read_data[j]); + } + } + i++; + memset(read_data, 0, sizeof(read_data)); + PrivTaskDelay(10000); + } + + //ControlProtocolClose(modbus_tcp_protocol); + } +} +PRIV_SHELL_CMD_FUNCTION(ControlDeltadvpTest, Delta dvp Demo, PRIV_SHELL_CMD_MAIN_ATTR); + + diff --git a/APP_Framework/Applications/control_app/plc_demo/ge/Makefile b/APP_Framework/Applications/control_app/plc_demo/ge/Makefile new file mode 100644 index 000000000..1b9589bee --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/ge/Makefile @@ -0,0 +1,3 @@ +SRC_FILES := ge_versamax001.c + +include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/APP_Framework/Applications/control_app/plc_demo/ge/ge_versamax001.c b/APP_Framework/Applications/control_app/plc_demo/ge/ge_versamax001.c new file mode 100644 index 000000000..c87786a68 --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/ge/ge_versamax001.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/** + * @file ge_versamax001.c + * @brief PLC GE Versamax app + * @version 3.0 + * @author AIIT XUOS Lab + * @date 2022.9.27 + */ + +#include + +extern int Adapter4GActive(void); + +void ControlGeversamaxTest(void) +{ + int i, j = 0; + int read_data_length = 0; + uint8_t read_data[128] = {0}; + +#ifdef CONNECTION_ADAPTER_4G + Adapter4GActive(); +#endif + + ControlProtocolType modbus_rtu_protocol = ControlProtocolFind(); + if (NULL == modbus_rtu_protocol) { + printf("%s get modbus rtu protocol %p failed\n", __func__, modbus_rtu_protocol); + return; + } + + printf("%s get modbus rtu protocol %p successfull\n", __func__, modbus_rtu_protocol); + + if (CONTROL_REGISTERED == modbus_rtu_protocol->protocol_status) { + ControlProtocolOpen(modbus_rtu_protocol); + + for (;;) { + read_data_length = ControlProtocolRead(modbus_rtu_protocol, read_data, sizeof(read_data)); + printf("%s read [%d] modbus rtu data %d using receipe file\n", __func__, i, read_data_length); + if (read_data_length) { + for (j = 0; j < read_data_length; j ++) { + printf("j %d data 0x%x\n", j, read_data[j]); + } + } + i++; + memset(read_data, 0, sizeof(read_data)); + PrivTaskDelay(10000); + } + + //ControlProtocolClose(modbus_rtu_protocol); + } +} +PRIV_SHELL_CMD_FUNCTION(ControlGeversamaxTest, ge versamax001 Demo, PRIV_SHELL_CMD_MAIN_ATTR); + + diff --git a/APP_Framework/Applications/control_app/plc_demo/mitsubishi/Makefile b/APP_Framework/Applications/control_app/plc_demo/mitsubishi/Makefile index 418021732..72090f4f1 100755 --- a/APP_Framework/Applications/control_app/plc_demo/mitsubishi/Makefile +++ b/APP_Framework/Applications/control_app/plc_demo/mitsubishi/Makefile @@ -1,3 +1,3 @@ -SRC_FILES := mitsubishi_fx3u.c mitsubishi_fx5u.c +SRC_FILES := mitsubishi_fx3u.c mitsubishi_fx5u.c mitsubishi_fx2n.c mitsubishi_q02u.c include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Applications/control_app/plc_demo/mitsubishi/mitsubishi_fx2n.c b/APP_Framework/Applications/control_app/plc_demo/mitsubishi/mitsubishi_fx2n.c new file mode 100644 index 000000000..2c1bfb8d4 --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/mitsubishi/mitsubishi_fx2n.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/** + * @file mitsubishi_fx2n.c + * @brief PLC MITSUBISHI FX2N app + * @version 3.0 + * @author AIIT XUOS Lab + * @date 2022.9.27 + */ + +#include + +extern int Adapter4GActive(void); + +void ControlFx2nTest(void) +{ + int i, j = 0; + int read_data_length = 0; + uint8_t read_data[128] = {0}; + +#ifdef CONNECTION_ADAPTER_4G + Adapter4GActive(); +#endif + + ControlProtocolType melsec_1c_protocol = ControlProtocolFind(); + if (NULL == melsec_1c_protocol) { + printf("%s get melsec 1c protocol %p failed\n", __func__, melsec_1c_protocol); + return; + } + + printf("%s get melsec 1c protocol %p successfull\n", __func__, melsec_1c_protocol); + + if (CONTROL_REGISTERED == melsec_1c_protocol->protocol_status) { + ControlProtocolOpen(melsec_1c_protocol); + + for (;;) { + read_data_length = ControlProtocolRead(melsec_1c_protocol, read_data, sizeof(read_data)); + printf("%s read [%d] melsec 1c data %d using receipe file\n", __func__, i, read_data_length); + if (read_data_length) { + for (j = 0; j < read_data_length; j ++) { + printf("j %d data 0x%x\n", j, read_data[j]); + } + } + i++; + memset(read_data, 0, sizeof(read_data)); + PrivTaskDelay(10000); + } + + //ControlProtocolClose(melsec_1c_protocol); + } +} +PRIV_SHELL_CMD_FUNCTION(ControlFx2nTest, Mitsubishi FX2N Demo, PRIV_SHELL_CMD_MAIN_ATTR); + + diff --git a/APP_Framework/Applications/control_app/plc_demo/mitsubishi/mitsubishi_fx3u.c b/APP_Framework/Applications/control_app/plc_demo/mitsubishi/mitsubishi_fx3u.c index 985a5fc61..fab030368 100644 --- a/APP_Framework/Applications/control_app/plc_demo/mitsubishi/mitsubishi_fx3u.c +++ b/APP_Framework/Applications/control_app/plc_demo/mitsubishi/mitsubishi_fx3u.c @@ -32,20 +32,20 @@ void ControlFx3uTest(void) Adapter4GActive(); #endif - ControlProtocolType modbus_tcp_protocol = ControlProtocolFind(); - if (NULL == modbus_tcp_protocol) { - printf("%s get modbus tcp protocol %p failed\n", __func__, modbus_tcp_protocol); + ControlProtocolType melsec_1e_protocol = ControlProtocolFind(); + if (NULL == melsec_1e_protocol) { + printf("%s get melsec 1e protocol %p failed\n", __func__, melsec_1e_protocol); return; } - printf("%s get modbus tcp protocol %p successfull\n", __func__, modbus_tcp_protocol); + printf("%s get melsec 1e protocol %p successfull\n", __func__, melsec_1e_protocol); - if (CONTROL_REGISTERED == modbus_tcp_protocol->protocol_status) { - ControlProtocolOpen(modbus_tcp_protocol); + if (CONTROL_REGISTERED == melsec_1e_protocol->protocol_status) { + ControlProtocolOpen(melsec_1e_protocol); for (;;) { - read_data_length = ControlProtocolRead(modbus_tcp_protocol, read_data, sizeof(read_data)); - printf("%s read [%d] modbus tcp data %d using receipe file\n", __func__, i, read_data_length); + read_data_length = ControlProtocolRead(melsec_1e_protocol, read_data, sizeof(read_data)); + printf("%s read [%d] melsec 1e data %d using receipe file\n", __func__, i, read_data_length); if (read_data_length) { for (j = 0; j < read_data_length; j ++) { printf("j %d data 0x%x\n", j, read_data[j]); diff --git a/APP_Framework/Applications/control_app/plc_demo/mitsubishi/mitsubishi_q02u.c b/APP_Framework/Applications/control_app/plc_demo/mitsubishi/mitsubishi_q02u.c new file mode 100644 index 000000000..751adaf5a --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/mitsubishi/mitsubishi_q02u.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/** + * @file mitsubishi_q02u.c + * @brief PLC MITSUBISHI Q02U app + * @version 3.0 + * @author AIIT XUOS Lab + * @date 2022.9.27 + */ + +#include + +extern int Adapter4GActive(void); + +void ControlQ02uTest(void) +{ + int i, j = 0; + int read_data_length = 0; + uint8_t read_data[128] = {0}; + +#ifdef CONNECTION_ADAPTER_4G + Adapter4GActive(); +#endif + + ControlProtocolType melsec_3e_protocol = ControlProtocolFind(); + if (NULL == melsec_3e_protocol) { + printf("%s get melsec 3e protocol %p failed\n", __func__, melsec_3e_protocol); + return; + } + + printf("%s get melsec 3e protocol %p successfull\n", __func__, melsec_3e_protocol); + + if (CONTROL_REGISTERED == melsec_3e_protocol->protocol_status) { + ControlProtocolOpen(melsec_3e_protocol); + + for (;;) { + read_data_length = ControlProtocolRead(melsec_3e_protocol, read_data, sizeof(read_data)); + printf("%s read [%d] melsec 3c data %d using receipe file\n", __func__, i, read_data_length); + if (read_data_length) { + for (j = 0; j < read_data_length; j ++) { + printf("j %d data 0x%x\n", j, read_data[j]); + } + } + i++; + memset(read_data, 0, sizeof(read_data)); + PrivTaskDelay(10000); + } + + //ControlProtocolClose(melsec_3c_protocol); + } +} +PRIV_SHELL_CMD_FUNCTION(ControlQ02uTest, Mitsubishi Q02U Demo, PRIV_SHELL_CMD_MAIN_ATTR); + + diff --git a/APP_Framework/Applications/control_app/plc_demo/omron/Makefile b/APP_Framework/Applications/control_app/plc_demo/omron/Makefile index 0bd99da9d..ccc3487f7 100755 --- a/APP_Framework/Applications/control_app/plc_demo/omron/Makefile +++ b/APP_Framework/Applications/control_app/plc_demo/omron/Makefile @@ -1,3 +1,3 @@ -SRC_FILES := omron_cj2m.c omron_nj501.c omron_nx102.c +SRC_FILES := omron_cj2m.c omron_nj501.c omron_nx102.c omron_cp1h.c omron_cp1l.c include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Applications/control_app/plc_demo/omron/omron_cp1h.c b/APP_Framework/Applications/control_app/plc_demo/omron/omron_cp1h.c new file mode 100644 index 000000000..ba28d4533 --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/omron/omron_cp1h.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/** + * @file omron_cj2m.c + * @brief PLC OMRON CJ2M app + * @version 3.0 + * @author AIIT XUOS Lab + * @date 2022.9.27 + */ + diff --git a/APP_Framework/Applications/control_app/plc_demo/omron/omron_cp1l.c b/APP_Framework/Applications/control_app/plc_demo/omron/omron_cp1l.c new file mode 100644 index 000000000..814af8f3b --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/omron/omron_cp1l.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/** + * @file omron_.cp1l.c + * @brief PLC OMRON CP1L app + * @version 3.0 + * @author AIIT XUOS Lab + * @date 2023.2.10 + */ +#include + +void ControlOmronCP1LTest(void) +{ + int i = 0; + uint16_t read_data_length = 0; + uint8_t read_data[1024] = {0}; + ControlProtocolType fins_protocol = ControlProtocolFind(); + if (NULL == fins_protocol) { + printf("%s get fins protocol %p failed\n", __func__, fins_protocol); + return; + } + + printf("%s get fins protocol %p successfull\n", __func__, fins_protocol); + + if (CONTROL_REGISTERED == fins_protocol->protocol_status) { + ControlProtocolOpen(fins_protocol); + + for (;;) { + read_data_length = ControlProtocolRead(fins_protocol, read_data, sizeof(read_data)); + printf("%s read [%d] fins data %d using receipe file\n", __func__, i, read_data_length); + i++; + PrivTaskDelay(100000); + } + + //ControlProtocolClose(fins_protocol); + } +} +PRIV_SHELL_CMD_FUNCTION(ControlOmronCP1LTest, Omron Plc FINS Demo, PRIV_SHELL_CMD_MAIN_ATTR); \ No newline at end of file diff --git a/APP_Framework/Applications/control_app/plc_demo/schneider/m241_recipe.json b/APP_Framework/Applications/control_app/plc_demo/schneider/m241_recipe.json new file mode 100644 index 000000000..d87b89834 --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/schneider/m241_recipe.json @@ -0,0 +1,30 @@ +{ + "device_id": 1, + "device_name": "m241", + "communication_type": 1, + "serial_config": { + "station": 1, + "baud_rate": 9600, + "data_bits": 8, + "stop_bits": 1, + "check_mode": 3 + }, + "protocol_type": 3, + "read_period": 100, + "read_item_list": [ + { + "value_name": "MW0", + "value_type": 3, + "function_code": 3, + "start_address": 0, + "quantity": 1 + }, + { + "value_name": "MW1", + "value_type": 3, + "function_code": 3, + "start_address": 1, + "quantity": 1 + } + ] +} \ No newline at end of file diff --git a/APP_Framework/Applications/control_app/plc_demo/schneider/schneider_m241.c b/APP_Framework/Applications/control_app/plc_demo/schneider/schneider_m241.c index 2121da530..60fb1d2b6 100644 --- a/APP_Framework/Applications/control_app/plc_demo/schneider/schneider_m241.c +++ b/APP_Framework/Applications/control_app/plc_demo/schneider/schneider_m241.c @@ -15,9 +15,50 @@ * @brief PLC SCHNEIDER M241 app * @version 3.0 * @author AIIT XUOS Lab - * @date 2022.9.27 + * @date 2023.2.1 */ - +#include + +extern int Adapter4GActive(void); + +void ControlM241Test(void) +{ + int i, j = 0; + int read_data_length = 0; + uint8_t read_data[128] = {0}; + + #ifdef CONNECTION_ADAPTER_4G + Adapter4GActive(); + #endif + + ControlProtocolType modbus_rtu_protocol = ControlProtocolFind(); + if (NULL == modbus_rtu_protocol) { + printf("%s get modbus rtu protocol %p failed\n", __func__, modbus_rtu_protocol); + return; + } + + printf("%s get modbus rtu protocol %p successfull\n", __func__, modbus_rtu_protocol); + + if (CONTROL_REGISTERED == modbus_rtu_protocol->protocol_status) { + ControlProtocolOpen(modbus_rtu_protocol); + + for (;;) { + read_data_length = ControlProtocolRead(modbus_rtu_protocol, read_data, sizeof(read_data)); + printf("%s read [%d] modbus rtu data %d using receipe file\n", __func__, i, read_data_length); + if (read_data_length) { + for (j = 0; j < read_data_length; j ++) { + printf("j %d data 0x%x\n", j, read_data[j]); + } + } + i++; + memset(read_data, 0, sizeof(read_data)); + PrivTaskDelay(10000); + } + + //ControlProtocolClose(modbus_rtu_protocol); + } +} +PRIV_SHELL_CMD_FUNCTION(ControlM241Test, Schneider M241 Demo, PRIV_SHELL_CMD_MAIN_ATTR); diff --git a/APP_Framework/Applications/control_app/plc_demo/xinje/Makefile b/APP_Framework/Applications/control_app/plc_demo/xinje/Makefile new file mode 100755 index 000000000..fcf6b1e27 --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/xinje/Makefile @@ -0,0 +1,3 @@ +SRC_FILES := xsdh-60a32-e.c xdh-60t4-e.c + +include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Applications/control_app/plc_demo/xinje/xdh-60t4-e.c b/APP_Framework/Applications/control_app/plc_demo/xinje/xdh-60t4-e.c new file mode 100644 index 000000000..823be9644 --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/xinje/xdh-60t4-e.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/** + * @file mitsubishi_fx3u.c + * @brief PLC MITSUBISHI FX3U app + * @version 3.0 + * @author AIIT XUOS Lab + * @date 2023.2.1 + */ + diff --git a/APP_Framework/Applications/control_app/plc_demo/xinje/xsdh-60a32-e.c b/APP_Framework/Applications/control_app/plc_demo/xinje/xsdh-60a32-e.c new file mode 100644 index 000000000..ed106879b --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/xinje/xsdh-60a32-e.c @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/** + * @file mitsubishi_fx3u.c + * @brief PLC MITSUBISHI FX3U app + * @version 3.0 + * @author AIIT XUOS Lab + * @date 2023.3.1 + */ diff --git a/APP_Framework/Framework/control/ipc_protocol/modbus_uart/modbus_uart.c b/APP_Framework/Framework/control/ipc_protocol/modbus_uart/modbus_uart.c index bd86ecf0c..f8e41c3b0 100644 --- a/APP_Framework/Framework/control/ipc_protocol/modbus_uart/modbus_uart.c +++ b/APP_Framework/Framework/control/ipc_protocol/modbus_uart/modbus_uart.c @@ -112,15 +112,20 @@ static int ModbusUartGetDataBySerial(ModbusUartReadItem *p_read_item) ModbusUartDataInfo *p_modbus_uart_data_info = &(p_read_item->data_info); BasicPlcDataInfo *p_base_data_info = &(p_modbus_uart_data_info->base_data_info); - ModbusUartFunctionCode function_code = p_modbus_uart_data_info->function_code; + ModbusUartFunctionCode function_code = p_modbus_uart_data_info->function_code; + uint16_t quantity = p_read_item->quantity;//++ ControlPrintfList("SEND", p_base_data_info->p_command, p_base_data_info->command_length); SerialWrite(p_base_data_info->p_command, p_base_data_info->command_length); if (READ_COIL_STATUS == function_code || READ_INPUT_STATUS == function_code) { cmd_length = 6; - } else if (READ_HOLDING_REGISTER == function_code || READ_INPUT_REGISTER == function_code) { + } else if ((READ_HOLDING_REGISTER == function_code || READ_INPUT_REGISTER == function_code) && quantity == 1 ) { cmd_length = 7; + } else if ((READ_HOLDING_REGISTER == function_code || READ_INPUT_REGISTER == function_code) && quantity == 2 ) { + cmd_length = 9; + } else if ((READ_HOLDING_REGISTER == function_code || READ_INPUT_REGISTER == function_code) && quantity == 4 ) { + cmd_length = 13; } else if (WRITE_SINGLE_COIL == function_code || WRITE_SINGLE_REGISTER == function_code) { cmd_length = 8; } else { @@ -369,7 +374,7 @@ static struct ControlDone modbusuart_protocol_done = }; /** - * @description: Modbus TCP Protocol Cmd Generate + * @description: Modbus Uart Protocol Cmd Generate * @param p_recipe - recipe pointer * @param protocol_format_info - protocol format info pointer * @return success : 0 error : -1 @@ -402,7 +407,7 @@ int ModbusUartProtocolFormatCmd(struct ControlRecipe *p_recipe, ProtocolFormatIn } /** - * @description: Modbus TCP Protocol Init + * @description: Modbus Uart Protocol Init * @param p_recipe - recipe pointer * @return success : 0 error : -1 */ diff --git a/APP_Framework/Framework/control/plc_protocol/melsec/melsec.c b/APP_Framework/Framework/control/plc_protocol/melsec/melsec.c index 27b97a831..01a25420f 100644 --- a/APP_Framework/Framework/control/plc_protocol/melsec/melsec.c +++ b/APP_Framework/Framework/control/plc_protocol/melsec/melsec.c @@ -270,7 +270,7 @@ static uint16_t Melsec3eqlGenerateCommand(uint8_t *p_command, uint32_t command_c uint16_t head_device_number = 0; for (uint8_t i = 0; i < 6; i++) { if (0 != p_read_item->head_device_number_string[i]) - head_device_number = TransformAsciiToHex(p_read_item->head_device_number_string[i]) + head_device_number * (((0x9c == (uint8_t)p_read_item->device_code) || (0x9d == (uint8_t)p_read_item->device_code)) ? 16 : 10); + head_device_number = TransformAsciiToHex(p_read_item->head_device_number_string[i]) + head_device_number * (((0x9c == (uint8_t)p_read_item->device_code) || (0x9d == (uint8_t)p_read_item->device_code) || (0xa0 == (uint8_t)p_read_item->device_code) || (0xb4 == (uint8_t)p_read_item->device_code)) ? 16 : 10); else break; } @@ -297,7 +297,7 @@ static uint16_t Melsec3eiqrGenerateCommand(uint8_t *p_command, uint32_t command_ uint16_t head_device_number = 0; for (uint8_t i = 0; i < 6; i++) { if (0 != p_read_item->head_device_number_string[i]) - head_device_number = TransformAsciiToHex(p_read_item->head_device_number_string[i]) + head_device_number * (((0x9c == (uint8_t)p_read_item->device_code) || (0x9d == (uint8_t)p_read_item->device_code)) ? 16 : 10); + head_device_number = TransformAsciiToHex(p_read_item->head_device_number_string[i]) + head_device_number * (((0x9c == (uint8_t)p_read_item->device_code) || (0x9d == (uint8_t)p_read_item->device_code)|| (0xa0 == (uint8_t)p_read_item->device_code)|| (0xb4 == (uint8_t)p_read_item->device_code)) ? 16 : 10); else break; } @@ -567,7 +567,7 @@ static int MelsecTransformRecvBuffToData(MelsecReadItem *p_read_item, uint8_t *r p_data[2 * i] = TransformAsciiToHex(recv_buff[recv_buff_index]) * 16 + TransformAsciiToHex(recv_buff[recv_buff_index + 1]); p_data[2 * i + 1] = TransformAsciiToHex(recv_buff[recv_buff_index + 2]) * 16 + TransformAsciiToHex(recv_buff[recv_buff_index + 3]); } - printf("0x%x 0x%x", p_data[2 * i], p_data[2 * i + 1]); + printf("0x%x 0x%x ", p_data[2 * i], p_data[2 * i + 1]); } } printf("\n"); @@ -629,16 +629,51 @@ static int MelsecGetDataBySocket(int32_t socket, MelsecReadItem *p_read_item) */ static int MelsecGetDataBySerial(MelsecReadItem *p_read_item) { - uint32_t read_length = 0; + uint32_t cmd_length,read_length = 0; memset(recv_buff, 0, sizeof(recv_buff)); MelsecDataInfo *p_melsec_data_info = &(p_read_item->data_info); - BasicPlcDataInfo *p_base_data_info = &(p_melsec_data_info->base_data_info); + BasicPlcDataInfo *p_base_data_info = &(p_melsec_data_info->base_data_info); + MelsecCommandType melsec_command_type = p_melsec_data_info->command_type;//++ + MelsecFrameType melsec_frame_type= p_melsec_data_info->frame_type;//++ + + uint16_t device_points_count = p_read_item->device_points_count;//++ ControlPrintfList("SEND", p_base_data_info->p_command, p_base_data_info->command_length); SerialWrite(p_base_data_info->p_command, p_base_data_info->command_length); + //++ + if (MELSEC_1C_FRAME == melsec_frame_type) { + if (READ_IN_BITS == melsec_command_type ) { + cmd_length = 9; + } else if (READ_IN_WORD == melsec_command_type && device_points_count==1 ) { + cmd_length = 12; + } else if (READ_IN_WORD == melsec_command_type && device_points_count==2 ) { + cmd_length = 16; + } else if (READ_IN_WORD == melsec_command_type && device_points_count==4 ) { + cmd_length = 24; + } else { + //MULTIPLE_COIL and MULTIPLE_REGISTER to do + cmd_length = 0; + } + }else if(MELSEC_3C_FRAME == melsec_frame_type){ + if (READ_IN_BITS == melsec_command_type ) { + cmd_length = 15; + } else if (READ_IN_WORD == melsec_command_type && device_points_count==1 ) { + cmd_length = 18; + } else if (READ_IN_WORD == melsec_command_type && device_points_count==2 ) { + cmd_length = 22; + } else if (READ_IN_WORD == melsec_command_type && device_points_count==4 ) { + cmd_length = 30; + } else { + //MULTIPLE_COIL and MULTIPLE_REGISTER to do + cmd_length = 0; + } - read_length = SerialRead(recv_buff, sizeof(recv_buff)); + } +//++ + + + read_length = SerialRead(recv_buff, cmd_length); if (read_length) { ControlPrintfList("RECV", recv_buff, read_length); return MelsecTransformRecvBuffToData(p_read_item, recv_buff);