当前位置:网站首页>Alibaba cloud development board haas510 responds to UART serial port instructions
Alibaba cloud development board haas510 responds to UART serial port instructions
2022-06-12 13:48:00 【TMS320VC5257H】
Abstract : When developing IOT devices , Commonly used MCU+ Hardware structure of IOT module ,HaaS510 It is a very good IOT module . This article shares with you HaaS510 On the basis of success in the cloud , How to respond to UART Serial port instruction .

The experiment purpose : adopt haas510 Receive the serial port instructions from the upper computer , adopt DEBUG Serial port display .
Hardware :haas510 (2.0 edition ),USB A serial port
Software :win7 x64,vscode
Catalog
1.HaaS510 There are several serial ports on the board ?
2. Principle of receiving and sending serial port instructions
3.amp Light application on the use of serial port
4. Write serial port response code
5. Observe the operation effect
1.HaaS510 There are several serial ports on the board ?
The serial port on the development board has 2 individual , They are user serial ports MAIN UART And debug serial port DEBUG UART.

HaaS510 Is based on EC600S Developed , Its external serial port is EC600S Serial port .EC600S The module leads out the stamp hole , There are also pads at the bottom . As shown in the red box below ,EC600S In the pins of the module , It provides 2 A serial port , One of them is debugging , The other is that users use .

because EC600S The necessary circuits have been encapsulated in a solid metal shell , So if you use these two serial ports , It is only necessary to lead the wire to the corresponding terminal . The terminal blocks used in the Alibaba cloud development board are XH2.54.

2. Principle of receiving and sending serial port instructions
The author drew a diagram , Used to explain the basic process of serial communication . In different MCU When programming , The code is different , But the core content is the same , Is to receive in turn , There is a buffer when receiving , When the buffer is full, there will be an interrupt , After the interrupt, you should respond , There may also be data verification and other contents . It often takes dozens of lines of code to receive and process a string .
The purpose of this experiment is to realize HaaS510 Receive the instructions from the upper computer , After receiving the command , We can parse these instructions , Or upload it to the Internet of things platform as data . In order to observe whether the data is received correctly , We adopt the method of receiving and then sending it through the serial port . If the same is sent and received , Then it proves that the experiment is successful .

3.amp Light application on the use of serial port
Use “ Low code ” Of course, we don't want to use too many statements to deal with an old serial port .
HaaS The team has helped us do well .
Just use JavaScript.
official API Help document connection is
uart - A serial port https://help.aliyun.com/document_detail/268752.html
https://help.aliyun.com/document_detail/268752.html
because JavaScript The language uses an event driven mechanism to respond to user actions , Alibaba cloud has helped us to UART Time and bottom driver debugging are done .
therefore , We can pass a very simple JavaScript sentence , Respond to the upper computer or other MCU Serial port command event sent , The complex serial communication process can be realized .
stay HaaS in , The name of this event is “data”. Name is what it is , What is passed on the serial port is indeed “data”.
The reference operation for programming this event is :

4. Write serial port response code
The purpose of this experiment is to haas510 Receive the serial port instructions from the upper computer , adopt DEBUG Serial port display .
We're in a HaaS510 Debug on the basis of the routine that successfully goes to the cloud and reports attributes . This facilitates the next step of uploading the data received by the serial port to the cloud .
The code is as follows :
var iot = require('iot');
var network = require('network');
var uart = require('uart');
var net = network.openNetWorkClient();
/* For information about device triples, please refer to common In the catalog iot Component description */
var productKey = 'gcXXXXXvu2';
var deviceName = 'cewSSSSS001';
var deviceSecret = 'ee213aSSSSSSSSSadcdedb3a9';
// Build Internet of things connection instances
var device;
var lightSwitch = 0;
// Open the user serial port , stay HaaS in , The serial port number of the user is UART2
var serial = uart.open({
id: 'UART2'
});
var msgbuf = [97, 98, 99, 100];
function ArrayToString(fileData) {
var dataString = "";
for (var i = 0; i < fileData.length; i++) {
dataString += String.fromCharCode(fileData[i]);
}
return dataString;
}
//net.on It is used to connect the IOT platform with triple data , The core is to implement a MQTT client
net.on('connect', function () {
device = iot.device({
productKey: productKey,
deviceName: deviceName,
deviceSecret: deviceSecret,
region: 'cn-shanghai',
success: function () {
console.log('iot: [success] connect');
},
fail: function () {
console.log('iot: [failed] connect');
}
});
})
// Timing procedure , This program implements 5 Second timing , Turn the status of the main light switch every time , Send an array of data to the user serial port
// Then send the main light switch status to the Internet of things platform
setInterval(function () {
lightSwitch = 1 - lightSwitch;
// user uart send data
serial.write(msgbuf);
/* Error model iot.postProps({
payload: {LightSwitch:'0'}
})*/
/* Correct demonstration , To send attributes , You have to use stringify Talent */
device.postProps(
JSON.stringify({
LightSwitch: lightSwitch
})
);
}, 5000);
// serial.on Used to respond to serial port data receiving events , What does the user receive through the serial port , Just send something through the debugging serial port .
// Be careful , The two serial ports are not the same .
serial.on('data', function(data) {
console.log('uart receive data is ' + ArrayToString(data));
});
5. Observe the operation effect
The effect we want to achieve is based on cloud online on the device , Receive the upper computer or MCU Serial port instructions sent .
First connect the hardware to the computer , Here we use 2 A serial port .

Then burn the program , Please refer to the article for the method of burning
Alibaba cloud development board vscode Development environment construction https://blog.csdn.net/youngwah292/article/details/120356887?spm=1001.2014.3001.5501
https://blog.csdn.net/youngwah292/article/details/120356887?spm=1001.2014.3001.5501
Open the Internet of things platform , Check whether the device is online

Then observe whether the interval 5 Second report attribute , It is found that attributes can be reported normally .

Next open 2 A serial port assistant , Corresponding to user serial port and debugging serial port respectively . It was found by experiment that , Achieved the desired effect . The information received is complete 、 accuracy .

The core code actually has only one sentence , In a word , Can be realized HaaS510 Keep an eye on the data on the user's serial port , Once there's data , Just send it out .
serial.on('data', function(data) {
console.log('uart receive data is ' + ArrayToString(data));
});In engineering application , It is very common to use the serial port to connect the IOT module . The company's original hardware engineers can focus on the research and development of hardware functions , When the device is on the cloud , Just connect an Internet of things module , What data needs to be sent on the cloud , Send instructions directly through the serial port .
The Internet of things device with this structure has a disadvantage , The structure is loose , The reliability is not particularly high . For example AT IOT module in the form of instructions , It requires multiple steps to operate before it can be put into the cloud , If you want to report attributes , Complex string operation is required to obtain the effect required by cloud settings .
It's about using HaaS510 Can make up for this shortcoming .HaaS510 Only a few statements are needed to implement the cloud on the device .
Today we learned to use 1 A statement can realize the receiving of serial port instructions ,HaaS The simplicity of .
next step , We will directly submit the data obtained through the serial port to the cloud platform .
边栏推荐
- [wustctf2020] selfie score query -1
- Tinyxml Usage Summary
- Top 10 tips for visual studio code on Google
- 【视频课】android studio物联网APP设计制作全套教程--国庆期间全掌握
- 618 entered the second half of the period, apple occupied the high-end market, and the domestic mobile phones finally undercut the price competition
- Codeforces 1629 C. Mexico array - simple greed
- 【SemiDrive源码分析】【X9芯片启动流程】25 - MailBox 核间通信机制介绍(代码分析篇)之 RPMSG-IPCC RTOS & QNX篇
- Explanation of static and extern keywords
- Factory mode of "object creation" mode
- Qualcomm platform development series (Protocol) QMI brief introduction and usage
猜你喜欢

Qualcomm platform development series (Protocol) QMI brief introduction and usage

Web3.0, the era of "stimulating creativity"

Data type conversion and conditional control statements

【视频课】android studio物联网APP设计制作全套教程--国庆期间全掌握

编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构

D1 Nezha Development Board understands the basic startup and loading process

Implementing singleton mode of database under QT multithreading

Scyther工具形式化分析Woo-Lam协议

Is MySQL query limit 1000,10 as fast as limit 10? How to crack deep paging

Possible solutions to problems after CodeBlocks installation
随机推荐
一种快速创建测试窗口的方法
Use of awlive structures
1414: [17noip popularization group] score
Codeforces 1629 E. grid XOR - simple thinking
Install RPM package offline using yum
上海解封背后,这群开发者“云聚会”造了个AI抗疫机器人
播放器屏幕方向方案
Recursion of subviews of view
There was an error installing mysql. Follow the link below to CMD
通过loganalyzer展示数据库中的日志
Realization of Joseph Ring with one-way ring linked list
Cocoapods的相关知识点
Pytorch to onnx, onnxruntime reasoning in mmclas
Go language functions as parameters of functions
Codeforces 1629 B. GCD arrays - simple thinking
Real time software source code of COVID-19
Acwing: topology sequence
Application of binary search -- finding the square root sqrt of a number
AVFoundation
Seekg, tellg related file operations