Changeset 130
- Timestamp:
- 07/10/08 03:13:18 (5 years ago)
- Location:
- branches/atorf/RWTHMindstormsNXT
- Files:
-
- 5 modified
-
COM_CloseNXT.m (modified) (5 diffs)
-
COM_CollectPacket.m (modified) (1 diff)
-
demos (modified) (1 prop)
-
demos/GUI_WatchAnalogSensor.fig (modified) (previous)
-
demos/GUI_WatchAnalogSensor.m (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/atorf/RWTHMindstormsNXT/COM_CloseNXT.m
r128 r130 87 87 end%try 88 88 89 textOut(sprintf('Closing handle (USB) with MAC = %s (handle was %.1f minutes old)\n', h.NXTMAC, etime(clock, h.CreationTime) / 60));90 89 91 90 if h.ConnectionTypeValue == 1 % USB 91 textOut(sprintf('Closing handle (USB) with MAC = %s (handle was %.1f minutes old)\n', h.NXTMAC, etime(clock, h.CreationTime) / 60)); 92 92 if h.OSValue == 1 % win 93 93 USB_CloseHandle_Windows(h); … … 96 96 end%if 97 97 else % BT 98 textOut(sprintf('Closing handle (Bluetooth) on port %s (handle was %.1f minutes old)... ', h.ComPort, etime(clock, h.CreationTime) / 60)); 98 99 BT_CloseHandle(h); 99 100 end%if … … 171 172 %% Close given bluetooth connection 172 173 173 textOut(sprintf('Closing Bluetooth connection on port %s ... ', h.ComPort));174 %textOut(sprintf('Closing Bluetooth connection on port %s ... ', h.ComPort)); 174 175 175 176 … … 232 233 %% Close all serial ports 233 234 if nargin < 1 234 textOut(sprintf('Closing all openserial ports... '));235 textOut(sprintf('Closing all serial ports... ')); 235 236 if ispc % WINDOWS VERSION ------------- 236 237 try … … 271 272 ComPort = readFromIniFile(inisection, 'SerialPort', inifilename); 272 273 273 textOut(sprintf('Closing openserial port %s... ', ComPort));274 textOut(sprintf('Closing serial port %s... ', ComPort)); 274 275 275 276 if ispc % WINDOWS VERSION ------------- -
branches/atorf/RWTHMindstormsNXT/COM_CollectPacket.m
r128 r130 116 116 textOut(sprintf('Packet contains error message %d: "%s"\n', statusbyte, errmsg)); 117 117 DebugMode(oldstate); 118 % increase handle's error-count by 1 119 handle.TransmissionErrors(1); 118 120 end%if 119 121 end%if -
branches/atorf/RWTHMindstormsNXT/demos
-
Property
svn:ignore set
to
*.asv
-
Property
svn:ignore set
to
-
branches/atorf/RWTHMindstormsNXT/demos/GUI_WatchAnalogSensor.m
r3 r130 23 23 % Edit the above text to modify the response to help GUI_WatchAnalogSensor 24 24 25 % Last Modified by GUIDE v2.5 26-Jul-2007 14:15:5525 % Last Modified by GUIDE v2.5 10-Jul-2008 03:03:01 26 26 27 27 % Begin initialization code - DO NOT EDIT … … 108 108 global DisableScreenOut; 109 109 global StopSensorWatchLoop; 110 global USmode; 110 111 StopSensorWatchLoop = false; 111 112 112 113 113 port = str2num(get(handles.txtPort, 'String')); 114 %tmp = get(handles.lstPort, 'String'); 115 port = get(handles.lstPort, 'Value') - 1; % - 1 because 1st sensor is 0 114 116 tmp = get(handles.lstSensorType, 'String'); 115 117 sensortype = tmp{get(handles.lstSensorType, 'Value')}; 116 %sensortype 117 118 h = BT_GetDefaultHandle; 118 119 PlotData = get(handles.chkPlotData, 'Value'); 120 121 USmode = false; 122 if strcmpi(sensortype, 'Ultrasonic') 123 USmode = true; 124 end%if 125 126 h = COM_GetDefaultNXT; 119 127 120 128 OldScreenOutMode = DisableScreenOut; … … 124 132 125 133 try 126 if NXT_SetInputMode(port, sensortype, 'PERIODCOUNTERMODE', 'reply', h) ~= 0 127 errordlg('Invalid sensor type, or the specified sensor is not connected to the specified port') 128 return 134 if USmode 135 CloseSensor(port); 136 OpenUltrasonic(port); 137 else 138 if NXT_SetInputMode(port, sensortype, 'PERIODCOUNTERMODE', 'reply', h) ~= 0 139 errordlg('Invalid sensor type, or the specified sensor is not connected to the specified port') 140 return 141 end%if 129 142 end%if 130 131 143 catch 132 144 errordlg('Invalid sensor type, or the specified sensor is not connected to the specified port') … … 135 147 136 148 149 MaxYVal = 1024; 150 if USmode; MaxYVal = 256; end%if 137 151 138 152 axes(handles.axsSensorData); 139 axis([0 DisplayPeriod 0 1024]);153 axis([0 DisplayPeriod 0 MaxYVal]); 140 154 hold on 141 155 cla 142 plot([0 DisplayPeriod], [1024 * 0.45 1024 * 0.45], 'k--') 143 plot([0 DisplayPeriod], [1024 * 0.55 1024 * 0.55], 'k--') 144 cmap = colormap(jet(1024)); 156 157 if ~USmode 158 plot([0 DisplayPeriod], [MaxYVal * 0.45 MaxYVal * 0.45], 'k--') 159 plot([0 DisplayPeriod], [MaxYVal * 0.55 MaxYVal * 0.55], 'k--') 160 else 161 plot([0 DisplayPeriod], [150 150], 'k--') 162 end%if 163 cmap = colormap(jet(MaxYVal)); 145 164 146 165 147 166 tictic(1); 148 167 tictic(3); 149 % we've got this handy bytecounter only when using a serial port handle, 150 % i.e. under windows... 151 if ispc 152 StartBytesReceived = h.ValuesReceived; 153 else 154 StartBytesReceived = 0; 155 end%if 168 169 StartBytesReceived = h.BytesReceived(); 170 StartErrorCount = h.TransmissionErrors(); 171 156 172 ReplyCount = 0; 157 173 MaxLatency = 0; 158 174 LatencySum = 0; 175 176 if h.ConnectionTypeValue == 1 177 LineWidth = 2; % USB 178 else 179 LineWidth = 3; 180 end%if 181 182 159 183 while(~StopSensorWatchLoop) 160 184 161 185 if toctoc(1) >= 1 162 186 163 if ispc % WINDOWS version for serial port handle only...164 set(handles.txtReceivedBytes, 'String', h.ValuesReceived - StartBytesReceived);165 StartBytesReceived = h.ValuesReceived;166 end%if167 187 PlotData = get(handles.chkPlotData, 'Value'); 188 189 set(handles.txtReceivedBytes, 'String', h.BytesReceived() - StartBytesReceived); 190 StartBytesReceived = h.BytesReceived(); 191 168 192 set(handles.txtAvgLatency, 'String', [num2str(ceil((LatencySum / ReplyCount) * 1000)) ' ms'] ); 169 193 LatencySum = 0; … … 175 199 ReplyCount = 0; 176 200 201 set(handles.txtTransmissionErrors, 'String', h.TransmissionErrors() - StartErrorCount); 202 StartErrorCount = h.TransmissionErrors(); 203 204 % update current values so there's at least some kind of info 205 if ~USmode 206 set(handles.txtPeriodCount, 'String', out.ScaledVal); 207 set(handles.txtCurVal, 'String', out.NormalizedADVal); 208 else 209 set(handles.txtCurVal, 'String', out); 210 end%if 211 212 213 drawnow % need this for MATLAB to not freeze if drawing is disabled 214 177 215 tictic(1); 178 216 end%if … … 181 219 tictic(2); 182 220 183 out = NXT_GetInputValues(port, h); 221 if ~USmode 222 out = NXT_GetInputValues(port, h); 223 else 224 out = GetUltrasonic(port); 225 if out < 1 226 % work around for color map to not crash 227 out = 1; 228 end%if 229 end%if 184 230 ReplyCount = ReplyCount + 1; 185 231 … … 187 233 LatencySum = LatencySum + tmp; 188 234 if tmp > MaxLatency, MaxLatency = tmp; end 235 189 236 190 191 set(handles.txtPeriodCount, 'String', out.ScaledVal);192 set(handles.txtCurVal, 'String', out.NormalizedADVal);193 194 plot([toctoc(3) toctoc(3)], [0 out.NormalizedADVal], 'LineWidth', 3, 'Color', cmap(out.NormalizedADVal + 1, :))195 196 197 237 if toctoc(3) > DisplayPeriod 198 238 tictic(3); 199 239 cla 200 plot([0 DisplayPeriod], [1024 * 0.45 1024 * 0.45], 'k--') 201 plot([0 DisplayPeriod], [1024 * 0.55 1024 * 0.55], 'k--') 240 if ~USmode 241 plot([0 DisplayPeriod], [MaxYVal * 0.45 MaxYVal * 0.45], 'k--') 242 plot([0 DisplayPeriod], [MaxYVal * 0.55 MaxYVal * 0.55], 'k--') 243 else 244 plot([0 DisplayPeriod], [150 150], 'k--') 245 end%if 202 246 end%if 203 204 205 drawnow 247 248 249 if PlotData 250 if ~USmode 251 set(handles.txtPeriodCount, 'String', out.ScaledVal); 252 set(handles.txtCurVal, 'String', out.NormalizedADVal); 253 plot([toctoc(3) toctoc(3)], [0 out.NormalizedADVal], 'LineWidth', LineWidth, 'Color', cmap(out.NormalizedADVal + 1, :)) 254 else 255 set(handles.txtCurVal, 'String', out); 256 plot([toctoc(3) toctoc(3)], [0 out], 'LineWidth', LineWidth, 'Color', cmap(out + 1, :)) 257 end%if 258 259 drawnow 260 end%if 206 261 207 262 208 263 end%while 264 265 try 266 CloseSensor(SENSOR_1); 267 CloseSensor(SENSOR_2); 268 CloseSensor(SENSOR_3); 269 CloseSensor(SENSOR_4); 270 catch 271 % nothing 272 end%try 273 209 274 DisableScreenOut = OldScreenOutMode; 210 275 … … 243 308 244 309 245 function edit3_Callback(hObject, eventdata, handles)246 % hObject handle to edit3 (see GCBO)247 % eventdata reserved - to be defined in a future version of MATLAB248 % handles structure with handles and user data (see GUIDATA)249 250 % Hints: get(hObject,'String') returns contents of edit3 as text251 % str2double(get(hObject,'String')) returns contents of edit3 as a double252 253 310 254 311 % --- Executes during object creation, after setting all properties. … … 266 323 267 324 268 function edit4_Callback(hObject, eventdata, handles)269 % hObject handle to edit4 (see GCBO)270 % eventdata reserved - to be defined in a future version of MATLAB271 % handles structure with handles and user data (see GUIDATA)272 273 % Hints: get(hObject,'String') returns contents of edit4 as text274 % str2double(get(hObject,'String')) returns contents of edit4 as a double275 276 277 325 % --- Executes during object creation, after setting all properties. 278 326 function edit4_CreateFcn(hObject, eventdata, handles) … … 358 406 359 407 360 function edit8_Callback(hObject, eventdata, handles)361 % hObject handle to edit8 (see GCBO)362 % eventdata reserved - to be defined in a future version of MATLAB363 % handles structure with handles and user data (see GUIDATA)364 365 % Hints: get(hObject,'String') returns contents of edit8 as text366 % str2double(get(hObject,'String')) returns contents of edit8 as a double367 368 369 % --- Executes during object creation, after setting all properties.370 function edit8_CreateFcn(hObject, eventdata, handles)371 % hObject handle to edit8 (see GCBO)372 % eventdata reserved - to be defined in a future version of MATLAB373 % handles empty - handles not created until after all CreateFcns called374 375 % Hint: edit controls usually have a white background on Windows.376 % See ISPC and COMPUTER.377 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))378 set(hObject,'BackgroundColor','white');379 end380 381 382 % --- Executes on button press in checkbox1.383 function checkbox1_Callback(hObject, eventdata, handles)384 % hObject handle to checkbox1 (see GCBO)385 % eventdata reserved - to be defined in a future version of MATLAB386 % handles structure with handles and user data (see GUIDATA)387 388 % Hint: get(hObject,'Value') returns toggle state of checkbox1389 390 391 % --- Executes on button press in checkbox2.392 function checkbox2_Callback(hObject, eventdata, handles)393 % hObject handle to checkbox2 (see GCBO)394 % eventdata reserved - to be defined in a future version of MATLAB395 % handles structure with handles and user data (see GUIDATA)396 397 % Hint: get(hObject,'Value') returns toggle state of checkbox2398 399 400 % --- Executes on button press in checkbox3.401 function checkbox3_Callback(hObject, eventdata, handles)402 % hObject handle to checkbox3 (see GCBO)403 % eventdata reserved - to be defined in a future version of MATLAB404 % handles structure with handles and user data (see GUIDATA)405 406 % Hint: get(hObject,'Value') returns toggle state of checkbox3407 408 409 410 function edit9_Callback(hObject, eventdata, handles)411 % hObject handle to edit9 (see GCBO)412 % eventdata reserved - to be defined in a future version of MATLAB413 % handles structure with handles and user data (see GUIDATA)414 415 % Hints: get(hObject,'String') returns contents of edit9 as text416 % str2double(get(hObject,'String')) returns contents of edit9 as a double417 408 418 409 … … 554 545 555 546 % Hint: get(hObject,'Value') returns toggle state of cmdResetCount 556 557 h = BT_GetDefaultHandle; 558 port = str2num(get(handles.txtPort, 'String')); 559 NXT_ResetInputScaledValue(port, h) 547 global USmode 548 549 if ~USmode 550 %h = COM_GetDefaultNXT; 551 port = get(handles.lstPort, 'Value') - 1; 552 NXT_ResetInputScaledValue(port) 553 end%if 560 554 561 555 … … 572 566 % if default handle set, ok, if not, create one... 573 567 try 574 h = BT_GetDefaultHandle();568 h = COM_GetDefaultNXT(); 575 569 catch 576 BT_CloseAllHandles('bluetooth.ini');577 BT_SetDefaultHandle(BT_OpenHandle('bluetooth.ini', 'check'))570 COM_CloseNXT('all', 'bluetooth.ini'); 571 COM_SetDefaultNXT(COM_OpenNXT('bluetooth.ini', 'check')); 578 572 end%try 579 573 … … 602 596 603 597 598 599 600 601 function txtTransmissionErrors_Callback(hObject, eventdata, handles) 602 % hObject handle to txtTransmissionErrors (see GCBO) 603 % eventdata reserved - to be defined in a future version of MATLAB 604 % handles structure with handles and user data (see GUIDATA) 605 606 % Hints: get(hObject,'String') returns contents of txtTransmissionErrors as text 607 % str2double(get(hObject,'String')) returns contents of txtTransmissionErrors as a double 608 609 610 % --- Executes during object creation, after setting all properties. 611 function txtTransmissionErrors_CreateFcn(hObject, eventdata, handles) 612 % hObject handle to txtTransmissionErrors (see GCBO) 613 % eventdata reserved - to be defined in a future version of MATLAB 614 % handles empty - handles not created until after all CreateFcns called 615 616 % Hint: edit controls usually have a white background on Windows. 617 % See ISPC and COMPUTER. 618 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 619 set(hObject,'BackgroundColor','white'); 620 end 621 622 623 624 625 % --- Executes on selection change in lstPort. 626 function lstPort_Callback(hObject, eventdata, handles) 627 % hObject handle to lstPort (see GCBO) 628 % eventdata reserved - to be defined in a future version of MATLAB 629 % handles structure with handles and user data (see GUIDATA) 630 631 % Hints: contents = get(hObject,'String') returns lstPort contents as cell array 632 % contents{get(hObject,'Value')} returns selected item from lstPort 633 634 635 % --- Executes during object creation, after setting all properties. 636 function lstPort_CreateFcn(hObject, eventdata, handles) 637 % hObject handle to lstPort (see GCBO) 638 % eventdata reserved - to be defined in a future version of MATLAB 639 % handles empty - handles not created until after all CreateFcns called 640 641 % Hint: popupmenu controls usually have a white background on Windows. 642 % See ISPC and COMPUTER. 643 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 644 set(hObject,'BackgroundColor','white'); 645 end 646 647 648 649 650 % --- Executes when user attempts to close figure1. 651 function figure1_CloseRequestFcn(hObject, eventdata, handles) 652 % hObject handle to figure1 (see GCBO) 653 % eventdata reserved - to be defined in a future version of MATLAB 654 % handles structure with handles and user data (see GUIDATA) 655 656 % Hint: delete(hObject) closes the figure 657 delete(hObject); 658 659 660 661 662 % --- Executes on button press in chkPlotData. 663 function chkPlotData_Callback(hObject, eventdata, handles) 664 % hObject handle to chkPlotData (see GCBO) 665 % eventdata reserved - to be defined in a future version of MATLAB 666 % handles structure with handles and user data (see GUIDATA) 667 668 % Hint: get(hObject,'Value') returns toggle state of chkPlotData 669 670
