本期為大家推送一個很有創意的迪文開發者論壇獲獎開源案例——瀏覽器網頁與T5L迪文屏串口深度擴展(Node-RED技術)。工程師使用T5L智能屏,通過Node-RED技術,只需要一個串口,就可以接入互聯網,實現迪文屏與瀏覽器網頁的數據交互。該方案實現了智能屏與網頁端的數據收發、圖表交互、基本信息顯示等功能。
Node-RED網頁端運行效果展示 (1)使用Node-RED技術,以瀏覽器作為交互入口,使瀏覽器與屏幕通過串口交互,實現相應功能展示。
數據收發Tab頁面
圖標交互Tab頁面
基本信息Tab頁面效果
(2)Node-RED網頁端主要參考代碼如下:
{
"id": "fbb314a16ea00889",
"type": "serial in",
"z": "09e0777eaff7fdea",
"g": "c1661722c7db00f9",
"name": "串口接受數據",
"serial": "83fb45b5f4b51d61",
"x": 390,
"y": 140,
"wires": [
[
"685a2fb2c2dc8fba"
]
]
},
{
"id": "1ba3c6e812e03e27",
"type": "serial out",
"z": "09e0777eaff7fdea",
"g": "c1661722c7db00f9",
"name": "串口發送",
"serial": "83fb45b5f4b51d61",
"x": 860,
"y": 260,
"wires": []
},
{
"id": "5fb7f1d3d7425133",
"type": "status",
"z": "09e0777eaff7fdea",
"g": "c1661722c7db00f9",
"name": "監聽串口狀態",
"scope": [
"fbb314a16ea00889"
],
"x": 390,
"y": 200,
"wires": [
[
"3f18d1fdea398d35"
]
]
},
{
"id": "3f18d1fdea398d35",
"type": "function",
"z": "09e0777eaff7fdea",
"g": "c1661722c7db00f9",
"name": "提取串口狀態",
"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 = '出現錯誤';\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": "顯示串口狀態",
"order": 1,
"width": 0,
"height": 0,
"format": "
\n 串口狀態:
DGUS界面設計 C51工程設計
方案采用T5L智能屏串口2與Node-RED網頁通信,部分參考代碼如下:
#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;
}
}
}
-
串口
+關注
關注
14文章
1543瀏覽量
76185 -
瀏覽器
+關注
關注
1文章
1015瀏覽量
35271 -
迪文屏
+關注
關注
3文章
76瀏覽量
5373
發布評論請先 登錄
相關推薦
評論