I've successfully written scripts to communicate over RS232 using ASCII protocol (not Modbus). There is essentially no documentation on it, but the coding isn't too hard.
Start with the following code placed near the top of your Screen Load script:
--Place this code at the top of the screen load script
--Open the COM port immediately upon loading Mach 4. Com port remains open until Mach 4 closes
rs232 = require("luars232")
port_name = "COM1"
local out = io.stderr
---------------------------------------------------------------
-- Initialize Communications --
---------------------------------------------------------------
--Open Serial Port 8N1 38400 baud
local e, p = rs232.open(port_name)
if e ~= rs232.RS232_ERR_NOERROR then
mc.mcCntlSetLastError(inst, "Cannot Open Serial Port")
return
end
-- set port settings
assert(p:set_baud_rate(rs232.RS232_BAUD_38400) == rs232.RS232_ERR_NOERROR)
assert(p:set_data_bits(rs232.RS232_DATA_8) == rs232.RS232_ERR_NOERROR)
assert(p:set_parity(rs232.RS232_PARITY_NONE) == rs232.RS232_ERR_NOERROR)
assert(p:set_stop_bits(rs232.RS232_STOP_1) == rs232.RS232_ERR_NOERROR)
assert(p:set_flow_control(rs232.RS232_FLOW_OFF) == rs232.RS232_ERR_NOERROR)
This opens a serial port on your computer and allows you to read and write.
The serial write function takes a string and transmits it over the serial port opened above. It returns an error if applicable, and the length of the string written on the port.
err, len_written = p:write(string, timeout)
The Serial Read function pulls the characters from Windows' serial buffer (default 4096 bytes/characters) which keeps track of the incoming data behind the scenes. Once you read a character from the buffer, it is gone forever so reading empties the buffer. It returns an error if applicable, the data (as a string), and the length/size of the string.
err, data_read, size = p:read(read_length, timeout)
This is a very high level overview. I'd be happy explain more if this is what you are looking for.
I should add that no special packages, libraries, dll's, or anything else need to be added for this to work. Just a clean install of a recent version of Mach 4.