Improve Create peripheral detection and add diagnostics
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
-- Writes all attached peripheral types, methods and Block Reader data to a file.
|
||||
|
||||
local outputName = "create_debug.txt"
|
||||
local output = assert(fs.open(outputName, "w"))
|
||||
|
||||
local function writeLine(text)
|
||||
text = tostring(text or "")
|
||||
output.writeLine(text)
|
||||
print(text)
|
||||
end
|
||||
|
||||
local names = peripheral.getNames()
|
||||
table.sort(names)
|
||||
|
||||
writeLine("CREATE PERIPHERAL DEBUG")
|
||||
writeLine("Computer ID: " .. os.getComputerID())
|
||||
writeLine("Peripherals: " .. #names)
|
||||
writeLine("")
|
||||
|
||||
for _, name in ipairs(names) do
|
||||
local types = { peripheral.getType(name) }
|
||||
local methods = peripheral.getMethods(name) or {}
|
||||
table.sort(methods)
|
||||
|
||||
writeLine(("[%s]"):format(name))
|
||||
writeLine("Types: " .. table.concat(types, ", "))
|
||||
writeLine("Methods: " .. table.concat(methods, ", "))
|
||||
|
||||
local hasBlockData = false
|
||||
for _, method in ipairs(methods) do
|
||||
if method == "getBlockData" then hasBlockData = true end
|
||||
end
|
||||
|
||||
if hasBlockData then
|
||||
local ok, data = pcall(peripheral.call, name, "getBlockData")
|
||||
writeLine("getBlockData OK: " .. tostring(ok))
|
||||
writeLine(ok and textutils.serialize(data) or tostring(data))
|
||||
end
|
||||
writeLine("")
|
||||
end
|
||||
|
||||
output.close()
|
||||
print("Fertig: " .. outputName)
|
||||
Reference in New Issue
Block a user