Changeset 981

Show
Ignore:
Timestamp:
09/30/11 12:21:35 (20 months ago)
Author:
staas
Message:

*COM_MakeBTConfigFile.m : added the fields NXT-Name, NXT-Mac and Channel to the Bluetooth ini-File to make it compatible to the new Matlab Bluetooth interface
*COM_OpenNXTEx.m : some changes to better support the new Matlab Bluetooth interface. You can open NXT via NXT-Name or NXT-MAC given in the ini-File.
*Troubleshooting.m : added Section for Windows 64Bit USB problems

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/doc/m2html/Troubleshooting.m

    r808 r981  
    4646% </html> 
    4747 
     48%% Windows 64Bit 
     49% 
     50 
     51%% 
     52% 
     53% *Problems with USB-Connection*  
     54% 
     55% If you have problems connecting your NXT make sure you installed 
     56% "libusb_win32" correctly. You have to run "inf-wizard.exe" once for EVERY 
     57% NXT. Your NXT is installed correctly if it appears under "libusb-win32 
     58% devices" in your Windows Device Manager. 
    4859 
    4960 
  • trunk/mfiles/COM_MakeBTConfigFile.m

    r952 r981  
    2121% 
    2222% Signature 
    23 %   Author: Alexander Behrens, Linus Atorf (see AUTHORS) 
    24 %   Date: 2008/07/09 
     23%   Author: Alexander Behrens, Linus Atorf, Martin Staas (see AUTHORS) 
     24%   Date: 2011/09/30 
    2525%   Copyright: 2007-2011, RWTH Aachen University 
    2626% 
     
    5757        dlg_title = 'Configuration File Settings'; 
    5858        if ispc 
    59             prompt    = {'Filename:', 'SerialPort:', 'BaudRate:', 'DataBits:', 'SendPause:', 'ReceivePause:', 'Timeout:'}; 
     59            archstr = computer('arch'); 
     60            Is64Bit = regexp(archstr,'\w*64','match'); %are we running on 64Bit? 
     61            if isempty(Is64Bit) 
     62                prompt    = {'Filename:', 'SerialPort:', 'BaudRate:', 'DataBits:', 'SendPause:', 'ReceivePause:', 'Timeout:'}; 
     63            else 
     64                prompt    = {'Filename:', 'SerialPort:', 'BaudRate:', 'DataBits:', 'SendPause:', 'ReceivePause:', 'Timeout:','NXT-Name:','NXT-MAC:','Channel:'}; 
     65            end 
    6066        else 
    6167            prompt    = {'Filename:', 'SerialPort:', 'SendPause:', 'ReceivePause:', 'Timeout:'}; 
     
    6672         
    6773        if ispc 
    68             default_parameters = {'bluetooth.ini','COM3','9600', '8', '5', '25', '2'}; 
     74            if isempty(Is64Bit) 
     75                default_parameters = {'bluetooth.ini','COM3','9600', '8', '5', '25', '2'}; 
     76            else 
     77                default_parameters = {'bluetooth.ini','COM3','9600', '8', '5', '25', '2','NXT','','1'}; 
     78            end 
    6979        else 
    7080            default_parameters = {'bluetooth.ini', '/dev/rfcomm0', '5', '25', '2'}; 
     
    7686            filename     = my_parameters{1}; 
    7787            if ispc 
    78                 port         = my_parameters{2}; 
    79                 baudrate     = str2double(my_parameters{3}); 
    80                 databits     = str2double(my_parameters{4}); 
    81                 sendpause    = str2double(my_parameters{5}); 
    82                 receivepause = str2double(my_parameters{6}); 
    83                 timeout      = str2double(my_parameters{7}); 
     88                if isempty(Is64Bit) 
     89                    port         = my_parameters{2}; 
     90                    baudrate     = str2double(my_parameters{3}); 
     91                    databits     = str2double(my_parameters{4}); 
     92                    sendpause    = str2double(my_parameters{5}); 
     93                    receivepause = str2double(my_parameters{6}); 
     94                    timeout      = str2double(my_parameters{7}); 
     95                else 
     96                    port         = my_parameters{2}; 
     97                    baudrate     = str2double(my_parameters{3}); 
     98                    databits     = str2double(my_parameters{4}); 
     99                    sendpause    = str2double(my_parameters{5}); 
     100                    receivepause = str2double(my_parameters{6}); 
     101                    timeout      = str2double(my_parameters{7}); 
     102                    nxtname         = my_parameters{8}; 
     103                    nxtmac          = my_parameters{9}; 
     104                    channel      = str2double(my_parameters{10}); 
     105                end 
    84106            else 
    85107                port         = my_parameters{2}; 
     
    119141            fwrite(h_file, sprintf('Timeout=%d\r\n', timeout)); 
    120142            fwrite(h_file, sprintf('\r\n')); 
     143             
     144            if ~isempty(Is64Bit) 
     145                fwrite(h_file, sprintf('NXT-Name=%s\r\n', nxtname)); 
     146                fwrite(h_file, sprintf('NXT-MAC=%s\r\n', nxtmac)); 
     147                fwrite(h_file, sprintf('Channel=%d\r\n', channel)); 
     148                fwrite(h_file, sprintf('\r\n'));   
     149            end 
    121150 
    122151            fclose(h_file); 
  • trunk/mfiles/COM_OpenNXTEx.m

    r980 r981  
    102102% 
    103103% Signature 
    104 %   Author: Linus Atorf, Alexander Behrens (see AUTHORS) 
    105 %   Date: 2011/09/28 
     104%   Author: Linus Atorf, Alexander Behrens, Martin Staas (see AUTHORS) 
     105%   Date: 2011/09/30 
    106106%   Copyright: 2007-2011, RWTH Aachen University 
    107107% 
     
    413413        end%if 
    414414        if hIn.OSValue == 4 % 64 Bit 
    415             NXTName = readFromIniFile(inisection, 'NXTName', inifilename);             
     415            NXTName = readFromIniFile(inisection, 'NXT-Name', inifilename); 
     416            NXTMac  = readFromIniFile(inisection, 'NXT-Mac', inifilename); 
    416417            Channel = readFromIniFile(inisection, 'Channel', inifilename);             
    417418        end 
     
    459460        end%try 
    460461    elseif ispc && hIn.OSValue == 4 % 64 Bit 
    461         handle= Bluetooth(NXTName,str2num(Channel)); 
    462         fopen(handle); 
     462        if ~isempty(NXTMac) %open with MAC 
     463            btMac = strcat( 'btspp://' , NXTMac); 
     464            handle= Bluetooth(btMac,str2num(Channel));    
     465        else %open with name 
     466            handle = Bluetooth(NXTName,str2num(Channel)); 
     467        end 
     468         
     469        try 
     470            % Try to open our Bluetooth Handle. This might fail if NXTName 
     471            % or NXTMac are false or the NXT turned off. 
     472            fopen(handle); 
     473            if ~ strcmp(handle.RemoteName,NXTName); %if connection works, check if names match, just to be sure 
     474                warning('MATLAB:RWTHMindstormsNXT:Bluetooth:namesDontMatch','The Name of the NXT with MAC: "%s" is: "%s" this name does not match the one given in the Bluetooth ini-File: "%s". Using NXT with name: "%s"', NXTMac, handle.RemoteName, NXTName, handle.RemoteName); 
     475            end 
     476        catch 
     477             
     478            if ~isempty(NXTMac) && ~isempty(NXTName) %maybe we can get the right NXT by name? 
     479                try 
     480                    warning('MATLAB:RWTHMindstormsNXT:Bluetooth:couldNotOpenConnectionMac','Could not open connection to NXT with MAC: "%s". Trying to open NXT with name "%s" instead.', NXTMac, NXTName); 
     481                    handle = Bluetooth(NXTName,str2num(Channel)); 
     482                    fopen(handle); 
     483                catch 
     484                    error('MATLAB:RWTHMindstormsNXT:Bluetooth:couldNotOpenConnectionToNXT', 'Could not open bluetooth connection to NXT: %s. Please check your bluetooth ini-File', NXTName ); 
     485                end 
     486            else 
     487                error('MATLAB:RWTHMindstormsNXT:Bluetooth:couldNotOpenConnectionToNXT', 'Could not open bluetooth connection to NXT: %s. Please check your bluetooth ini-File', NXTName ); 
     488        end 
     489        end %try 
     490         
    463491         
    464492         
     
    511539 
    512540        %TODO get NXT's name & mac in here, and compare... 
     541        %this is already checked above for Windows 64-Bit.  
    513542         
    514543    end%if 
     
    779808    hOut.ConnectionTypeName     = 'USB'; 
    780809     
    781 %% Unload libusb (if already in memory) 
    782     if libisloaded('libusb') 
     810 
     811%% Unload libusb when working with Linux (if already in memory) 
     812    if libisloaded('libusb') && (hIn.OSValue == 2) 
    783813        textOut(sprintf('  - Unloading library "libusb"... ')); 
    784814        try