——Lati Apejọ Olùgbéejáde DWIN
Ninu atẹjade yii, a ṣafihan fun ọ ni ọran orisun ṣiṣi ti o gba ẹbun ti Apejọ Olùgbéejáde DWIN - yara ogbin ọlọgbọn. Awọn onimọ-ẹrọ ṣe imuse iboju smart T5L lati ṣakoso alapapo ati awọn iṣẹ iṣakoso iwọn otutu afẹfẹ nipasẹ ilana Modbus. Ipese agbara naa le tun ṣe atunṣe lati ṣe adaṣe iṣẹ ina. Eto naa le ṣiṣẹ laifọwọyi ni ibamu si awọn aye ti a ṣeto loju iboju ati ṣafipamọ awọn igbasilẹ itan-akọọlẹ ẹbi.
1.UI Ohun elo Ifihan
![asvdfb (2)](https://ecdn6.globalso.com/upload/p/1355/source/2024-03/65f96ba08612736786.jpg)
![asvdfb (1)](https://ecdn6.globalso.com/upload/p/1355/source/2024-03/65f96ba210c7924337.jpg)
2.UI Apẹrẹ
1.C51 Oniru
Awọn koodu akọkọ fun gbigba ati imudojuiwọn data gẹgẹbi iwọn otutu, ọriniinitutu, ati giga lori wiwo akọkọ, ati lilo modbus rtu lati ṣakoso awọn modulu iṣakoso iwọn otutu, awọn mọto, wiwa itaniji, ati awọn ẹrọ ẹru miiran jẹ atẹle yii.
Itọkasi koodu wiwo akọkọ:
#pẹlu "akọkọ_win.h"
#pẹlu "modbus.h"
#pẹlu "sys_params.h"
#pẹlu "func_handler.h"
#pẹlu "uart2.h"
#pẹlu
#pẹlu
# setumo TEMP_HUM_SLAVE_ADDR 2
# ṣe asọye TEMP_HUM_VAL_MAX_NUM 2
#sọtumọ ALERT_BIT_MAX_NUM 30
#sọtumọ ALERT_BYTE_NUM (ALERT_BIT_MAX_NUM/8+((ALERT_BIT_MAX_NUM%8)!=0))
#sọtumọ GET_ALERT_BIT(val, pos) ((val[pos/8]>>(pos%8))&0x01)
ọna irudef{
char ọjọ[17];
u8 desc;
}IGBAGBÜ;
#sọtumọ ALERT_TABLE_LEN 20
aimi u8 btn_sta[MAIN_WIN_BTN_MAX_NUM] = {0};
aimi u8 btn_addr[MAIN_WIN_BTN_MAX_NUM] = {50, 51, 52, 69, 53, 54, 55, 70, 56, 57, 58, 59};
u16 main_win_val[MAIN_WIN_VAL_MAX_NUM];
u16 temp_hum_val[TEMP_HUM_VAL_MAX_NUM] = {0};
u16 date_val[MAIN_WIN_DATE_MAX_NUM] = {0};
u8 alert_val[ALERT_BYTE_NUM] = {0};
u8 old_alert_val[ALERT_BYTE_NUM] = {0};
ALERT alert_tabili[ALERT_TABLE_LEN];
u16 alert_num = 0;
bit is_main_win = 0;
ofo main_win_update()
{
}
ofo main_win_disp_date()
{
u8 nikan;
lẹn = sprintf (common_buf, "% u:% u", (u16) date_val[3], (u16) date_val[4]);
common_buf[len+1] = 0;
sys_write_vp (MAIN_WIN_DATE_VP, common_buf, lẹnsi/2+2);
}
ofo main_win_process_alert()
{
u8 i;
fun (i=0;i
{
ti (GET_ALERT_BIT(old_alert_val, i))
tesiwaju;
ti (GET_ALERT_BIT(alert_val, i))
{
ti (alert_num>=ALERT_TABLE_LEN)
alert_num = ALERT_TABLE_LEN-1;
alert_table[alert_num].desc = i +1;
sprintf(alert_table[alert_num].ọjọ, "%u/%u/%u %u:%u",
date_val[0], date_val[1], date_val[2], date_val[3], date_val[4]
);
alert_num++;
}
}
memcpy (old_alert_val, alert_val, sizeof (alert_val));
}
ofo main_win_disp_alert()
{
u16 ati;
pẹlu u16;
u16 nikan = 0;
common_buf [0] = 0;
fun (i=0;i
{
val = 0;
tí mo bá
{
val = alert_table.desc;
len += sprintf(common_buf+len, "%s\r\n", alert_table.date);
}
sys_write_vp(ALERT_WIN_DESC_START_VP+i, (u8*)&val, 1);
}
common_buf[len+1] = 0;
sys_write_vp (ALERT_WIN_DATE_VP, common_buf, lẹnsi/2+2);
}
ofo main_win_init()
{
leefofo fix_val;
u8 i;
is_main_win = 1;
main_win_val [5] = (u16) (temp_hum_val [0] / 10.0 + 0.5f);
main_win_val [6] = (u16) (temp_hum_val [1] / 10.0 + 0.5f);
fun (i=0;i
{
ti (i==0)
tesiwaju;
sys_write_vp (MAIN_WIN_WIND_SPEED_VP+MAIN_WIN_VAL_OFFSET *i, (u8*) & main_win_val, 1);
}
fix_val = main_win_val [0]/WIND_SPEED_SCALE+FLOAT_FIX_VAL;
sys_write_vp (MAIN_WIN_WIND_SPEED_VP, (u8*)&fixed_val, 2);
}
ofo main_win_click_handler(u16 btn_val)
{
u8 atọka;
ti (btn_val== 0x0B)
{
main_win_disp_alert ();
pada;
}
atọka = btn_val-1;
btn_sta[index] = !btn_sta[index];
ti o ba jẹ ((( atọka = 3)||( atọka==7))
btn_sta[index] = 1;
modbus_write_bit (btn_addr [index], btn_sta [index]? 0xFF00: 0x0000);
btn_val = btn_sta[index];
sys_write_vp(MAIN_WIN_BTN_STA_START_VP+MAIN_WIN_BTN_STA_OFFSET*index, (u8*)&btn_val, 1);
ti o ba jẹ ( atọka = 9 )
is_main_win = 0;
miran ti o ba ti (( atọka==3)||( atọka==7))
{
nigba (sys_get_touch_sta ());
modbus_write_bit (btn_addr [index], 0x0000);
}
}
ofo main_win_msg_handler(u8 *msg,u16 msg_len)
{
u8 f_code = msg[MODBUS_RESPOND_POS_FUNC_CODE];
u8 data_len = msg[MODBUS_RESPOND_POS_DATA_LEN];
u8 i;
u8 aiṣedeede;
msg_len = msg_len;
ti (! jẹ_main_win)
pada;
ti ((f_code==MODBUS_FUNC_CODE_03)&&(data_len==MAIN_WIN_VAL_MAX_NUM*2))
{
aiṣedeede = MODBUS_RESPOND_POS_DATA;
fun (i=0;i
{
main_win_val = SYS_GET_U16(msg[aiṣedeede], msg[offset+1]);
aiṣedeede += 2;
}
main_win_update ();
}miiran ti ((f_code==MODBUS_FUNC_CODE_01)&&(data_len==ALERT_BYTE_NUM))
{
aiṣedeede = MODBUS_RESPOND_POS_DATA;
fun (i=0;i
{
alert_val = msg[aiṣedeede];
aiṣedeede ++;
}
main_win_process_alert ();
}miiran ti ((f_code==MODBUS_FUNC_CODE_03)&&(data_len==TEMP_HUM_VAL_MAX_NUM*2))
{
aiṣedeede = MODBUS_RESPOND_POS_DATA;
fun (i=0;i
{
temp_hum_val = SYS_GET_U16(msg[aiṣedeede], msg[offset+1]);
aiṣedeede += 2;
modbus_write_word (5+i, temp_hum_val);
}
main_win_update ();
}miiran ti ((f_code==MODBUS_FUNC_CODE_03)&&(data_len==MAIN_WIN_DATE_MAX_NUM*2))
{
aiṣedeede = MODBUS_RESPOND_POS_DATA;
fun (i=0;i
{
date_val = SYS_GET_U16(msg[aiṣedeede], msg[offset+1]);
aiṣedeede += 2;
}
main_win_disp_date ();
}
}
ofo main_win_read_temp_hum()
{
u8 old_slave_addr = SLAVE_ADDR;
sys_params.user_config [5] = TEMP_HUM_SLAVE_ADDR;
modbus_read_words (0, TEMP_HUM_VAL_MAX_NUM);
sys_params.user_config[5] = old_slave_addr;// Pada
}
ofo main_win_handler ()
{
aimi u8 flag = 0;
ti o ba jẹ (jẹ_akọkọ_win)
{
ti o ba jẹ (akoko_kika_itaniji==ALERT_READ_PERIOD)
{
alert_read_period = 0;
modbus_read_bits (510, ALERT_BIT_MAX_NUM);
pada;
}
ti o ba jẹ (ọjọ_imudojuiwọn_akoko = DATE_UPDATE_PERIOD)
{
date_update_period = 0;
modbus_read_words (180, MAIN_WIN_DATE_MAX_NUM);
pada;
}
asia = !flag;
ti (asia)
modbus_read_words (0, MAIN_WIN_VAL_MAX_NUM);
miiran
main_win_read_temp_hum ();
}
}
itọkasi koodu modbus rtu:
#pẹlu "modbus.h"
#pẹlu "crc16.h"
#pẹlu "sys_params.h"
# asọye UART_INCLUDE "uart2.h"
# asọye UART_INIT uart2_init
# ṣe asọye UART_SEND_BYTES uart2_firanṣẹ_baiti
# asọye UART_BAUD 9600
#sọtumọ MODBUS_RECV_TIMEOUT (u8)(35000.0f/UART_BAUD+2)
# ṣe alaye MODBUS_SEND_INTERVAL 150
#pẹlu UART_INCLUDE
aimi bit is_modbus_recv_complete = 0;
aimi u8 modbus_recv_buff [270];
aimi u16 modbus_recv_len = 0;// Lapapọ ipari ti awọn baiti gba
aimi u8 modbus_recv_timeout = 0;// Gba akoko aponsedanu
aimi iyipada u16 modbus_send_interval = 0;
MODBUS_PACKET apo;
ofo modbus_init()
{
UART_INIT(UART_BAUD);
}
ofo modbus_send_bytes (u8 * baiti, u16 lẹn)
{
UART_SEND_BYTES(baiti, lẹn);
}
ofo modbus_recv_byte(u8 baiti)
{
ti o ba jẹ (jẹ_modbus_recv_complete)
pada;
ti o ba (modbus_recv_len
modbus_recv_buff [modbus_recv_len ++] = baiti;
}
ofo modbus_check_recv_timeout()
{
ti o ba jẹ (modbus_recv_timeout)
{
modbus_recv_timeout--;
ti (modbus_recv_timeout==0)
{
is_modbus_recv_complete = 1;
}
}
}
u8 modbus_send_packet(u8 *packet)
{
u16 nikan;
u16 crc;
u8 func_code = soso[1];
nigba (modbus_send_interval);
ti (func_code==MODBUS_FUNC_CODE_10)
{
((MODBUS_10_PACKET*)packet)->byte_num = ((MODBUS_10_PACKET*)packet)->word_num*2;
len = 9+ ((MODBUS_10_PACKET*)packet)->byte_num;
}miiran ti(func_code==MODBUS_FUNC_CODE_0F)
{
len = ((MODBUS_0F_PACKET*)packet)->bit_num;
((MODBUS_0F_PACKET *) apo) -> byte_num = len / 8+ (len% 8? 1: 0);
len = 9+ ((MODBUS_0F_PACKET *) apo) -> byte_num;
}miiran
{
lẹn = iwọn (MODBUS_PACKET);
}
crc = crc16 (packet, len-2);
apo-iwe [len-2] = (u8) (crc>> 8);
apo-iwe [len-1] = (u8) crc;
modbus_send_bytes (packet, lẹn);
modbus_send_interval = MODBUS_SEND_INTERVAL;
pada 0;//Aseyori
}
ode ofo modbus_msg_handler(u8 *msg,u16 msg_len);
ofo modbus_handler ()
{
u16 crc;
ti (! is_modbus_recv_complete)
pada;
// Ṣayẹwo iye crc
crc = ((u16)modbus_recv_buff[modbus_recv_len-2]
ti (crc16 (modbus_recv_buff,modbus_recv_len-2) = crc)
{
modbus_msg_handler (modbus_recv_buff,modbus_recv_len);
}
modbus_recv_len = 0;
is_modbus_recv_complete = 0;
}
u8 modbus_send_fcode (u8 fcode, u16 addr, u16 lẹnsi)
{
packet.slave_addr = SLAVE_ADDR;
packet.func_code = fcode;// Koodu iṣẹ
packet.start_addr = addr;//Adirẹsi
packet.data_len = lẹnsi;// Iye ti a kọ
lẹn = modbus_send_packet ((u8*) & soso);
pada lẹnsi;
}
Akoko ifiweranṣẹ: Jan-12-2024