Abstract: A embedded communication scheme based on Lua script language was designed for various peripheral devices in substations that use UART serial communication protocol for information transmission in the development of IED intelligent devices that require communication with them. Through this scheme, the construction and parsing of specific serial port packet protocols can be handed over to Lua scripts for processing, allowing designers to focus only on the design of their interaction interfaces with peripheral devices and Lua scripts in the software development of specific devices, without worrying about specific serial port communication protocols. This provides a field configurable solution for device serial port communication, improving the flexibility of device applications.
introduction
With the gradual improvement of substation intelligence, there is an increasing demand for DNC115 to collect on-site state parameters such as temperature and humidity. At present, in on-site applications, such devices often use UART serial communication methods such as RS232 or RS485 to interact with Intelligent Electronic Device (IED) devices. Generally speaking, different devices use different communication data frame formats. The various serial data frame formats pose certain difficulties for the software standardization of IED devices. The traditional approach is usually for the device manufacturer to specify and match the peripheral equipment, and the flexibility of the device is not ideal. This article proposes a solution based on Lua scripting language to address such issues, which can effectively improve the adaptability of IED devices to various types of serial port data packet frame formats. This scheme hands over the construction and parsing of specific serial port packet protocols to Lua scripts for processing, allowing designers to focus only on the design of relevant interfaces in device software development, without worrying about specific serial port communication protocols. This facilitates software finalization and improves the flexibility of the device itself in applications.
Introduction to Lua Script Language
Lua is an open-source, free, and lightweight embedded scripting language that fully utilizes ANSI (ISO) C. This makes it very suitable for integration into embedded development environments primarily based on C language. The key to achieving interaction between the two lies in a virtual stack, which, along with the relevant interface functions provided by Lua, allows for convenient transfer of various types of data between them.
Compared with other scripting languages such as Perl, Tcl, Python, etc., Lua has demonstrated sufficient simplicity and very high execution efficiency. Combined with its high platform independence and sufficient scalability, it has gained more and more attention from people. Therefore, in this article, Lua script is preferred for design.
Overview of 2 System Solutions
This scheme is mainly designed around the communication between the IED device and peripheral serial devices, and the system framework is shown in Figure 1.
Figure 1 System Framework
Figure 1 System Framework
When the IED device starts running, DNC115 will create a read and write scheduling task for UART communication. In this task, first use the interface functions provided by Lua to start its script engine and create the Lua virtual machine. Then, the C function written by the user can be registered into the Lua virtual machine, and the Lua script files that exist in the Flash file system and are independent of the device C program can be loaded into the virtual machine, thereby establishing the interaction environment between Lua and C. In system applications, the specific data content that needs to be sent to peripheral devices is placed in Lua script files. When the device C program needs to send data, the communication read/write scheduling program and virtual machine cooperate to retrieve this part of the data and call the serial port driver program to send it to peripheral devices. When receiving a message from the peripheral device to the IED device, the corresponding data is then transmitted to the script program running in the virtual machine for processing, and Lua calls the registered C function for relevant business processing based on the data processing results.
Figure 2 System Program Flow
Figure 2 System Program Flow
The program flow of this system is shown in Figure 2.
Among them, the serial communication chip is implemented using TI’s 4-channel programmable UART chip TL16C754B with 64 byte FIFO. Its four channels can be independently programmed, and under an operating voltage of 3.3 V, the data transmission rate can reach up to 2 Mbps, which is suitable for applications in various UART communication environments [2]. Based on the device’s application environment, this article adopts the RS485 question answering mechanism and combines query methods to design the serial communication scheme. In the implementation of the plan, the device will send a query message through the serial port chip every certain period of time. When the correct response message sent by the peripheral device is found, relevant business processing will be carried out.