COM_CloseNXT
Closes and deletes a specific NXT handle, or clears all existing handles
Contents
Syntax
COM_CloseNXT(handle)
COM_CloseNXT('all')
COM_CloseNXT('all', inifilename)
Description
After using NXT handles, a user should free the device (and the memory occupied by the handle) by calling this method. After the clean up invoked by this call, an NXT brick can be accessed and used again (by COM_OpenNXT or COM_OpenNXTEx.
COM_CloseNXT(handle) will close and erase the specified device. handle has to be a valid handle struct created by either COM_OpenNXT or COM_OpenNXTEx.
COM_CloseNXT('all') will close and erase all existing NXT devices from memory (as long as the toolbox could keep track of them). All USB handles will be destroyed, all open serial ports (for Bluetooth connections) will be closed. This can be useful at the beginning of a program to create a "fresh start" and a well-defined starting environment. Please note that a clear all command can cause this function to fail (in such a way, that not all open USB devices can be closed, since all information about them has be cleare from MATLAB's memory). If this happens, an NXT device might appear to be busy and cannot be used. Usually rebooting the NXT helps, if not try to restart MATLAB as well. So be careful with using clear all before |COM_CloseNXT('all').
COM_CloseNXT('all', inifilename) will do the same as above, but instead of closing all open serial ports, only the COM-Port specified in inifilename will be used (a valid Bluetooth configuration file can be created by the function COM_MakeBTConfigFile). This syntax helps to avoid interference with other serial ports that might be used by other (MATLAB) programs at the same time. Note that still all open USB devices will be closed.
Limitations
If you call COM_CloseNXT('all') after a clear all command has been issued, the function will not be able to close all remaining open USB handles, since they have been cleared out of memory. This is a problem on Linux systems. You will not be able to use the NXT device without rebooting it. Solution: Either use only clear in your programs, or you use the COM_CloseNXT('all') statement before clear all. The best way however is to track your handles carefully and close them manually before exiting whenever possible!
Example
handle = COM_OpenNXT('bluetooth.ini', check');
COM_SetDefaultNXT(handle);
NXT_PlayTone(440,10);
COM_CloseNXT(handle);
See also
COM_OpenNXT, COM_OpenNXTEx, COM_MakeBTConfigFile, COM_SetDefaultNXT,
Signature
- Author: Linus Atorf (see AUTHORS)
- Date: 2009/08/31
- Copyright: 2007-2010, RWTH Aachen University