About the use of serial ports in scripts

I use matek h743 flight controller. I want to use a script to make a multi-machine automatic formation system. Among them, I need to use the serial port for communication, but do not use the original mavlink protocol. Suppose I use serial port number 4 for communication. So I set port 4 SERIAL4_PROTOCOL to -1. Then refer to the script serial_test.lua and put it into the SD card of the flight controller, but found that the script did not run normally. In addition, there are few script descriptions about the serial port, and I can’t find any information. , the routine also doesn’t work properly in my flight controller. Hope to get help.
Is it possible to provide a script to let the serial port of the flight control receive the data packet and then send the routine of the data packet. thank you very much

This problem has been solved. For the H743 flight controller, the corresponding serial port function needs to be enabled first (note that the serial number of the flight controller does not correspond to the hardware serial port number)
1: Enable function is 28
2: Turn on the script function in the flight control
3: Put the script into the script folder in the SD card
4: Restart the flight control
5: Use USB to serial port to view the serial port data sent by the flight controller

local port = serial:find_serial(0)

if port then



gcs:send_text(0, “OKOKOKOKOKOKOKOKOKO”)

local step = 65

function spit ()

if port:available() > 0 then

  read = port:read()

  gcs:send_text(0, read .. " = " .. step)


if step > 122 then

  step = 65


  step = step + 1

  gcs:send_text(6, step)



return spit, 1000


return spit, 1000


gcs:send_text(6, “NO!!!1”)