Jump to content


p3p's Content

There have been 4 items by p3p (Search limited from 22-October 19)


By content type

See this member's

Sort by                Order  

#214031 possible openperipheral bug

Posted by p3p on 14 April 2015 - 11:40 PM in Ask a Pro

Ah that explains that, thank you,
I was aware of how the events where distributed but for some reason I didn't think of that, the design is indeed far overly complicated for the example but that was just a reproduction of my problem, the modules are basically drivers that are loaded when a device is detected, they then register with the event system and the driver responds to events, the problems started when my drivers started yielding in the event chain and the events where eaten, to avoid that i need to run then in a seperate parallel method, which caused more problems, but I'm getting there,
Thanks again for the help



#214014 possible openperipheral bug

Posted by p3p on 14 April 2015 - 07:42 PM in Ask a Pro

while experimenting with coroutines and handling event loss during peripheral calls I am having an odd issue, if I try and use peripheral call on an openperipheral peripheral inside a coroutine, (I understand the entire comutercraft system runs on coroutines and thats what makes this odd) it triggers an internal error.

[20:31:27] [Coroutine-258/INFO] [OpenMods]: Unwrapped error during method getPlayers(9) execution on peripheral openperipheral_sensor, args: []
java.lang.ArrayIndexOutOfBoundsException

This is how I reproduced the error I was having:
openpsensor = peripheral.wrap("top")
remote_computer = peripheral.wrap("computer_1")
--module
function sensor_reader()
  while true do
	--standard peripheral is fine
	print(remote_computer.getID())
	--internal error here
	status, value = pcall(openpsensor.getPlayers)
	if status == true then
	  print(textutils.serialize(value))
	else
	  print(value)
	end
	coroutine.yield()
  end
end
--state
local modules = { ["next_pid"] = 1, ["routines"] = {}, ["event_router"] = {}, ["events"] = {} }
function modules.add(func)
  modules.routines[modules.next_pid] = coroutine.create(func)
  modules.next_pid = modules.next_pid + 1
end
--Kernel
function process()
  while true do
	for i,v in ipairs(modules.routines) do
	  coroutine.resume(v)
	end
	--openperipheral works here
	status, value = pcall(openpsensor.getPlayers)
	if status == true then
	  print(textutils.serialize(value))
	else
	  print(value)
	end
	os.pullEvent("tick")
  end
end
function event_distribute()
  while true do
	local event = {os.pullEvent()}
  end
end
function ticker()
  while true do
	os.queueEvent("tick")
	os.sleep(0.05)
  end
end
--startup
modules.add(sensor_reader)
parallel.waitForAny(process, event_distribute, ticker)

I would just like some feedback as to whether this is my misuse of coroutines or a real issue



#213875 Peripheral call dropping events

Posted by p3p on 14 April 2015 - 12:33 AM in Ask a Pro

Ah that's disappointing not sure how to work around events randomly dropping



#213869 Peripheral call dropping events

Posted by p3p on 13 April 2015 - 11:42 PM in Ask a Pro

I'm writing a basic device manager that loads a driver for any peripheral that is attached or gets attached to a computer, this part works well, the issue I'm having is that events seem to be dropped during the peripheral call method, specifically I'm using a timer event to mediate my kernel execution and it disappears, I'm curious if this is by design, (like sleep ect) or if I'm being stupid.