05-14-2023, 05:12 AM
Is there a way to force controller _DEVICES to be cleared and re-detected?
For instance, when _DEVICES is first used in a running program the detected number of controllers will be returned. If one or more of the detected controllers is then disconnected the _DEVICE$ for the disconnected controllers will add "[DISCONNECTED]" to the string returned but still occupy a place in _DEVICES. If a user were to start plugging in random controllers after program startup the _DEVICES value will just keep growing with each new unique controller connected. The program listed below will show this in action. I would like to clear the _DEVICES list when a controller is listed as "[DISCONNECTED]" so _DEVICES can recount the actual number of controllers still plugged in if this is possible while a program is running. Any thoughts?
For instance, when _DEVICES is first used in a running program the detected number of controllers will be returned. If one or more of the detected controllers is then disconnected the _DEVICE$ for the disconnected controllers will add "[DISCONNECTED]" to the string returned but still occupy a place in _DEVICES. If a user were to start plugging in random controllers after program startup the _DEVICES value will just keep growing with each new unique controller connected. The program listed below will show this in action. I would like to clear the _DEVICES list when a controller is listed as "[DISCONNECTED]" so _DEVICES can recount the actual number of controllers still plugged in if this is possible while a program is running. Any thoughts?
Code: (Select All)
DIM Devices AS INTEGER
DIM Fcount AS INTEGER
DIM d AS INTEGER
DIM DeviceName AS STRING
Devices = _DEVICES
Fcount = 0
DO
CLS
_LIMIT 30
Fcount = Fcount + 1
IF Fcount = 30 THEN ' check for new devices once per second
Fcount = 1
IF _DEVICES <> Devices THEN Devices = _DEVICES ' if number of devices changes get new count
END IF
PRINT
FOR d = 1 TO Devices ' print found devices
COLOR 14, 1
DeviceName = _DEVICE$(d)
IF INSTR(DeviceName, "[DISCONNECTED]") THEN COLOR 7, 0 ' change color if disconnected
PRINT " Found: "; _DEVICE$(d)
COLOR 7, 0
NEXT d
_DISPLAY
LOOP UNTIL _KEYDOWN(27) ' press ESC to exit