Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------
- ------------------------------------------------------------------
- local codename = 'calicommAPI'
- local codeversion = '0.1.0.1'
- local whoami = tonumber(os.getComputerID ())
- print (">>>"..codename.." Version "..codeversion.."@ID:"..whoami)
- local hardwaresides = redstone.getSides ()
- local verbose = false
- modemtable = {}
- ------------------------------------------------------------------
- function enableDebug (debugswitch)
- if (type(debugswitch) == 'boolean') then
- verbose = debugswitch
- end
- end
- ------------------------------------------------------------------
- function initModems ()
- if (verbose) then print ("*calicommAPI.initModems: called...") end
- for i=1,#hardwaresides do
- local modemside = hardwaresides[i]
- local device = peripheral.getType (modemside)
- if (device == 'modem') then
- local modemhandle = peripheral.wrap (modemside)
- local iswlanmodem = modemhandle.isWireless ()
- if (iswlanmodem) then
- if (verbose) then print ("*calicommAPI.initModems: found WIRELESS modem @"..modemside) end
- else
- if (verbose) then print ("*calicommAPI.initModems: found WIRED modem @"..modemside) end
- end
- table.insert (modemtable, {modemhandle, modemside, iswlanmodem})
- end
- end
- if (verbose) then print ("*calicommAPI.initModems: found "..#modemtable.." modems") end
- return #modemtable
- end
- ------------------------------------------------------------------
- function openModemChannel (modemhandle, modemchannel)
- if (verbose) then print ("*calicommAPI.openModemChannel: trying to open channel: "..modemchannel) end
- if ((modemchannel < 1) or (modemchannel >= 65535)) then
- if (verbose) then print ("*calicommAPI.openModemChannel: invalid channel!") end
- return false
- else
- if (modemhandle.isOpen (modemchannel)) then
- if (verbose) then print ("*calicommAPI.openModemChannel: channel already open!") end
- return false
- end
- modemhandle.open (modemchannel)
- if (modemhandle.isOpen (modemchannel)) then
- if (verbose) then print ("*calicommAPI.openModemChannel: opening channel: success!") end
- return true
- else
- if (verbose) then print ("*calicommAPI.openModemChannel: opening channel: failure!") end
- return false
- end
- end
- end
- ------------------------------------------------------------------
- function closeModemChannel (modemhandle, modemchannel)
- if (verbose) then print ("*calicommAPI.closeModemChannel: trying to close channel: "..modemchannel) end
- if ((modemchannel < 1) or (modemchannel >= 65535)) then
- if (verbose) then print ("*calicommAPI.closeModemChannel: invalid channel!") end
- return false
- else
- if (not modemhandle.isOpen (modemchannel)) then
- if (verbose) then print ("*calicommAPI.closeModemChannel: channel not open!") end
- return false
- end
- modemhandle.close (modemchannel)
- if (modemhandle.isOpen (modemchannel)) then
- if (verbose) then print ("*calicommAPI.closeModemChannel: closing channel: failure!") end
- return false
- else
- if (verbose) then print ("*calicommAPI.closeModemChannel: closing channel: success!") end
- return true
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment