User Guide for tuya models including: PLC Gateway Development Framework Software, Gateway Development Framework Software, Development Framework Software, Framework Software

PLC Sub-Device Connectivity-TuyaOS-Tuya Developer


File Info : application/pdf, 6 Pages, 52.08KB

PDF preview unavailable. Download the PDF instead.

PLC Sub-Device Connectivity TuyaOS TuyaOS
PLC Sub-Device Connectivity
Version: 20250317
Online Version

Contents Contents 1. Background information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2. Development guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.1. Configuration description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.2. Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
I

1Background information Power Line Communication (PLC) sub-device connectivity is designed to help you easily develop PLC gateways. Tuya's hardware and software-integrated solution provides PLC module and software implementation, allowing you to build a PLC gateway with no code and connect to PLC sub-devices in the Tuya ecosystem. This topic describes how to use the PLC features with the TuyaOS Gateway Development Framework.
1 / 4

1. Background information

1Background information

Developing a PLC gateway has a high barrier to entry and a long development cycle. Tuya's hardware and software-integrated solution makes complicated gateway development simple. Even if you do not have any PLC knowledge, you can build a PLC gateway cost-effectively. Connect your hardware to Tuya's PLC module through the serial port and enable PLC features in the software. Then, your product becomes PLC-capable and can connect to Tuya-enabled sub-devices.

2 / 4

2. Development guide

2Development guide

This section describes how to enable PLC features with the TuyaOS Gateway Development Framework by making API calls. Two interfaces are used to enable PLC features: PLC initialization tuya_plc_svc_init and PLC startup tuya_plc_svc_start . They have the same parameters in JSON used for configurations.

2.1. Configuration description

Fields in the JSON data: Field
dev_name cts
baud_rate

Description Specifies the serial port number. Specifies whether to enable hardware

flow control. Valid values:

·

1 : Enable

·

0 : Disable Whether to enable

hardware flow control depends on

the PLC module you use. The baud rate for serial

communication between the PLC

module and the gateway's

microcontroller chip. Set the baud rate

according to the requirements of the

PLC module you use.

2.2. Example

1 // ...

2 #include "user_plc_svc.h"

3 int main(int argc, char **argv)

4{

5 ty_cJSON *app_cfg = ty_cJSON_CreateObject();

6

if (app_cfg == NULL) {

7

return OPRT_CJSON_GET_ERR;

8

}

9

ty_cJSON_AddStringToObject(app_cfg, "storage_path", "./");

10

ty_cJSON_AddStringToObject(app_cfg, "cache_path", "/tmp/");

3 / 4

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
32 }

// Set a storage path TUYA_CALL_ERR_RETURN(tuya_set_config(app_cfg));
ty_cJSON *plc_cfg = ty_cJSON_CreateObject(); if (plc_cfg == NULL) {
return OPRT_CJSON_GET_ERR; } ty_cJSON_AddStringToObject(plc_cfg, "dev_name", "/dev/ttyS2"); ty_cJSON_AddNumberToObject(plc_cfg, "cts", 1); ty_cJSON_AddNumberToObject(plc_cfg, "baud_rate", 921600);
// Initialize the PLC service TUYA_CALL_ERR_RETURN(tuya_plc_svc_init(plc_cfg));
// Start the PLC service TUYA_CALL_ERR_RETURN(tuya_plc_svc_start(plc_cfg));
// ...
return 0;

4 / 4



References

Typst 0.13.0