NEQTO Docs
  • Languages iconEnglish
    • 日本語
  • Docs
  • API
  • FAQ

›neqto.js

Getting Started

  • NEQTO Hello World!
  • Tutorial Step 1. NEQTO Console Setting
  • Tutorial Step 2. Device Settings & Launching Service (NEQTO Bridge)
  • Tutorial Step 2. Device Settings & Launching Service (STM32 Discovery)
  • Tutorial Step 2. Device Settings & Launching Service (SPRESENSE)
  • Tutorial Step 3. Application development using scripts

NEQTO

  • NEQTO Account Registration
  • Sub-accounts
  • API Usage
  • NEQTO CloudSync for GCP
  • NEQTO Engine Firmware List
  • Support Guidelines

NEQTO Console

  • Introduction
  • Fundamentals
  • Administrative Actions
  • Device Management
  • Linux-based Device Management
  • Batch Registration
  • Scripts
  • Actions and Contacts
  • View Data from the Console
  • NEQTO Apps

    • About NEQTO Apps
    • NEQTO Infinitypool
    • NEQTO Insights
    • NEQTO Custodia
    • NEQTO Flow
  • Machine Driver
  • Recommended Browsers
  • Billing Information

SPRESENSE

    Hardware Specifications

    • 01. About Spresense

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. Spresense Wi-Fi Initial Setup
    • 04. Spresense LTE-M Initial Setup
    • 05. Debug Log Acquisition
    • 06. System LED Indications
    • 07. Event Messages
    • 08. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. GPIO
    • 12. UART
    • 13. SPI
    • 14. I2C
    • 15. ADC
    • 16. GNSS
    • 17. Camera
    • 18. Utils
    • 19. nqSpresense
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte

STM32 Discovery

    Hardware Specifications

    • 01. About STM32 Discovery Kit (B-L4S5I-IOT01A)

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. STM32 Discovery Wi-Fi Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 18. Utils
    • 19. nqDiscovery
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi

NEQTO Bridge

    Hardware Specifications

    • 01. NEQTO Bridge Module
    • 02. NEQTO Bridge Wi-Fi Module
    • 03. NEQTO Bridge LTE-1 Module
    • 04. NEQTO Bridge LTE-M/NB Module
    • 05. NEQTO Bridge IO Board
    • 06. NEQTO Bridge Digital IO Board
    • 07. NEQTO Bridge Connector Board

    Software Specifications

    • 01. Operational Flow
    • 02. NEQTO Bridge Wi-Fi Module Initial Setup
    • 03. NEQTO Bridge LTE Module Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 17. BLE
    • 18. Utils
    • 19. nqBridge
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte
    • 25. nqLAN
    • 26. nqEx

Linux-based device

    Software Specifications

    • 01. System Requirements
    • 02. Installation
    • 03. Software Configurations
    • 04. Operational Flow
    • 05. Debug Log Acquisition
    • 06. Event Messages
    • 07. Updating Software

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. RTC
    • 10. UNIXSocket
    • 11. FileSystem
    • 12. SubProcess
    • 13. Utils
    • 14. nqLinux
    • 15. nqService
    • 16. nqMqtt
    • 17. nqFOTA
    • 18. nqLAN

neqto.js Libraries

  • About neqto.js Libraries
  • UART

    • GM65 Barcode Reader
    • SRF Ultrasonic Range Finder - Serial Mode

    I2C

    • HTS221 v2 Temperature and Humidity Sensor
    • LIS2DW12 v2 Accelerometer
    • SRF Ultrasonic Range Finder - I2C Mode
    • [Archive] HTS221 Temperature and Humidity Sensor
    • [Archive] LIS2DW12 Accelerometer

    Utils

    • RTC Alarm Synchronized Scheduler

    Integration

    • AWS S3 v2
    • AWS IoT Core v2
    • Azure IoT v2
    • GCP IoT Core
    • [Archive] AWS S3
    • [Archive] AWS IoT Core

neqto.js Snippets

  • About neqto.js Snippets
  • DataDog
  • Dropbox
  • Google Sheets
  • InfluxDB
  • Oracle Cloud Object Storage
  • Salesforce
  • SAP Cloud Platform Internet of Things
  • Splunk
  • Niagara

Release Notes

  • NEQTO Console Updates
  • NEQTO Firmware (Bridge Wi-Fi/LTE Module) Releases
  • NEQTO Firmware (STM32 Discovery Wi-Fi) Releases
  • NEQTO Firmware (Spresense Wi-Fi/LTE-M) Releases
  • NEQTO Engine for Linux Releases

12. UART

The UART object is a built-in object that provides UART communication functions.



Abstracts

Methods()/PropertiesSummaryVersionNote
new UART()Creates a UART instance.01.00.00+

{UART} Instance

Methods()/PropertiesSummaryVersionNote
.open()Starts the communication.01.00.00+
.close()Ends the communication.01.00.00+
.send()Sends the data.01.00.00+
.receive()Receives the data.01.00.00+
.setRecvEvent()Registers the data reception callback process.01.00.00+
.setBufRecvEvent()Registers the buffering type data reception callback process.01.00.00+
.releaseRecvEvent()Releases the data reception callback process registered by .setRecvEvent() or .setBufRecvEvent().01.00.00+
.checkSendComp()Confirms that data transmission is completed.01.00.00+
.waitSendComp()Waits (blocks) until the data transmission is completed.02.00.00+
.checkRecvData()Checks if there is receivable data.01.00.00+
.checkRecvError()Checks the reception errors.02.00.00+


Details

new UART(nodeNo)

Creates a UART instance.

NameTypeM/OSummaryNote
nodeNonumbermandatorySpecifies the node number of the UART interface to be used.
Please refer to Pinout.
return{UART}-{UART} : Generated {UART}

.open(baudrate,flow,parity[,dataBit[,stopBit]])

Starts the communication.

NameTypeM/OSummaryNote
baudratenumbermandatoryCommunication speed
Specify the communication baudrate [bps].
Range: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
flowbooleanmandatoryHardware flow
true: Valid
false: Invalid
paritynumbermandatoryParity bit
0: None
1: Even
2: Odd
dataBitnumberoptionalData bit
0: 8-bit
1: 7-bit
The default value is 0.
Version 02.00.00+
stopBitnumberoptionalStop bit
0: 1-bit
1: 2-bit
The default value is 0.
Version 02.00.00+
returnboolean-true: Success
false: Failure

.close()

Ends the communication.

NameTypeM/OSummaryNote
returnboolean-true: Success
false: Failure

.send(data,block)

Sends the data.

NameTypeM/OSummary                                Note
dataArrayBuffer,
string
mandatoryTransmission data
ArrayBuffer : ArrayBuffer size will be sent.
string : The specified string is sent.
The maximum size that can be sent at one time is 512 bytes.
blockbooleanmandatorySpecify the transmission blocking process.
true: Enable blocking
false: Disable blocking
If disabled, all data specified in one process may not be sent. Please check the size of the transmitted data, and if necessary, retransmit from the continuination of the data.
returnnumber-Transmitted data sizeReturns -1 if the transmission failed.

.receive(isBin,recvLen)

Receives the data.
Since it is executed in non-block processing, the reception is not awaited.

NameTypeM/OSummaryNote
isBinbooleanmandatorySpecify the format of the received data.
true: Receive in binary data format
false: Receive in string format
recvLennumberoptionalSpecify the maximum receiving size [byte].
Range: 1 - 512
The default value is 512 bytes.
returnArrayBuffer,
string
-Received data
The return type is determined by isBin.
If isBin is true, the type is ArrayBuffer; otherwise, the type is string.
Data length will be less than or equal to the size specified in recvLen.
If there is no data received, the size will be 0.

.setRecvEvent(callback,isBin,recvLen)

Registers the data reception callback process.
Executes callback processing when data is received. When there is no data received, the callback processing does not occur.
In addition, it is not possible to re-register the callback process within the data reception callback process execution.

Cannot be used simultaneously with .setBufRecvEvent(), and should be used exclusively.

NameTypeM/OSummaryNote
callback(data)functionmandatoryExecutes callback processing when data is received.
data : {ArrayBuffer|string}
Received data
The type of the argument is determined by isBin.
If isBin is true, the type is ArrayBuffer; otherwise, the type is string.
Data length will be less than or equal to the size specified in recvLen.
isBinbooleanmandatorySpecifies the format of the received data.
true: Receive in binary data format
false: Receive in string format
recvLennumberoptionalSpecifies the maximum receiving size in Bytes.
Range: 1 - 512
The default value is 512 bytes.
returnboolean-true: Success
false: Failure

.setBufRecvEvent(callback,buff)

Registers the buffering type data reception callback process.
Executes the callback process when the received data accumulates for the specified buffer size.
After the callback, the data reception callback process will be released. To continue waiting for data reception, register the callback process again.
In addition, it is not possible to re-register the callback process within the data reception callback process execution.

Received data is written directly to the specified buffer. Although efficient, as the writing and reading will conflict, this can be used for synchronous control where the receive data length is fixed and the receive timing is guaranteed.

Cannot be used simultaneously with .setRecvEvent(), and should be used exclusively.

NameTypeM/OSummaryNote
callback(dataLen)functionmandatoryExecutes the callback process when the received data accumulates for the specified buffer size.
dataLen : {number}
Receive data length
dataLen will be always specified buffer size.
buffArrayBuffermandatorySpecifies the buffer for writing the received data.Received data is written directly to the specified buffer.
returnboolean-true: Success
false: Failure

.releaseRecvEvent()

Releases the data reception callback process registered by .setRecvEvent() or .setBufRecvEvent().

NameTypeM/OSummaryNote
returnboolean-true: Success
false: Failure

.checkSendComp()

Confirms that data transmission is completed.

NameTypeM/OSummary                                    Note
returnboolean-Transmission status
true: Transmission complete
false: Transmission in progress
When the UART send buffer is empty and the hardware is in the send complete state, it is determined that the transmission is complete.

Version 01.03.02 or older:
Number type is returned.
1: Transmission complete
0: Transmission in progress
When the UART send buffer is empty, it is determined that the transmission is complete.

.waitSendComp()

Waits (blocks) until the data transmission is completed.

NameTypeM/OSummaryNote
returnundefined-When the UART send buffer is empty and the hardware is in the send complete state, it is determined that the transmission is complete.

.checkRecvData()

Checks if there is receivable data.

NameTypeM/OSummaryNote
returnboolean-true: With received data
false: Without received data

.checkRecvError()

Checks the reception errors.
Error causes are represented by bit flags.
When a receive error is detected, the target bit flag is set to 1.
In addition, after this method is called, all bit flags are cleared to 0 once.

This function is not supported. 0 is always returned.

NameTypeM/OSummary                            Note
returnnumber-Error causes
bit 0: Parity error
bit 1: Framing error
bit 2: Noise detection flag
bit 3: Overrun error
The value is always 0 when no receive error has occurred.



Object Usage Examples

Sample 1

This is a sample that sends and receives string data.
Displays the received data using the .setRecvEvent() method.

var NODE_NO = 2;
var BAUDRATE = 115200;

var uart = new UART(NODE_NO);
uart.open(BAUDRATE, false, 0);

uart.setRecvEvent(function(data) {
    print('recv: ' + data);
}, false, 128);

while(1) {
    uart.send('Hello World!\r\n', true);
    setTimeout(1000).wait();
}

uart.releaseRecvEvent();
uart.close();

Sample 2

This is a sample that sends and receives binary data.
Displays the received data using the .setRecvEvent() method.

var NODE_NO = 2;
var BAUDRATE = 115200;

var uart = new UART(NODE_NO);
uart.open(BAUDRATE, false, 0);

var sendCnt = 0;
var sendBuff = new ArrayBuffer(1);
var sendArr = new Uint8Array(sendBuff);

uart.setRecvEvent(function(buff) {
    var arr = new Uint8Array(buff);
    var dump = '';
    for(var i=0; i<arr.length; i++) {
        dump += ('00' + arr[i].toString(16).toUpperCase()).substr(-2) + ' ';
    }
    print('recv(' + arr.length + '): ' + dump);
}, true, 128);

while(1) {
    sendArr[0] = sendCnt;
    uart.send(sendBuff, true);
    setTimeout(1000).wait();
    sendCnt++;
    sendCnt &= 255;
}

uart.releaseRecvEvent();
uart.close();

Sample 3

This is a sample that sends and receives data.
Waits for data reception to the receive buffer to complete using the .setBufRecvEvent() method.

var NODE_NO = 2;
var BAUDRATE = 115200;

var uart = new UART(NODE_NO);
uart.open(BAUDRATE, false, 0);

var received = false;
var recvBuff = new ArrayBuffer(8);

uart.setBufRecvEvent(function(dataLen) { //one-shot
    var arr = new Uint8Array(recvBuff);
    var dump = '';
    for(var i=0; i<arr.length; i++) {
        dump += ('00' + arr[i].toString(16).toUpperCase()).substr(-2) + ' ';
    }
    print('recv(' + dataLen + '): ' + dump);
    received = true
}, recvBuff);

while(!received) {
    uart.send('Waiting for ' + recvBuff.byteLength + ' bytes of data to be received.\r\n', true);
    setTimeout(1000).wait();
}

print('finished');

uart.close();



Updated: 2022-06-02
← 11. GPIO13. SPI →
  • Abstracts
    • {UART} Instance
  • Details
    • new UART(nodeNo)
    • .open(baudrate,flow,parity[,dataBit[,stopBit]])
    • .close()
    • .send(data,block)
    • .receive(isBin,recvLen)
    • .setRecvEvent(callback,isBin,recvLen)
    • .setBufRecvEvent(callback,buff)
    • .releaseRecvEvent()
    • .checkSendComp()
    • .waitSendComp()
    • .checkRecvData()
    • .checkRecvError()
  • Object Usage Examples
    • Sample 1
    • Sample 2
    • Sample 3
AboutNewsProductsFAQPrivacy Policy}
NEQTO Console
IntroductionFundamentalsAdministrative ActionsDevice Management NEQTO Apps
NEQTO Bridge
NEQTO Bridge ModuleNEQTO Bridge Wi-Fi ModuleNEQTO Bridge LTE-1 ModuleError Logging Event Messages
API Documentation
API UsageGlobal APIRegional APIAPI Terms of Service
Jigsaw, Inc.
© 2023 JIG-SAW INC.