Merge branch 'control_framework' of https://gitlink.org.cn/IACU/xiuos into control_framework

This commit is contained in:
Liu_Weichao 2023-04-26 11:02:48 +08:00
commit 4f72b78b96
14 changed files with 281 additions and 131 deletions

View File

@ -1,3 +1,3 @@
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje inovance
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,3 @@
SRC_FILES := inovance_am401_cpu1608tn_ethernet.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,26 @@
# INOVANCE AM4011608TN通信测试
[TOC]
## 通信接线及参数设置
* 网口
* CN3 EtherNET,Mosbus TCP协议IP192.168.250.50Port502
* 串口
* CN1 RS485AM401只支持一路串口AM600可支持两路串口。AM401接线pin1:485-pin2:485+。波特率9600数据位8位停止位1位校验偶校验
## 存储区
- 存储区 IQM区。
## 通信测试
1共测试BOOLINT16INT32FLOAT共四种类型数据。
2测试M区及Q区数据。
3M区数据测试用功能码03以字为单位读取。如读MX0.3,则读取MW0然后按位拆解。如读MW100则配方文件中起始地址则直接写100即可。如读MDx则配方文件中起始地址应为2*x这是汇川的地址编码规则决定如MD200则对应400。
4Q区数据测试用功能码01以位为单位读取。如读QX.Y则配方文件中起始地址为X*8+Y如读QWQD等则需按位进行读取后然后组合得到。

View File

@ -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 inovance_am401_cpu1608tn_ethernet.c
* @brief PLC inovance am401 app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.4.25
*/
#include <control.h>
extern int Adapter4GActive(void);
void ControlInovanceam401EthernetTest(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(ControlInovanceam401EthernetTest, inovance am401 ethernet Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -0,0 +1,80 @@
{
"device_id": 1,
"device_name": "INOVANCE_AM401_TCP",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.50",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.1",
"netmask": "255.255.254.0",
"port": 502
},
"protocol_type": 2,
"read_period": 2000,
"read_item_list": [
{
"value_name": "q00",
"value_type": 1,
"function_code": 1,
"start_address": 0,
"quantity": 1
},
{
"value_name": "q01",
"value_type": 1,
"function_code": 1,
"start_address":1,
"quantity": 1
},
{
"value_name": "q10",
"value_type": 1,
"function_code": 1,
"start_address": 8,
"quantity": 1
},
{
"value_name": "mw100",
"value_type": 3,
"function_code": 3,
"start_address": 100,
"quantity": 1
},
{
"value_name": "mw101",
"value_type": 3,
"function_code": 3,
"start_address": 101,
"quantity": 1
},
{
"value_name": "md200",
"value_type": 4,
"function_code": 3,
"start_address": 400,
"quantity": 2
},
{
"value_name": "md201",
"value_type": 4,
"function_code": 3,
"start_address": 402,
"quantity": 2
},
{
"value_name": "md300",
"value_type": 9,
"function_code": 3,
"start_address": 600,
"quantity": 2
},
{
"value_name": "md301",
"value_type": 9,
"function_code": 3,
"start_address": 602,
"quantity": 2
}
]
}

View File

@ -18,3 +18,28 @@
* @date 2023.3.27
*/
#include <control.h>
void ControlS71500Test(void)
{
int i = 0;
uint16_t read_data_length = 0;
uint8_t read_data[1024] = {0};
ControlProtocolType s7_protocol = ControlProtocolFind();
if (NULL == s7_protocol) {
printf("%s get s7 protocol %p failed\n", __func__, s7_protocol);
return;
}
printf("%s get s7 protocol %p successfull\n", __func__, s7_protocol);
if (CONTROL_REGISTERED == s7_protocol->protocol_status) {
ControlProtocolOpen(s7_protocol);
for (;;) {
read_data_length = ControlProtocolRead(s7_protocol, read_data, sizeof(read_data));
printf("%s read [%d] s7 data %d using receipe file\n", __func__, i, read_data_length);
i++;
memset(read_data, 0, sizeof(read_data));
PrivTaskDelay(10000);
}
}
}
PRIV_SHELL_CMD_FUNCTION(ControlS71500Test, Siemens Plc S7_1512 Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -1,6 +1,6 @@
{
"device_id": 1,
"device_name": "打包机",
"device_name": "demo",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.2",

View File

@ -1,3 +1,3 @@
SRC_FILES := xsdh-60a32-e.c xdh-60t4-e.c
SRC_FILES := xdh_60t4_e.c xsdh_60a32_e.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -19,6 +19,7 @@
*/
#include <control.h>
void ControlXDHTest(void)
{
int i, j = 0;

View File

@ -20,6 +20,7 @@
#include <control.h>
void ControlXSDHTest(void)
{
int i, j = 0;

View File

@ -102,24 +102,6 @@ static struct ControlDone s7_protocol_done =
._ioctl = NULL,
};
/**
* @description: S7 Protocol Value Type
* @param uniform_value_type - uniform value type
* @return success : 0-8 error : -1
*/
static uint8_t GetUniformValueTypeMemorySize(UniformValueType uniform_value_type)
{
if (uniform_value_type == UNIFORM_BOOL || uniform_value_type == UNIFORM_INT8 || uniform_value_type == UNIFORM_UINT8)
return 1;
if (uniform_value_type == UNIFORM_INT16 || uniform_value_type == UNIFORM_UINT16)
return 2;
if (uniform_value_type == UNIFORM_INT32 || uniform_value_type == UNIFORM_UINT32 || uniform_value_type == UNIFORM_FLOAT)
return 4;
if (uniform_value_type == UNIFORM_DOUBLE)
return 8;
return 0;
}
/**
* @description: Push Data Onto a Stack One By One
* @param datastack - data stack pointer
@ -181,7 +163,7 @@ int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe)
}
TS7DataItem data_info = ((S7ReadItem*)p_read_item + i)->data_info;
Cli_ReadMultiVars(s7_plc, &data_info, 1);
uint16_t Size = GetUniformValueTypeMemorySize(((S7ReadItem*)p_read_item + i)->value_type);
uint16_t Size = GetValueTypeMemorySize(((S7ReadItem*)p_read_item + i)->value_type);
PrintHexNumberList("s7 recv", data_info.pdata,Size);
PushDataIntoStack(s7_data,data_info.pdata,Size);
MdelayKTask(100);
@ -200,6 +182,79 @@ int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe)
return 0;
}
/**
* @description: S7 Protocol read item Init
* @param p_read_item - read item pointer
* @param read_item_json - read item json pointer
* @param p_data - unused
* @return success : 0 error : -1
*/
static uint8_t InitialS7ReadItem(S7ReadItem* p_read_item, cJSON* read_item_json, uint8_t* p_data)
{
p_read_item->value_type = cJSON_GetObjectItem(read_item_json, "value_type")->valueint;
strncpy(p_read_item->value_name, cJSON_GetObjectItem(read_item_json, "value_name")->valuestring, 20);
TS7DataItem* p_data_info = &(p_read_item->data_info);
p_data_info->Amount = cJSON_GetObjectItem(read_item_json, "amount")->valueint;
p_data_info->Start = cJSON_GetObjectItem(read_item_json, "start")->valueint;
p_data_info->DBNumber = cJSON_GetObjectItem(read_item_json, "db_number")->valueint;
char* area_valuestring = cJSON_GetObjectItem(read_item_json, "area")->valuestring;
if (strcmp(area_valuestring, "I") == 0)
p_data_info->Area = S7AreaPE;
else if (strcmp(area_valuestring, "Q") == 0)
p_data_info->Area = S7AreaPA;
else if (strcmp(area_valuestring, "M") == 0)
p_data_info->Area = S7AreaMK;
else if (strcmp(area_valuestring, "DB") == 0)
p_data_info->Area = S7AreaDB;
else if (strcmp(area_valuestring, "C") == 0)
p_data_info->Area = S7AreaCT;
else if (strcmp(area_valuestring, "T") == 0)
p_data_info->Area = S7AreaTM;
char* wordlen_valuestring = cJSON_GetObjectItem(read_item_json, "wordlen")->valuestring;
if (strcmp(wordlen_valuestring, "Bit") == 0)
p_data_info->WordLen = S7WLBit;
else if (strcmp(wordlen_valuestring, "Byte") == 0)
p_data_info->WordLen = S7WLByte;
else if (strcmp(wordlen_valuestring, "Word") == 0)
p_data_info->WordLen = S7WLWord;
else if (strcmp(wordlen_valuestring, "DWord") == 0)
p_data_info->WordLen = S7WLDWord;
else if (strcmp(wordlen_valuestring, "Real") == 0)
p_data_info->WordLen = S7WLReal;
else if (strcmp(wordlen_valuestring, "Counter") == 0)
p_data_info->WordLen = S7WLCounter;
else if (strcmp(wordlen_valuestring, "Timer") == 0)
p_data_info->WordLen = S7WLTimer;
p_data_info->pdata = p_data;
printf("value_type is %d, amount is %d, start is %04d, db_number is %d, area is 0x%03x, wordlen is %d.\n",
p_read_item->value_type, p_data_info->Amount, p_data_info->Start, p_data_info->DBNumber,
p_data_info->Area, p_data_info->WordLen);
return GetValueTypeMemorySize(p_read_item->value_type);
}
/**
* @description: S7 Protocol Cmd Generate
* @param p_recipe - recipe pointer
* @param protocol_format_info - protocol format info pointer
* @return success : 0 error : -1
*/
int S7ProtocolFormatCmd(struct ControlRecipe *p_recipe, ProtocolFormatInfo *protocol_format_info)
{
int ret = 0;
uint8_t* S7_plc_read_data = malloc(p_recipe->protocol_data.data_length);
uint16_t S7_plc_read_data_index = 8;
cJSON *read_single_item_json = protocol_format_info->read_single_item_json;
int i = protocol_format_info->read_item_index;
if (i == 0)
p_recipe->read_item = malloc(sizeof(S7ReadItem) * p_recipe->read_item_count);
S7_plc_read_data_index += InitialS7ReadItem((S7ReadItem*)(p_recipe->read_item) + i,
read_single_item_json,S7_plc_read_data + S7_plc_read_data_index);
if (S7_plc_read_data_index == 8) {
ret = -1;
printf("%s read %d item failed!\n", __func__, i);
}
return ret;
}
/**
* @description: S7 Protocol Init
* @param p_recipe - recipe pointer
@ -212,12 +267,8 @@ int S7ProtocolInit(struct ControlRecipe *p_recipe)
PrivFree(p_recipe->read_item);
return -1;
}
memset(p_recipe->read_item, 0, sizeof(S7ReadItem));
// p_recipe->ControlProtocolFormatCmd = S7ProtocolFormatCmd;
p_recipe->ControlProtocolFormatCmd = S7ProtocolFormatCmd;
p_recipe->done = &s7_protocol_done;
return 0;
}

View File

@ -20,7 +20,6 @@
#include <control.h>
#include <control_def.h>
//#include "s7.h"
/**
* @description: Control Framework Find certain Protocol
@ -295,17 +294,6 @@ int ControlFrameworkInit(void)
printf("%u %u\n",control_protocol->recipe->total_data_length,control_protocol->recipe->device_id);
printf("%s ControlPeripheralInit done\n", __func__);
//s7 read
// ret = ReadPlcDataByRecipe(control_protocol->recipe);
// if (ret < 0) {
// printf("%s failed!\n", __func__);
// PrivFree(control_protocol);
// goto _out;
// }
_out:
return ret;

View File

@ -24,6 +24,7 @@
#include <transform.h>
#include <list.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -20,7 +20,6 @@
#include <control_def.h>
#include <control_io.h>
#include "s7.h"
/*using cirtular area to receive data*/
#define PLC_DATA_LENGTH 1024
@ -430,73 +429,6 @@ int RecipeBasicInformation(struct ControlRecipe *p_recipe, cJSON *p_recipe_file_
printf("\n************************************************************\n");
}
static uint8_t GetS7ValueTypeMemorySize(UniformValueType uniform_value_type)
{
if (uniform_value_type == UNIFORM_BOOL || uniform_value_type == UNIFORM_INT8 || uniform_value_type == UNIFORM_UINT8)
return 1;
if (uniform_value_type == UNIFORM_INT16 || uniform_value_type == UNIFORM_UINT16)
return 2;
if (uniform_value_type == UNIFORM_INT32 || uniform_value_type == UNIFORM_UINT32 || uniform_value_type == UNIFORM_FLOAT)
return 4;
if (uniform_value_type == UNIFORM_DOUBLE)
return 8;
return 0;
}
/**
* @description: S7 Protocol read item Init
* @param p_read_item - read item pointer
* @param read_item_json - read item json pointer
* @param p_data - unused
* @return success : 0 error : -1
*/
static uint8_t InitialS7ReadItem(S7ReadItem* p_read_item, cJSON* read_item_json, uint8_t* p_data)
{
p_read_item->value_type = cJSON_GetObjectItem(read_item_json, "value_type")->valueint;
strncpy(p_read_item->value_name, cJSON_GetObjectItem(read_item_json, "value_name")->valuestring, 20);
TS7DataItem* p_data_info = &(p_read_item->data_info);
p_data_info->Amount = cJSON_GetObjectItem(read_item_json, "amount")->valueint;
p_data_info->Start = cJSON_GetObjectItem(read_item_json, "start")->valueint;
p_data_info->DBNumber = cJSON_GetObjectItem(read_item_json, "db_number")->valueint;
char* area_valuestring = cJSON_GetObjectItem(read_item_json, "area")->valuestring;
if (strcmp(area_valuestring, "I") == 0)
p_data_info->Area = S7AreaPE;
else if (strcmp(area_valuestring, "Q") == 0)
p_data_info->Area = S7AreaPA;
else if (strcmp(area_valuestring, "M") == 0)
p_data_info->Area = S7AreaMK;
else if (strcmp(area_valuestring, "DB") == 0)
p_data_info->Area = S7AreaDB;
else if (strcmp(area_valuestring, "C") == 0)
p_data_info->Area = S7AreaCT;
else if (strcmp(area_valuestring, "T") == 0)
p_data_info->Area = S7AreaTM;
char* wordlen_valuestring = cJSON_GetObjectItem(read_item_json, "wordlen")->valuestring;
if (strcmp(wordlen_valuestring, "Bit") == 0)
p_data_info->WordLen = S7WLBit;
else if (strcmp(wordlen_valuestring, "Byte") == 0)
p_data_info->WordLen = S7WLByte;
else if (strcmp(wordlen_valuestring, "Word") == 0)
p_data_info->WordLen = S7WLWord;
else if (strcmp(wordlen_valuestring, "DWord") == 0)
p_data_info->WordLen = S7WLDWord;
else if (strcmp(wordlen_valuestring, "Real") == 0)
p_data_info->WordLen = S7WLReal;
else if (strcmp(wordlen_valuestring, "Counter") == 0)
p_data_info->WordLen = S7WLCounter;
else if (strcmp(wordlen_valuestring, "Timer") == 0)
p_data_info->WordLen = S7WLTimer;
p_data_info->pdata = p_data;
printf("value_type is %d, amount is %d, start is %04d, db_number is %d, area is 0x%03x, wordlen is %d.\n",
p_read_item->value_type, p_data_info->Amount, p_data_info->Start, p_data_info->DBNumber,
p_data_info->Area, p_data_info->WordLen);
return GetS7ValueTypeMemorySize(p_read_item->value_type);
}
/**
* @description: Control Framework Read Variable Item Function
* @param p_recipe - Control recipe pointer
@ -526,37 +458,15 @@ void RecipeReadVariableItem(struct ControlRecipe *p_recipe, cJSON *p_recipe_file
/*Format Data Header, Reference "CONTROL FRAMEWORK READ DATA FORMAT"*/
FormatDataHeader(p_recipe);
uint16_t read_item_count = p_recipe->read_item_count;
uint8_t* S7_plc_read_data;
S7_plc_read_data = malloc(p_recipe->protocol_data.data_length);
uint16_t S7_plc_read_data_index = 8;
for (i = 0; i < read_item_count; i ++) {
cJSON *read_single_item_json = cJSON_GetArrayItem(read_item_list_json, i);
protocol_format_info.read_single_item_json = read_single_item_json;
protocol_format_info.read_item_index = i;
switch (p_recipe->protocol_type) {
case PROTOCOL_S7:
if (i == 0)
p_recipe->read_item = malloc(sizeof(S7ReadItem) * p_recipe->read_item_count);
S7_plc_read_data_index += InitialS7ReadItem((S7ReadItem*)(p_recipe->read_item) + i,
read_single_item_json,S7_plc_read_data + S7_plc_read_data_index);
if (S7_plc_read_data_index == 8) {
printf("%s read %d item failed!\n", __func__, i);
continue;
}
break;
default:
/*Format Protocol Cmd By Analyze Variable Item One By One*/
ret = p_recipe->ControlProtocolFormatCmd(p_recipe, &protocol_format_info);
/*Format Protocol Cmd By Analyze Variable Item One By One*/
ret = p_recipe->ControlProtocolFormatCmd(p_recipe, &protocol_format_info);
if (ret < 0) {
printf("%s read %d item failed!\n", __func__, i);
continue;
}
}
}
}