本期為大家推送一個很有創(chuàng)意的迪文開發(fā)者論壇獲獎開源案例——瀏覽器網(wǎng)頁與T5L迪文屏串口深度擴展(Node-RED技術(shù))。工程師使用T5L智能屏,通過Node-RED技術(shù),只需要一個串口,就可以接入互聯(lián)網(wǎng),實現(xiàn)迪文屏與瀏覽器網(wǎng)頁的數(shù)據(jù)交互。該方案實現(xiàn)了智能屏與網(wǎng)頁端的數(shù)據(jù)收發(fā)、圖表交互、基本信息顯示等功能。
Node-RED網(wǎng)頁端運行效果展示 (1)使用Node-RED技術(shù),以瀏覽器作為交互入口,使瀏覽器與屏幕通過串口交互,實現(xiàn)相應功能展示。
數(shù)據(jù)收發(fā)Tab頁面
圖標交互Tab頁面
基本信息Tab頁面效果
(2)Node-RED網(wǎng)頁端主要參考代碼如下:
{
"id": "fbb314a16ea00889",
"type": "serial in",
"z": "09e0777eaff7fdea",
"g": "c1661722c7db00f9",
"name": "串口接受數(shù)據(jù)",
"serial": "83fb45b5f4b51d61",
"x": 390,
"y": 140,
"wires": [
[
"685a2fb2c2dc8fba"
]
]
},
{
"id": "1ba3c6e812e03e27",
"type": "serial out",
"z": "09e0777eaff7fdea",
"g": "c1661722c7db00f9",
"name": "串口發(fā)送",
"serial": "83fb45b5f4b51d61",
"x": 860,
"y": 260,
"wires": []
},
{
"id": "5fb7f1d3d7425133",
"type": "status",
"z": "09e0777eaff7fdea",
"g": "c1661722c7db00f9",
"name": "監(jiān)聽串口狀態(tài)",
"scope": [
"fbb314a16ea00889"
],
"x": 390,
"y": 200,
"wires": [
[
"3f18d1fdea398d35"
]
]
},
{
"id": "3f18d1fdea398d35",
"type": "function",
"z": "09e0777eaff7fdea",
"g": "c1661722c7db00f9",
"name": "提取串口狀態(tài)",
"func": "let sta = msg.status.text;\nlet color = 'red';\nif (sta.indexOf('not-connected') >= 0) \n sta = '未連接';\nelse if (sta.indexOf('connected') >= 0)\n{\n sta = '連接成功';\n color = 'green';\n}else\n sta = '出現(xiàn)錯誤';\nmsg['payload'] = sta;\nmsg['color'] = color;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 620,
"y": 200,
"wires": [
[
"2ec78ff0b0b9a56f"
]
]
},
{
"id": "2ec78ff0b0b9a56f",
"type": "ui_template",
"z": "09e0777eaff7fdea",
"g": "c1661722c7db00f9",
"group": "4e4db779a7b91019",
"name": "顯示串口狀態(tài)",
"order": 1,
"width": 0,
"height": 0,
"format": "
\n 串口狀態(tài):
DGUS界面設計 C51工程設計
方案采用T5L智能屏串口2與Node-RED網(wǎng)頁通信,部分參考代碼如下:
#include "sys.h"
#include "uart2.h"
#include
#include
u8 buff[200];
void main(void)
{
u16num;
u16val;
u16old;
u8i;
sys_init();
uart2_init(115200);
old= 0;
while(1)
{
if(is_recv_complete)
{
uart2_buf[recv_len++]= 0;
uart2_buf[recv_len++]= 0;
if(strstr((char*)uart2_buf,"cmd"))
{
num= uart2_buf[3]-'0';
if(num<3)
{
for(i=0;i<3;i++)
{
val= (num==i);
sys_write_vp(0x2300+i,(u8*)&val, 1);
}
}elseif(num<5)
{
val= (num==3);
sys_write_vp(0x2200,(u8*)&val, 1);
}
}else
{
sys_write_vp(0x2000,uart2_buf, recv_len/2+2);
}
recv_len= 0;
is_recv_complete= 0;
}
sys_read_vp(0x1000,(u8*)&val, 1);
if(val==1)
{
sys_read_vp(0x2100,buff, 50);
for(i=0;i<100;i++)
{
if(buff==0xff)
{
buff= 0x00;
buff[i+1]= 0x00;
break;
}
}
u2_send_bytes(buff,strlen(buff));
val= 0;
sys_write_vp(0x1000,(u8*)&val, 1);
}
sys_read_vp(0x2400,(u8*)&val, 1);
if(val!=old)
{
sprintf(buff,"%d", val);
u2_send_bytes(buff,strlen(buff));
old= val;
}
}
}
-
串口
+關(guān)注
關(guān)注
14文章
1551瀏覽量
76421 -
瀏覽器
+關(guān)注
關(guān)注
1文章
1022瀏覽量
35325 -
迪文屏
+關(guān)注
關(guān)注
3文章
78瀏覽量
5382
發(fā)布評論請先 登錄
相關(guān)推薦
評論