Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.find("modem")
- if not modem then
- error("No modems attached")
- end
- function closeAll()
- modem.closeAll()
- end
- closeAll()
- function open(channel)
- if channel and channel >= 0 and channel <= 25565 then
- modem.open(channel)
- return true
- end
- return false
- end
- function send(channel, message)
- if not modem.isOpen(channel) then
- open(channel)
- end
- if channel and message then
- modem.transmit(channel, channel, message)
- end
- end
- function receive(channel, timeout)
- if not modem.isOpen(channel) then
- open(channel)
- end
- if timeout then
- time = os.startTimer(timeout)
- end
- while true do
- event = {os.pullEvent()}
- if event[1] == "modem_message" then
- return event[5]
- elseif event[2] == time then
- return "Timeout"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement