Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local printerid
- local cur_docid = 1
- local function packet(iType, id, cmd, data)
- if type(data) == "table" then
- data = textutils.serialize(data)
- end
- rednet.send(printerid, textutils.serialize({dataroot = {["type"] = iType, packetid = id, cmd = cmd, data = data}}))
- end
- local function waitForRespose()
- while true do
- id, msg, disance = rednet.read(5)
- if id == nil then return false, "Connection timed out" end
- if id == printerid then
- p = textutils.unserialize(msg)
- if p.dataroot == nil then
- return false, "Unknown Packet received. Printserver may be bugged"
- end
- p = p.dataroot
- if p['type'] == 5 then
- return false, p.data
- elseif p['type'] == 6 then
- return true, p.data
- else
- return false, "Unknown Packet received. Printserver may be bugged"
- end
- end
- end
- end
- function getCursorPos()
- -- Not avaible yet
- return nil
- end
- function getPaperLevel()
- -- Not avaible yet
- return nil
- end
- function setCursorPos(docid, x, y)
- packet(3, docid, "setCursorPos", {x, y})
- return waitForResponse()
- end
- function newPage(docid)
- packet(3, docid, "newPage", {})
- return waitForResponse()
- end
- function write(docid, text)
- packet(3, docid, "write", {text})
- return waitForResponse()
- end
- function setPageTitle (docid, title)
- packet(3, docid, "setPageTitle", {title})
- return waitForResponse()
- end
- function endPage (docid)
- packet(3, docid, "endPage", {})
- return waitForResponse()
- end
- function startPrinting(printerid)
- local docid = curdocid..os.time()..os.computerID()
- curdocid = curdocid + 1
- packet(1, docid, "", "")
- s, m = waitForResponse()
- if s then
- return true, m, docid
- else
- return false, m
- end
- end
- function endPrinting(docid)
- packet(2, docid, "", "")
- return waitForResponse()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement