modbus数据打包解包代码
This commit is contained in:
1 parent
135ce35517
commit
64ca79d1a3
15 files changed
+1344
-1089
No files matched your search
@@ -457,7 +457,7 @@ void pasre_DAT(const char *api, const char *json_str)
|
||||
}
|
||||
else if (strcmp(api, "SC851") == 0)
|
||||
{//创建数组
|
||||
cJSON *Dev = cJSON_CreateArray();
|
||||
/* cJSON *Dev = cJSON_CreateArray();
|
||||
for (int i = 0; i < DIO_TABLE_SIZE; i++) {
|
||||
cJSON* item = cJSON_CreateObject();
|
||||
// 添加 IO 编号
|
||||
@@ -469,11 +469,11 @@ void pasre_DAT(const char *api, const char *json_str)
|
||||
// 将当前项添加到数组中
|
||||
cJSON_AddItemToArray(Dev, item);
|
||||
}
|
||||
cJSON_AddItemToObject(dat,"DIO",Dev);
|
||||
cJSON_AddItemToObject(dat,"DIO",Dev);*/
|
||||
}
|
||||
else if (strcmp(api, "SC852") == 0)
|
||||
{//创建数组
|
||||
cJSON *Dev = cJSON_CreateArray();
|
||||
/* cJSON *Dev = cJSON_CreateArray();
|
||||
for (int i = 0; i < AIO_TABLE_SIZE; i++) {
|
||||
cJSON* item = cJSON_CreateObject();
|
||||
// 添加 IO 编号
|
||||
@@ -483,11 +483,11 @@ void pasre_DAT(const char *api, const char *json_str)
|
||||
// 将当前项添加到数组中
|
||||
cJSON_AddItemToArray(Dev, item);
|
||||
}
|
||||
cJSON_AddItemToObject(dat,"A",Dev);
|
||||
cJSON_AddItemToObject(dat,"A",Dev);*/
|
||||
}
|
||||
else if (strcmp(api, "SC853") == 0)
|
||||
{//创建数组
|
||||
cJSON *Dev = cJSON_CreateArray();
|
||||
/* cJSON *Dev = cJSON_CreateArray();
|
||||
for (int i = 0; i < DATA_TABLE_SIZE; i++) {
|
||||
cJSON* item = cJSON_CreateObject();
|
||||
// 添加 IO 编号
|
||||
@@ -497,7 +497,7 @@ void pasre_DAT(const char *api, const char *json_str)
|
||||
// 将当前项添加到数组中
|
||||
cJSON_AddItemToArray(Dev, item);
|
||||
}
|
||||
cJSON_AddItemToObject(dat,"M",Dev);
|
||||
cJSON_AddItemToObject(dat,"M",Dev);*/
|
||||
}
|
||||
else if (strcmp(api, "SC854") == 0) {
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "SC828_DATA_table.h"
|
||||
#include <rtthread.h>
|
||||
#include "Variable.h"
|
||||
|
||||
// 系统数据状态表(表格)
|
||||
@@ -19,7 +18,7 @@ IO_State_DATA data_table[] = {
|
||||
};
|
||||
|
||||
// DIO状态表(表格)
|
||||
IO_State_DIO dio_table[] = {
|
||||
IO_State_DIO di_table[] = {
|
||||
{2001, 0, STR_EMERGENCY_STOP},
|
||||
{2002, 0, STR_TEMP_LOCK},
|
||||
{2003, 0, STR_PRESSURE_LOCK},
|
||||
@@ -102,8 +101,10 @@ IO_State_DIO dio_table[] = {
|
||||
{2080, 0, STR_MATERIAL3_FILL},
|
||||
{2081, 0, STR_MATERIAL3_HEAT},
|
||||
{2082, 0, STR_MATERIAL3_STIR},
|
||||
};
|
||||
// --- DIO 输出(3001~3066)---
|
||||
{3001, 0, STR_RED}, // 红
|
||||
IO_State_DIO do_table[] = {
|
||||
{3001, 1, STR_RED}, // 红
|
||||
{3002, 0, STR_GREEN}, // 绿
|
||||
{3003, 0, STR_YELLOW}, // 黄
|
||||
{3004, 0, STR_ALARM}, // 警报
|
||||
@@ -215,15 +216,21 @@ IO_State_AIO aio_table[] = {
|
||||
//步骤数据表最大99
|
||||
IO_STEP_DATA step_table[99];
|
||||
|
||||
const unsigned char DIO_TABLE_SIZE = sizeof(dio_table) / sizeof(dio_table[0]);
|
||||
const unsigned char DI_TABLE_SIZE = sizeof(di_table) / sizeof(di_table[0]);
|
||||
const unsigned char DO_TABLE_SIZE = sizeof(do_table) / sizeof(do_table[0]);
|
||||
const unsigned char AIO_TABLE_SIZE = sizeof(aio_table) / sizeof(aio_table[0]);
|
||||
const unsigned char DATA_TABLE_SIZE = sizeof(data_table) / sizeof(data_table[0]);
|
||||
|
||||
void DATA_Table_Init(){
|
||||
for(int i=0;i<DIO_TABLE_SIZE;i++)
|
||||
for(int i=0;i<DI_TABLE_SIZE;i++)
|
||||
{
|
||||
dio_table[i].current_state = 0;
|
||||
di_table[i].current_state = 0;
|
||||
}
|
||||
for(int i=0;i<DO_TABLE_SIZE;i++)
|
||||
{
|
||||
do_table[i].current_state = 0;
|
||||
}
|
||||
|
||||
for(int i=0;i<AIO_TABLE_SIZE;i++)
|
||||
{
|
||||
aio_table[i].current_Value = 0;
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#ifndef APPLICATIONS_SC828_DATA_Table_H
|
||||
#define APPLICATIONS_SC828_DATA_Table_H
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "stdbool.h"
|
||||
#include "language.h"
|
||||
|
||||
// IO状态结构体(可扩展)
|
||||
typedef struct {
|
||||
int pin; // PLCID
|
||||
unsigned char current_state; // 当前电平:0=低,1=高
|
||||
rt_bool_t current_state; // 当前电平:0=低,1=高
|
||||
str_id_t name; // 名称(可选,用于调试)
|
||||
} IO_State_DIO;
|
||||
|
||||
@@ -51,12 +52,14 @@ typedef struct {
|
||||
double Parameter5_S3;
|
||||
} IO_STEP_DATA;
|
||||
|
||||
extern IO_State_DIO dio_table[];
|
||||
extern IO_State_DIO di_table[];
|
||||
extern IO_State_DIO do_table[];
|
||||
extern IO_State_AIO aio_table[];
|
||||
extern IO_State_DATA data_table[];
|
||||
extern IO_STEP_DATA step_table[99];
|
||||
|
||||
extern const unsigned char DIO_TABLE_SIZE;
|
||||
extern const unsigned char DI_TABLE_SIZE;
|
||||
extern const unsigned char DO_TABLE_SIZE;
|
||||
extern const unsigned char AIO_TABLE_SIZE;
|
||||
extern const unsigned char DATA_TABLE_SIZE;
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
rt_int32_t sys_temperature;//主机环境温度
|
||||
rt_int32_t sys_humidity;//主机环境湿度
|
||||
char sys_var[8];//主机版本0.0.00A
|
||||
unsigned char sys_time[6];//系统时间
|
||||
unsigned int sys_run_time;//运行时间
|
||||
char sys_time[9]="00:00:00";//系统时间
|
||||
unsigned int sys_run_time=0;//运行时间
|
||||
int pow_bat;//电池电压
|
||||
int pow_code;//主电压
|
||||
int pow_dev1;//设备电压.通讯
|
||||
@@ -28,7 +28,7 @@ char MACHINE_CALL = 0;
|
||||
char MACHINE_USER = 0;
|
||||
|
||||
// 字符串变量(RAM 中可修改)
|
||||
char Work[25];
|
||||
char Work[25]="SC----------";
|
||||
char Dye[25];
|
||||
char Process[50];
|
||||
char Message[40];
|
||||
@@ -42,25 +42,25 @@ unsigned int RUN = 0;
|
||||
unsigned int STEPID = 0;
|
||||
|
||||
// 浮点变量
|
||||
float MTT = 0.0f;
|
||||
float MTL = 0.0f;
|
||||
float MTH = 6.0f; // 默认目标温度
|
||||
float MST = 0.0f;
|
||||
float MUT = 0.0f;
|
||||
float STTA = 0.0f;
|
||||
float STLA = 0.0f;
|
||||
float STTB = 0.0f;
|
||||
float STLB = 0.0f;
|
||||
float STTC = 0.0f;
|
||||
float STLC = 0.0f;
|
||||
float MTT = 0.0f;//主缸温度
|
||||
float MTL = 0.0f;//主缸水位
|
||||
float MTH = 6.0f;//主缸ph
|
||||
float MST = 0.0f;//目标温度
|
||||
float MUT = 0.0f;//主缸温度2
|
||||
float STTA = 0.0f;//料a温度
|
||||
float STLA = 0.0f;//料a水位
|
||||
float STTB = 0.0f;//料b温度
|
||||
float STLB = 0.0f;//料b水位
|
||||
float STTC = 0.0f;//料c温度
|
||||
float STLC = 0.0f;//料c水位
|
||||
|
||||
// 控制输出
|
||||
unsigned int Pump = 0;
|
||||
unsigned int TC = 0;
|
||||
unsigned int Fan = 0;
|
||||
unsigned int Pull = 0;
|
||||
unsigned int Swing = 0;
|
||||
unsigned int STA = 0;
|
||||
unsigned int Pump = 0;//主泵
|
||||
unsigned int TC = 0;//温度比例
|
||||
unsigned int Fan = 0;//风机
|
||||
unsigned int Pull = 0;//提布
|
||||
unsigned int Swing = 0;//摆布
|
||||
unsigned int STA = 0;//料a比例
|
||||
unsigned int STB = 0;
|
||||
unsigned int STC = 0;
|
||||
unsigned int Time = 0;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
extern rt_int32_t sys_temperature;//主机环境温度
|
||||
extern rt_int32_t sys_humidity;//主机环境湿度
|
||||
extern char sys_var[8];//主机版本0.0.00A
|
||||
extern unsigned char sys_time[6];//系统时间
|
||||
extern char sys_time[9];//系统时间
|
||||
extern unsigned int sys_run_time;//运行时间
|
||||
extern int pow_bat;//电池电压
|
||||
extern int pow_code;//主电压
|
||||
|
||||
Reference in new issue
Block a user