forked from xuos/xiuos
add frermodbustcp and CIP protocol; add three PLC test demo and readme, include ab L30、850and abb PM5630
it is OK
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
* @date: 2023/2/17
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
@@ -54,7 +55,7 @@ void TestCAN(void)
|
||||
}
|
||||
printf("CAN configure successful!\n");
|
||||
|
||||
uint8_t data_buff[64u] = {1,2,3,4,4,3,2,1};
|
||||
uint8_t data_buff[64u] = "12344321";
|
||||
struct CanSendConfigure frame_send;
|
||||
frame_send.ide=0;
|
||||
frame_send.stdid = 0x55;
|
||||
@@ -62,7 +63,7 @@ void TestCAN(void)
|
||||
frame_send.data_lenth=8;
|
||||
|
||||
struct CanSendConfigure frame_recv;
|
||||
uint8_t recv_buff[65U] = {0};
|
||||
uint8_t recv_buff[64u] = {};
|
||||
frame_recv.data = recv_buff;
|
||||
|
||||
// CAN write
|
||||
|
||||
@@ -15,6 +15,10 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
||||
SRC_DIR += socket_demo
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_FREEMODBUSTCP),y)
|
||||
SRC_DIR += freemodbus_tcp_slave
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
SRC_FILES := tcpserver_sample.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* FreeModbus Libary: Win32 Demo Application
|
||||
* Copyright (C) 2006 Christian Walter <wolti@sil.at>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* File: $Id$
|
||||
*/
|
||||
|
||||
/**********************************************************
|
||||
* Linux TCP support.
|
||||
* Based on Walter's project.
|
||||
* Modified by Steven Guo <gotop167@163.com>
|
||||
***********************************************************/
|
||||
|
||||
/* ----------------------- Standard C Libs includes --------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <transform.h>
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/sockets.h"
|
||||
|
||||
/* ----------------------- Modbus includes ----------------------------------*/
|
||||
#include "mb.h"
|
||||
#include "mbport.h"
|
||||
|
||||
/* ----------------------- Defines ------------------------------------------*/
|
||||
#define PROG "freemodbus"
|
||||
|
||||
#define REG_INPUT_START 1000
|
||||
#define REG_INPUT_NREGS 4
|
||||
#define REG_HOLDING_START 2000
|
||||
#define REG_HOLDING_NREGS 10
|
||||
|
||||
/* ----------------------- Static variables ---------------------------------*/
|
||||
static USHORT usRegInputStart = REG_INPUT_START;
|
||||
static USHORT usRegInputBuf[REG_INPUT_NREGS];
|
||||
static USHORT usRegHoldingStart = REG_HOLDING_START;
|
||||
static USHORT usRegHoldingBuf[REG_HOLDING_NREGS];
|
||||
static pthread_mutex_t xLock;
|
||||
static enum ThreadState
|
||||
{
|
||||
STOPPED,
|
||||
RUNNING,
|
||||
SHUTDOWN
|
||||
} ePollThreadState;
|
||||
|
||||
/* ----------------------- Static functions ---------------------------------*/
|
||||
static BOOL bCreatePollingThread( void );
|
||||
static enum ThreadState eGetPollingThreadState( void );
|
||||
static void eSetPollingThreadState( enum ThreadState eNewState );
|
||||
static void* pvPollingThread( void *pvParameter );
|
||||
int LWIPConnectSocket(uint16_t port);
|
||||
|
||||
/* ----------------------- Start implementation -----------------------------*/
|
||||
int MBSlave()
|
||||
{
|
||||
int iExitCode;
|
||||
CHAR cCh;
|
||||
BOOL bDoExit;
|
||||
usRegHoldingBuf[5] = 123;
|
||||
usRegHoldingBuf[7] = 234;
|
||||
|
||||
printf("%s ip %d.%d.%d.%d mask %d.%d.%d.%d gw %d.%d.%d.%d\n", __func__,
|
||||
192, 168, 250, 233,
|
||||
255, 255, 255, 255,
|
||||
192, 168, 250, 1);
|
||||
uint8_t local_ip[4] = {192,168,250,233};
|
||||
uint8_t gateway[4] = {192,168,250,1};
|
||||
uint8_t netmask[4] = {255,255,255,0};
|
||||
lwip_config_tcp(0, local_ip, netmask, gateway);
|
||||
printf("%s LWIPInit done\n", __func__);
|
||||
|
||||
if( eMBTCPInit( MB_TCP_PORT_USE_DEFAULT ) != MB_ENOERR )
|
||||
{
|
||||
fprintf( stderr, "%s: can't initialize modbus stack!\r\n", PROG );
|
||||
iExitCode = EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
eSetPollingThreadState( STOPPED );
|
||||
/* CLI interface. */
|
||||
if( bCreatePollingThread( ) != TRUE )
|
||||
{
|
||||
printf( "Can't start protocol stack! Already running?\r\n" );
|
||||
}
|
||||
}
|
||||
printf("%d %d %s\n",sizeof(usRegHoldingBuf),__LINE__,__func__);
|
||||
|
||||
while(1)
|
||||
{
|
||||
for(int i =0; i<sizeof(usRegHoldingBuf)/2;i++)
|
||||
{
|
||||
printf("poll recv is %3d\n", usRegHoldingBuf[i]);
|
||||
MdelayKTask(100);
|
||||
}
|
||||
}
|
||||
return iExitCode;
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(MBSlave, a Mtcp server Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
|
||||
BOOL bCreatePollingThread( void )
|
||||
{
|
||||
BOOL bResult;
|
||||
pthread_t xThread;
|
||||
if( eGetPollingThreadState( ) == STOPPED )
|
||||
{
|
||||
if( pthread_create( &xThread, NULL, pvPollingThread, NULL ) != 0 )
|
||||
{
|
||||
/* Can't create the polling thread. */
|
||||
bResult = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bResult = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bResult = FALSE;
|
||||
}
|
||||
return bResult;
|
||||
}
|
||||
|
||||
|
||||
void* pvPollingThread( void *pvParameter )
|
||||
{
|
||||
eSetPollingThreadState( RUNNING );
|
||||
|
||||
if( eMBEnable( ) == MB_ENOERR )
|
||||
{
|
||||
do
|
||||
{
|
||||
if( eMBPoll( ) != MB_ENOERR )
|
||||
break;
|
||||
}
|
||||
while( eGetPollingThreadState( ) != SHUTDOWN );
|
||||
}
|
||||
|
||||
( void )eMBDisable( );
|
||||
|
||||
eSetPollingThreadState( STOPPED );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum ThreadState eGetPollingThreadState( )
|
||||
{
|
||||
enum ThreadState eCurState;
|
||||
|
||||
( void )pthread_mutex_lock( &xLock );
|
||||
eCurState = ePollThreadState;
|
||||
( void )pthread_mutex_unlock( &xLock );
|
||||
|
||||
return eCurState;
|
||||
}
|
||||
|
||||
void eSetPollingThreadState( enum ThreadState eNewState )
|
||||
{
|
||||
( void )pthread_mutex_lock( &xLock );
|
||||
ePollThreadState = eNewState;
|
||||
( void )pthread_mutex_unlock( &xLock );
|
||||
}
|
||||
|
||||
eMBErrorCode eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
int iRegIndex;
|
||||
|
||||
if( ( usAddress >= REG_INPUT_START )
|
||||
&& ( usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS ) )
|
||||
{
|
||||
iRegIndex = ( int )( usAddress - usRegInputStart );
|
||||
while( usNRegs > 0 )
|
||||
{
|
||||
*pucRegBuffer++ = ( unsigned char )( usRegInputBuf[iRegIndex] >> 8 );
|
||||
*pucRegBuffer++ = ( unsigned char )( usRegInputBuf[iRegIndex] & 0xFF );
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBErrorCode eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode )
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
int iRegIndex;
|
||||
|
||||
if( ( usAddress >= REG_HOLDING_START ) &&
|
||||
( usAddress + usNRegs <= REG_HOLDING_START + REG_HOLDING_NREGS ) )
|
||||
{
|
||||
iRegIndex = ( int )( usAddress - usRegHoldingStart );
|
||||
switch ( eMode )
|
||||
{
|
||||
/* Pass current register values to the protocol stack. */
|
||||
case MB_REG_READ:
|
||||
while( usNRegs > 0 )
|
||||
{
|
||||
*pucRegBuffer++ = ( UCHAR ) ( usRegHoldingBuf[iRegIndex] >> 8 );
|
||||
*pucRegBuffer++ = ( UCHAR ) ( usRegHoldingBuf[iRegIndex] & 0xFF );
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Update current register values with new values from the
|
||||
* protocol stack. */
|
||||
case MB_REG_WRITE:
|
||||
while( usNRegs > 0 )
|
||||
{
|
||||
usRegHoldingBuf[iRegIndex] = *pucRegBuffer++ << 8;
|
||||
usRegHoldingBuf[iRegIndex] |= *pucRegBuffer++;
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
|
||||
eMBErrorCode eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils, eMBRegisterMode eMode )
|
||||
{
|
||||
return MB_ENOREG;
|
||||
}
|
||||
|
||||
eMBErrorCode eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
|
||||
{
|
||||
return MB_ENOREG;
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje inovance keyence
|
||||
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje inovance keyence ab abb
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
3
APP_Framework/Applications/control_app/plc_demo/ab/Makefile
Executable file
3
APP_Framework/Applications/control_app/plc_demo/ab/Makefile
Executable file
@@ -0,0 +1,3 @@
|
||||
SRC_FILES := ab_l30erm.c ab_micro850.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
91
APP_Framework/Applications/control_app/plc_demo/ab/README_ab_850.md
Executable file
91
APP_Framework/Applications/control_app/plc_demo/ab/README_ab_850.md
Executable file
@@ -0,0 +1,91 @@
|
||||
# AB_850通信测试
|
||||
|
||||
[TOC]
|
||||
|
||||
## 通信接线及参数设置
|
||||
|
||||
* 网口
|
||||
|
||||
*Mosbus TCP协议,IP:192.168.250.56,Port:502
|
||||
|
||||
## 存储区
|
||||
|
||||
- 存储区D区
|
||||
|
||||
## JSON配方设计
|
||||
|
||||
* AB_850类型PLC需要配置控制器映射
|
||||
|
||||

|
||||
|
||||
* 共测试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) 剪裁配置完成后,用过烧写器下载至矽数通中,重启后完成测试。
|
||||
|
||||
|
||||
|
||||
|
||||
71
APP_Framework/Applications/control_app/plc_demo/ab/README_ab_l300erm.md
Executable file
71
APP_Framework/Applications/control_app/plc_demo/ab/README_ab_l300erm.md
Executable file
@@ -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) 剪裁配置完成后,用过烧写器下载至矽数通中,重启后完成测试。
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 ab_l30.c
|
||||
* @brief PLC ABB L30 app
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.8.27
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
|
||||
void ControlABL30Test(void)
|
||||
{
|
||||
int i = 0;
|
||||
uint16_t read_data_length = 0;
|
||||
uint8_t read_data[1024] = {0};
|
||||
ControlProtocolType CIP_protocol = ControlProtocolFind();
|
||||
if (NULL == CIP_protocol) {
|
||||
printf("%s get CIP protocol %p failed\n", __func__, CIP_protocol);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s get CIP protocol %p successfull\n", __func__, CIP_protocol);
|
||||
if (CONTROL_REGISTERED == CIP_protocol->protocol_status) {
|
||||
ControlProtocolOpen(CIP_protocol);
|
||||
|
||||
for (;;) {
|
||||
read_data_length = ControlProtocolRead(CIP_protocol, read_data, sizeof(read_data));
|
||||
printf("%s read [%d] CIP data %d using receipe file\n", __func__, i, read_data_length);
|
||||
i++;
|
||||
PrivTaskDelay(1000);
|
||||
}
|
||||
|
||||
//ControlProtocolClose(CIP_protocol);
|
||||
}
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(ControlABL30Test, Ab Plc CIP Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
@@ -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 <control.h>
|
||||
|
||||
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);
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.3 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.6 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
3
APP_Framework/Applications/control_app/plc_demo/abb/Makefile
Executable file
3
APP_Framework/Applications/control_app/plc_demo/abb/Makefile
Executable file
@@ -0,0 +1,3 @@
|
||||
SRC_FILES := abb_pm5630.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -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) 剪裁配置完成后,用过烧写器下载至矽数通中,重启后完成测试。
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 <control.h>
|
||||
|
||||
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);
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.7 MiB |
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user