diff --git a/APP_Framework/Applications/control_app/Makefile b/APP_Framework/Applications/control_app/Makefile index 2369ecaae..3661a817d 100755 --- a/APP_Framework/Applications/control_app/Makefile +++ b/APP_Framework/Applications/control_app/Makefile @@ -1,5 +1,4 @@ SRC_DIR := plc_demo -SRC_DIR += modbus_tcp_server_demo ifeq ($(CONFIG_RESOURCES_LWIP),y) diff --git a/APP_Framework/Applications/control_app/modbus_tcp_server_demo/freemodbustcpserver.c b/APP_Framework/Applications/control_app/modbus_tcp_server_demo/freemodbustcpserver.c deleted file mode 100644 index edbf64a5f..000000000 --- a/APP_Framework/Applications/control_app/modbus_tcp_server_demo/freemodbustcpserver.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 freemodbustcpserver.c - * @brief PLC fREEMODBUSTCP SERVER app - * @version 3.0 - * @author AIIT XUOS Lab - * @date 2023.7.31 - */ - -#include - -void ControlMtcpsTest(void) -{ - int i, j = 1; - int read_data_length = 0; - uint8_t read_data[128] = {0}; - ControlProtocolType freemodbus_tcp_protocol = ControlProtocolFind(); - if (NULL == freemodbus_tcp_protocol) { - printf("%s get freemodbus tcp protocol %p failed\n", __func__, freemodbus_tcp_protocol); - return; - } - printf("%s get freemodbus tcp protocol %p successfull\n", __func__, freemodbus_tcp_protocol); - - printf("%4X %4X %4X\n",freemodbus_tcp_protocol->name,freemodbus_tcp_protocol->recipe,freemodbus_tcp_protocol->done); - - if (CONTROL_REGISTERED == freemodbus_tcp_protocol->protocol_status) { - ControlProtocolOpen(freemodbus_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(ControlMtcpsTest, M Demo, PRIV_SHELL_CMD_MAIN_ATTR); \ No newline at end of file diff --git a/APP_Framework/Applications/control_app/plc_demo/Makefile b/APP_Framework/Applications/control_app/plc_demo/Makefile index 2ecd7fa53..3fba029fa 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 ge xinje inovance keyence ab +SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje inovance keyence ab abb include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Applications/control_app/plc_demo/ab/Makefile b/APP_Framework/Applications/control_app/plc_demo/ab/Makefile index 41f97a516..6d8383b89 100755 --- a/APP_Framework/Applications/control_app/plc_demo/ab/Makefile +++ b/APP_Framework/Applications/control_app/plc_demo/ab/Makefile @@ -1,3 +1,3 @@ -SRC_FILES := ab_l30.c +SRC_FILES := ab_l30erm.c ab_micro850.c include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Applications/control_app/plc_demo/ab/README_ab_850.md b/APP_Framework/Applications/control_app/plc_demo/ab/README_ab_850.md new file mode 100755 index 000000000..329ca65ae --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/ab/README_ab_850.md @@ -0,0 +1,91 @@ +# AB_850通信测试 + +[TOC] + +## 通信接线及参数设置 + +* 网口 + + *Mosbus TCP协议,IP:192.168.250.56,Port:502 + +## 存储区 + +- 存储区D区 + +## JSON配方设计 + +* AB_850类型PLC需要配置控制器映射 + + ![](./image/modbus映射.png) + +* 共测试Word和real共2种类型数据,real型数据有2个Word组成,以下为JSON文件解释。 + + - ```json + { + "device_id": 1, //设备ID默认是1,此参数无效 + "device_name": "AB_850", //设备名称,自定义 + "communication_type": 0, //通讯协议类型 0是以太网,1是串口 + "socket_config": { //以太网配置 + "plc_ip": "192.168.250.56", //PLC的IP地址 + "local_ip": "192.168.250.233", //矽达通IP地址设定 + "gateway": "192.168.250.1", //矽达通的网关地址设定 + "netmask": "255.255.255.0", //矽达通子网掩码设定 + "port":502 //端口号设定 + }, + "protocol_type": 2, //通讯协议,2代表modbus-tcp协议 + "read_period": 100, //交互周期ms + "read_item_list": [ + { + "value_name": "CON_DATA[0]", //变量名称,自定义 + "value_type": 1, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "function_code": 1, //功能码。1是读线圈 + "start_address": 0, //起始地址 + "data_length": 1 //默认是1,代表读取1个数据类型长度 + }, + { + "value_name": "CON_DATA[1]", //变量名称,自定义 + "value_type": 1, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "function_code": 1, //功能码。1是读 + "start_address": 1, //起始地址偏移1位106*8+1=849 + "data_length": 1 //默认是1,代表读取1个数据类型长度 + }, + { + "value_name": "CON_INT", //变量名称,自定义 + "value_type": 3, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "function_code": 3, //功能码。3是读 + "start_address": 2, //起始地址偏移2位 + "data_length": 1 //默认是1,代表读取1个数据类型长度 + }, + { + "value_name": "CON_ARRAY[0]_1", //变量名称,自定义 + "value_type": 3, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "function_code": 3, //功能码。3是读 + "start_address": 3, //起始地址偏移3位 + "data_length": 1 //默认是1,代表读取1个数据类型长度 + }, + { + "value_name": "CON_ARRAY[0]_2", //变量名称,自定义,CON_ARRAY[0]_1和CON_ARRAY[0]_2组成real型数据 + "value_type": 3, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "function_code": 3, //功能码。3是读 + "start_address": 4, //起始地址偏移4位 + "data_length": 1 //默认是1,代表读取1个数据类型长度 + } + ] + } + ``` + +## 通信测试 + + (1) 新增1个通信demo,命名为ab_micro850.c; + + (2) 复制modbus_tcp样例代码程序到ab_micro850.c文件中; + + (3) void **ControlAB850Test**(void) 更改函数名; + + (4) PRIV_SHELL_CMD_FUNCTION(**ControlAB850Test**, AB Plc micro850 Demo**, PRIV_SHELL_CMD_MAIN_ATTR);更改测试指令; + + (5) 剪裁配置完成后,用过烧写器下载至矽数通中,重启后完成测试。 + + + + diff --git a/APP_Framework/Applications/control_app/plc_demo/ab/README_ab_l300erm.md b/APP_Framework/Applications/control_app/plc_demo/ab/README_ab_l300erm.md new file mode 100755 index 000000000..7f814d573 --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/ab/README_ab_l300erm.md @@ -0,0 +1,71 @@ +# AB_L30ERM通信测试 + +[TOC] + +## 通信接线及参数设置 + +* 网口 + + *Ethernet/ip协议,IP:192.168.250.57,Port:44818 + +## 存储区 + +- Ethernet/ip协议是根据变量名称搜索寄存器地址 + +## JSON配方设计 + +* 本实例共测试Word和real共2种类型数据,以下为JSON文件解释。 + + - ```json + { + "device_id": “ab_l30”, // + "device_name": "robot", //设备名称,自定义 + "communication_type": 0, //通讯协议类型 0是以太网,1是串口 + "socket_config": { //以太网配置 + "plc_ip": "192.168.250.37", //PLC的IP地址 + "local_ip": "192.168.250.123", //矽达通IP地址设定 + "gateway": "192.168.250.1", //矽达通的网关地址设定 + "netmask": "255.255.255.0", //矽达通子网掩码设定 + "port":502 //端口号设定 + }, + "protocol_type": 12, //通讯协议,12代表ethernet/ip协议 + "read_period": 100, //交互周期ms + "read_item_list": [ + { + "value_name": "L30_SPEED", //变量名称,自定义 + "value_type": 3, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "wordlen": "WORD", //以WORD方式传输 + "amount": 1 //默认是1,代表读取1个数据类型长度 + }, + { + "value_name": "L30_TORQUE", //变量名称,自定义 + "value_type": 9, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "wordlen": 2, //以WORD方式传输 + "amount": 1 //默认是1,代表读取1个数据类型长度 + }, + { + "value_name": "D", //变量名称,自定义 + "value_type": 3, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "wordlen": 3, //以WORD方式传输 + "amount": 1 //默认是1,代表读取1个数据类型长度 + } + ] + } + ``` + + +## 通信测试 + + (1) 新增1个通信demo,命名为ab_l30erm.c; + + (2) 复制modbus_tcp样例代码程序到ab_l30erm.c文件中; + + (3) void **ControlABL30Test**(void) 更改函数名; + + (4) PRIV_SHELL_CMD_FUNCTION(**ControlABL30Test**, AB Plc l30ermDemo**, PRIV_SHELL_CMD_MAIN_ATTR);更改测试指令; + + (5) 剪裁配置完成后,用过烧写器下载至矽数通中,重启后完成测试。 + + + + diff --git a/APP_Framework/Applications/control_app/plc_demo/ab/ab_l30.c b/APP_Framework/Applications/control_app/plc_demo/ab/ab_l30erm.c similarity index 92% rename from APP_Framework/Applications/control_app/plc_demo/ab/ab_l30.c rename to APP_Framework/Applications/control_app/plc_demo/ab/ab_l30erm.c index 49c767f3c..65c56d780 100644 --- a/APP_Framework/Applications/control_app/plc_demo/ab/ab_l30.c +++ b/APP_Framework/Applications/control_app/plc_demo/ab/ab_l30erm.c @@ -15,12 +15,12 @@ * @brief PLC ABB L30 app * @version 3.0 * @author AIIT XUOS Lab - * @date 2022.9.27 + * @date 2023.8.27 */ #include -void Controlabl30Test(void) +void ControlABL30Test(void) { int i = 0; uint16_t read_data_length = 0; @@ -45,4 +45,4 @@ void Controlabl30Test(void) //ControlProtocolClose(CIP_protocol); } } -PRIV_SHELL_CMD_FUNCTION(Controlabl30Test, Ab Plc CIP Demo, PRIV_SHELL_CMD_MAIN_ATTR); +PRIV_SHELL_CMD_FUNCTION(ControlABL30Test, Ab Plc CIP Demo, PRIV_SHELL_CMD_MAIN_ATTR); diff --git a/APP_Framework/Applications/control_app/plc_demo/ab/ab_micro850.c b/APP_Framework/Applications/control_app/plc_demo/ab/ab_micro850.c new file mode 100644 index 000000000..5ea00ac0e --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/ab/ab_micro850.c @@ -0,0 +1,52 @@ +/* + * 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 ab_micro850.c + * @brief PLC AB MICRO850 app + * @version 3.0 + * @author AIIT XUOS Lab + * @date 2023.10.5 + */ + +#include + +void ControlAB850Test(void) +{ + int i, j = 0; + int read_data_length = 0; + uint8_t read_data[128] = {0}; + 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(ControlAB850Test, AB Plc MICRO850 Demo, PRIV_SHELL_CMD_MAIN_ATTR); \ No newline at end of file diff --git a/APP_Framework/Applications/control_app/plc_demo/ab/image/L30ERM.jpg b/APP_Framework/Applications/control_app/plc_demo/ab/image/L30ERM.jpg new file mode 100644 index 000000000..db7e41e18 Binary files /dev/null and b/APP_Framework/Applications/control_app/plc_demo/ab/image/L30ERM.jpg differ diff --git a/APP_Framework/Applications/control_app/plc_demo/ab/image/MICRO850.jpg b/APP_Framework/Applications/control_app/plc_demo/ab/image/MICRO850.jpg new file mode 100644 index 000000000..baebe73e6 Binary files /dev/null and b/APP_Framework/Applications/control_app/plc_demo/ab/image/MICRO850.jpg differ diff --git a/APP_Framework/Applications/control_app/plc_demo/ab/image/modbus映射.png b/APP_Framework/Applications/control_app/plc_demo/ab/image/modbus映射.png new file mode 100644 index 000000000..7cbf50b67 Binary files /dev/null and b/APP_Framework/Applications/control_app/plc_demo/ab/image/modbus映射.png differ diff --git a/APP_Framework/Applications/control_app/plc_demo/ab/json/test_recipe_L30.json b/APP_Framework/Applications/control_app/plc_demo/ab/json/test_recipe_L30.json new file mode 100644 index 000000000..852788b5d --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/ab/json/test_recipe_L30.json @@ -0,0 +1,34 @@ +{ + "device_id": "ab_l30", + "device_name": "robot", + "communication_type": 0, + "socket_config": { + "plc_ip": "192.168.250.57", + "local_ip": "192.168.250.123", + "gateway": "192.168.250.1", + "netmask": "255.255.255.0", + "port": 44818 + }, + "protocol_type": 12, + "read_period": 100, + "read_item_list": [ + { + "value_name": "L30_SPEED", + "value_type": 3, + "wordlen": "WORD", + "amount": 1 + }, + { + "value_name": "L30_TORQUE", + "value_type": 9, + "wordlen": "WORD", + "amount": 1 + }, + { + "value_name": "D", + "value_type": 3, + "wordlen": "WORD", + "amount": 1 + } + ] +} \ No newline at end of file diff --git a/APP_Framework/Applications/control_app/plc_demo/ab/json/test_recipe_ab_850.json b/APP_Framework/Applications/control_app/plc_demo/ab/json/test_recipe_ab_850.json new file mode 100644 index 000000000..c051d2321 --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/ab/json/test_recipe_ab_850.json @@ -0,0 +1,51 @@ +{ + "device_id": 1, + "device_name": "AB_850", + "communication_type": 0, + "socket_config": { + "plc_ip": "192.168.250.32", + "local_ip": "192.168.250.56", + "gateway": "192.168.250.1", + "netmask": "255.255.255.0", + "port": 502 + }, + "protocol_type": 2, + "read_period": 100, + "read_item_list": [ + { + "value_name": "D106.0", + "value_type": 1, + "function_code": 1, + "start_address": 848, + "quantity": 1 + }, + { + "value_name": "D106.1", + "value_type": 1, + "function_code": 1, + "start_address":849, + "quantity": 1 + }, + { + "value_name": "D100", + "value_type": 3, + "function_code": 3, + "start_address": 100, + "quantity": 1 + }, + { + "value_name": "D102", + "value_type": 3, + "function_code": 3, + "start_address": 102, + "quantity": 1 + }, + { + "value_name": "D103", + "value_type": 3, + "function_code": 3, + "start_address": 103, + "quantity": 1 + } + ] +} \ No newline at end of file diff --git a/APP_Framework/Applications/control_app/modbus_tcp_server_demo/Makefile b/APP_Framework/Applications/control_app/plc_demo/abb/Makefile similarity index 50% rename from APP_Framework/Applications/control_app/modbus_tcp_server_demo/Makefile rename to APP_Framework/Applications/control_app/plc_demo/abb/Makefile index 428b13b74..3ef527c15 100755 --- a/APP_Framework/Applications/control_app/modbus_tcp_server_demo/Makefile +++ b/APP_Framework/Applications/control_app/plc_demo/abb/Makefile @@ -1,3 +1,3 @@ -SRC_FILES := freemodbustcpserver.c +SRC_FILES := abb_pm5630.c include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Applications/control_app/plc_demo/abb/README.md b/APP_Framework/Applications/control_app/plc_demo/abb/README.md new file mode 100644 index 000000000..21b3bbff2 --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/abb/README.md @@ -0,0 +1,87 @@ +# ABB通信测试 + +[TOC] + +## 通信接线及参数设置 + +* 网口 + + *Mosbus TCP协议,IP:192.168.250.58,Port:502 + +## 存储区 + +- 存储区MW区 + +## JSON配方设计 + +* 共测试Word和real共2种类型数据,real型数据有2个Word组成,以下为JSON文件解释。 + + - ```json + { + "device_id": 1, //设备ID默认是1,此参数无效 + "device_name": "ABB_PM5630", //设备名称,自定义 + "communication_type": 0, //通讯协议类型 0是以太网,1是串口 + "socket_config": { //以太网配置 + "plc_ip": "192.168.250.58", //PLC的IP地址 + "local_ip": "192.168.250.233", //矽达通IP地址设定 + "gateway": "192.168.250.1", //矽达通的网关地址设定 + "netmask": "255.255.255.0", //矽达通子网掩码设定 + "port":502 //端口号设定 + }, + "protocol_type": 2, //通讯协议,2代表modbus-tcp协议 + "read_period": 100, //交互周期ms + "read_item_list": [ + { + "value_name": "MW0", //变量名称,自定义 + "value_type": 3, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "function_code": 3, //功能码。3是读 + "start_address": 0, //起始地址 + "data_length": 1 //默认是1,代表读取1个数据类型长度 + }, + { + "value_name": "MW1", //变量名称,自定义 + "value_type": 3, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "function_code": 3, //功能码。3是读 + "start_address": 1, //起始地址偏移1位 + "data_length": 1 //默认是1,代表读取1个数据类型长度 + }, + { + "value_name": "MW10", //变量名称,自定义 + "value_type": 3, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "function_code": 3, //功能码。3是读 + "start_address": 10, //起始地址偏移10位 + "data_length": 1 //默认是1,代表读取1个数据类型长度 + }, + { + "value_name": "MD20_1", //变量名称,自定义 + "value_type": 3, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "function_code": 3, //功能码。3是读 + "start_address": 20, //起始地址偏移20位 + "data_length": 1 //默认是1,代表读取1个数据类型长度 + }, + { + "value_name": "MD20_2", //变量名称,自定义,MD20_1和MD20_2组成real型数据 + "value_type": 3, //变量类型,BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9 + "function_code": 3, //功能码。3是读 + "start_address": 21, //起始地址偏移21位 + "data_length": 1 //默认是1,代表读取1个数据类型长度 + } + ] + } + ``` + +## 通信测试 + + (1) 新增1个通信demo,命名为abb_pm5630.c; + + (2) 复制modbus_tcp样例代码程序到abb_pm5630.c文件中; + + (3) void **ControlABBPM5630Test**(void) 更改函数名; + + (4) PRIV_SHELL_CMD_FUNCTION(**ControlABBPM5630Test**, ABB Plc PM5630 Demo**, PRIV_SHELL_CMD_MAIN_ATTR);更改测试指令; + + (5) 剪裁配置完成后,用过烧写器下载至矽数通中,重启后完成测试。 + + + + diff --git a/APP_Framework/Applications/control_app/plc_demo/abb/abb_pm5630.c b/APP_Framework/Applications/control_app/plc_demo/abb/abb_pm5630.c new file mode 100644 index 000000000..b7c50e152 --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/abb/abb_pm5630.c @@ -0,0 +1,52 @@ +/* + * 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 abb_pm5630.c + * @brief PLC ABB pm5630 app + * @version 3.0 + * @author AIIT XUOS Lab + * @date 2023.10.20 + */ + +#include + +void ControlABBPM5630Test(void) +{ + int i, j = 0; + int read_data_length = 0; + uint8_t read_data[128] = {0}; + 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(ControlABBPM5630Test, ABB Plc PM5630 Demo, PRIV_SHELL_CMD_MAIN_ATTR); \ No newline at end of file diff --git a/APP_Framework/Applications/control_app/plc_demo/abb/image/ABB_PM5630.jpg b/APP_Framework/Applications/control_app/plc_demo/abb/image/ABB_PM5630.jpg new file mode 100644 index 000000000..1b7ffcea6 Binary files /dev/null and b/APP_Framework/Applications/control_app/plc_demo/abb/image/ABB_PM5630.jpg differ diff --git a/APP_Framework/Applications/control_app/plc_demo/abb/json/test_recipe_abb_PM5630.json b/APP_Framework/Applications/control_app/plc_demo/abb/json/test_recipe_abb_PM5630.json new file mode 100644 index 000000000..f41e5cfac --- /dev/null +++ b/APP_Framework/Applications/control_app/plc_demo/abb/json/test_recipe_abb_PM5630.json @@ -0,0 +1,51 @@ +{ + "device_id": 1, + "device_name": "ABB_PM5630", + "communication_type": 0, + "socket_config": { + "plc_ip": "192.168.250.32", + "local_ip": "192.168.250.58", + "gateway": "192.168.250.1", + "netmask": "255.255.255.0", + "port": 502 + }, + "protocol_type": 2, + "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 + }, + { + "value_name": "MW10", + "value_type": 3, + "function_code": 3, + "start_address": 10, + "quantity": 1 + }, + { + "value_name": "MD20_1", + "value_type": 3, + "function_code": 3, + "start_address":20, + "quantity": 1 + }, + { + "value_name": "MD20_2", + "value_type": 3, + "function_code": 3, + "start_address":21, + "quantity": 1 + } + ] +} \ No newline at end of file diff --git a/APP_Framework/Framework/connection/industrial_network/Kconfig b/APP_Framework/Framework/connection/industrial_network/Kconfig index 2795791b1..23d69660a 100644 --- a/APP_Framework/Framework/connection/industrial_network/Kconfig +++ b/APP_Framework/Framework/connection/industrial_network/Kconfig @@ -21,4 +21,3 @@ config CONNECTION_ADAPTER_FREEMODBUSTCP if CONNECTION_ADAPTER_FREEMODBUSTCP source "$APP_DIR/Framework/connection/industrial_network/freemodbus_tcp/Kconfig" endif - \ No newline at end of file diff --git a/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/LwipTcpRecvTest b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/LwipTcpRecvTest deleted file mode 100644 index 2c28feb04..000000000 --- a/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/LwipTcpRecvTest +++ /dev/null @@ -1,92 +0,0 @@ - - -void LwipTcpRecvTest(void) -{ - uint8_t enet_port = 0; ///< test enet port 0 - - lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr); - - uint8_t *recv_data; - socklen_t sin_size; - int sock = -1, connected, bytes_received, i; - struct sockaddr_in server_addr, client_addr; - fd_set readset; - struct timeval timeout; - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock < 0) { - KPrintf("[%s:%d] Socket error!\n", __FILE__, __LINE__); - goto __exit; - } - - recv_data = (uint8_t *)malloc(128); - if (recv_data == NULL) { - KPrintf("No memory!\n"); - goto __exit; - } - - //configure tcp server param - server_addr.sin_family = AF_INET; - server_addr.sin_port = htons(tcp_server_port); - server_addr.sin_addr.s_addr = INADDR_ANY; - memset(&(server_addr.sin_zero), 0x0, sizeof(server_addr.sin_zero)); - - if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) { - KPrintf("Unable to bind!\n"); - goto __exit; - } - - if (listen(sock, 5) == -1) { - KPrintf("Listen error!\n"); - goto __exit; - } - - timeout.tv_sec = 30; - timeout.tv_usec = 0; - - if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) ==-1) { - KPrintf("setsockopt failed!"); - goto __exit; - } - - while (1) { - FD_ZERO(&readset); - FD_SET(sock, &readset); - - if (select(sock + 1, &readset, NULL, NULL, &timeout) == 0) { - continue; - } - - sin_size = sizeof(struct sockaddr_in); - connected = accept(sock, (struct sockaddr *)&client_addr, &sin_size); - while (1) { - bytes_received = recv(connected, recv_data, 128, 0); - if (bytes_received == 0) { - KPrintf("client disconnected (%s, %d)\n",inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); - break; - } else if (bytes_received < 0) { - KPrintf("recv error, client: (%s, %d)\n",inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); - break; - } else { - KPrintf("new client connected from (%s, %d)\n",inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); - KPrintf("recv data length %d Bytes\n", bytes_received); - for (i = 0; i < bytes_received; i ++) { - KPrintf("data 0x%x\n", recv_data[i]); - } - if (i = bytes_received) { - KPrintf("\r\n"); - memset(recv_data, 0, sizeof(recv_data)); - } - } - } - if (connected >= 0) { - closesocket(connected); - connected = -1; - break; - } - - __exit: - if (sock >= 0) closesocket(sock); - if (recv_data) free(recv_data); -} -SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | -SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),TCPRecv, LwipTcpRecvTest, TCP Recv message); \ No newline at end of file diff --git a/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/tcpserver_sample.c b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/tcpserver_sample.c index 5526acae5..ed5d12369 100644 --- a/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/tcpserver_sample.c +++ b/APP_Framework/Framework/connection/industrial_network/freemodbus_tcp/tcpserver_sample.c @@ -112,7 +112,6 @@ int MBServer() MdelayKTask(100); } } - return iExitCode; } diff --git a/APP_Framework/Framework/control/ipc_protocol/Kconfig b/APP_Framework/Framework/control/ipc_protocol/Kconfig index b6fd0d13f..8454c0a6a 100755 --- a/APP_Framework/Framework/control/ipc_protocol/Kconfig +++ b/APP_Framework/Framework/control/ipc_protocol/Kconfig @@ -14,3 +14,11 @@ if CONTROL_PROTOCOL_MODBUS_UART source "$APP_DIR/Framework/control/ipc_protocol/modbus_uart/Kconfig" endif +config CONTROL_PROTOCOL_ETHERCAT + bool "Using ethercat control protocol" + default n + select CONTROL_USING_SOCKET +if CONTROL_PROTOCOL_ETHERCAT + source "$APP_DIR/Framework/control/ipc_protocol/ethercat/Kconfig" +endif + diff --git a/APP_Framework/Framework/control/ipc_protocol/Makefile b/APP_Framework/Framework/control/ipc_protocol/Makefile index a22240e9a..d0459bceb 100755 --- a/APP_Framework/Framework/control/ipc_protocol/Makefile +++ b/APP_Framework/Framework/control/ipc_protocol/Makefile @@ -6,5 +6,9 @@ ifeq ($(CONFIG_CONTROL_PROTOCOL_MODBUS_UART), y) SRC_DIR := modbus_uart endif +ifeq ($(CONFIG_CONTROL_PROTOCOL_ETHERCAT), y) + SRC_DIR := ethercat +endif + include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/control/plc_protocol/Kconfig b/APP_Framework/Framework/control/plc_protocol/Kconfig index ba3672ac9..0e7c20377 100755 --- a/APP_Framework/Framework/control/plc_protocol/Kconfig +++ b/APP_Framework/Framework/control/plc_protocol/Kconfig @@ -33,5 +33,6 @@ config CONTROL_PROTOCOL_CIP default n select CONTROL_USING_SOCKET if CONTROL_PROTOCOL_CIP - source "$APP_DIR/Framework/control/plc_protocol/cip/Kconfig" + source "$APP_DIR/Framework/control/plc_protocol/ethernet_ip_cip/Kconfig" endif + diff --git a/APP_Framework/Framework/control/plc_protocol/Makefile b/APP_Framework/Framework/control/plc_protocol/Makefile index 3de046143..250a715e9 100755 --- a/APP_Framework/Framework/control/plc_protocol/Makefile +++ b/APP_Framework/Framework/control/plc_protocol/Makefile @@ -15,7 +15,7 @@ ifeq ($(CONFIG_CONTROL_PROTOCOL_S7), y) endif ifeq ($(CONFIG_CONTROL_PROTOCOL_CIP), y) - SRC_DIR := cip + SRC_DIR := ethernet_ip_cip endif include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/control/plc_protocol/cip/Kconfig b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/Kconfig similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/Kconfig rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/Kconfig diff --git a/APP_Framework/Framework/control/plc_protocol/cip/Makefile b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/Makefile similarity index 98% rename from APP_Framework/Framework/control/plc_protocol/cip/Makefile rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/Makefile index dbfeab3b3..a72b1a41e 100644 --- a/APP_Framework/Framework/control/plc_protocol/cip/Makefile +++ b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/Makefile @@ -1,2 +1,3 @@ SRC_FILES := $(wildcard ./*.c) + include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/control/plc_protocol/cip/ab_cip.c b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_cip.c similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/ab_cip.c rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_cip.c diff --git a/APP_Framework/Framework/control/plc_protocol/cip/ab_cip.h b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_cip.h similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/ab_cip.h rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_cip.h diff --git a/APP_Framework/Framework/control/plc_protocol/cip/ab_cip_helper.c b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_cip_helper.c similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/ab_cip_helper.c rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_cip_helper.c diff --git a/APP_Framework/Framework/control/plc_protocol/cip/ab_cip_helper.h b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_cip_helper.h similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/ab_cip_helper.h rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_cip_helper.h diff --git a/APP_Framework/Framework/control/plc_protocol/cip/ab_cip_private.h b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_cip_private.h similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/ab_cip_private.h rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_cip_private.h diff --git a/APP_Framework/Framework/control/plc_protocol/cip/ab_plc_cip_net.sln b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_plc_cip_net.sln similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/ab_plc_cip_net.sln rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_plc_cip_net.sln diff --git a/APP_Framework/Framework/control/plc_protocol/cip/ab_plc_cip_net.vcxproj b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_plc_cip_net.vcxproj similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/ab_plc_cip_net.vcxproj rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/ab_plc_cip_net.vcxproj diff --git a/APP_Framework/Framework/control/plc_protocol/cip/cip.c b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/cip.c similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/cip.c rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/cip.c diff --git a/APP_Framework/Framework/control/plc_protocol/cip/cip_socket.c b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/cip_socket.c similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/cip_socket.c rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/cip_socket.c diff --git a/APP_Framework/Framework/control/plc_protocol/cip/cip_socket.h b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/cip_socket.h similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/cip_socket.h rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/cip_socket.h diff --git a/APP_Framework/Framework/control/plc_protocol/cip/typedef.h b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/typedef.h similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/typedef.h rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/typedef.h diff --git a/APP_Framework/Framework/control/plc_protocol/cip/utill.c b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/utill.c similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/utill.c rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/utill.c diff --git a/APP_Framework/Framework/control/plc_protocol/cip/utill.h b/APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/utill.h similarity index 100% rename from APP_Framework/Framework/control/plc_protocol/cip/utill.h rename to APP_Framework/Framework/control/plc_protocol/ethernet_ip_cip/utill.h diff --git a/APP_Framework/Framework/control/shared/control.h b/APP_Framework/Framework/control/shared/control.h index 7679b3225..7cbba18f9 100644 --- a/APP_Framework/Framework/control/shared/control.h +++ b/APP_Framework/Framework/control/shared/control.h @@ -57,6 +57,7 @@ typedef enum PROTOCOL_MELSEC_3C, PROTOCOL_FREEMODBUS_TCP_SERVER, PROTOCOL_CIP, + PROTOCOL_ETHERCAT, PROTOCOL_END }ProtocolType; @@ -116,6 +117,7 @@ int ControlProtocolIoctl(struct ControlProtocol *control_protocol, int cmd, void /*Control Framework new certain Protocol*/ ControlProtocolType control_protocol; + #ifdef __cplusplus } #endif diff --git a/APP_Framework/Framework/control/shared/control_def.c b/APP_Framework/Framework/control/shared/control_def.c index 099a959b3..d3f9e9055 100644 --- a/APP_Framework/Framework/control/shared/control_def.c +++ b/APP_Framework/Framework/control/shared/control_def.c @@ -57,6 +57,10 @@ extern int FreeModbusTcpServerInit(struct ControlRecipe *p_recipe); extern int CipProtocolInit(struct ControlRecipe *p_recipe); #endif +#ifdef CONTROL_PROTOCOL_ETHERCAT +extern int EthercatProtocolInit(struct ControlRecipe *p_recipe); +#endif + /* CONTROL FRAMEWORK READ DATA FORMAT: | HEAD |device_id|read data length|read item count| data | @@ -103,6 +107,11 @@ static struct ControlProtocolInitParam protocol_init[] = #ifdef CONTROL_PROTOCOL_CIP { PROTOCOL_CIP, CipProtocolInit }, #endif + +#ifdef CONTROL_PROTOCOL_ETHERCAT + { PROTOCOL_ETHERCAT, EthercatProtocolInit }, +#endif + { PROTOCOL_END, NULL }, };