You are on page 1of 9

1/26/2011

MATLAB GUI Communication
Day 1 of 2

PC to micro Communication
• Playing with PC side

1

2 .1/26/2011 Serial Port on PC • If you have a serial port use ‘COM1’ • If you do NOT have a serial port – Need a USB to Serial converter – Needs a driver. Good to know how to find it though. Google search for: • prolific usb serial driver download – Use Device manager for find COM# Finding the COM port • • Search for “device manager” in the Start area Device Manager – Expand Ports – Find USB to Serial port USB-to-Serial Requires hardware to see it pop up.

1/26/2011 UART over USB • Moving off the PICDEM board • Also needs a driver • Google search for: ftdi virtual com port driver download MATLAB Serial Objects pic = serial(‘COM1’.10) • Communication Settings – – – Port: BaudRate: Terminator: Status: COM1 19200 10 closed • – Communication State 3 . 19200.'Terminator'. ‘BaudRate’.

‘Hello World!’).'Terminator'.… 19200.10) fopen(pic) fscanf(pic).1/26/2011 Writing data pic = serial(‘COM1’. ‘BaudRate’. ‘BaudRate’.10) fopen(pic) fprintf(pic. fclose(pic) 4 .'Terminator'. fclose(pic) Reading data pic = serial(‘COM1’.… 19200.

Event driven receive! >> pic = openSerial(3) >> fprintf(pic. 'BaudRate'. 'Terminator'..'terminator'. 19200.. 'BytesAvailableFcn'.1/26/2011 Fancy serial object open function Download “openSerial..@serial_PICDEM_BytesAvailableFcn).1.0......m”. function serial_PICDEM_BytesAvailableFcn(serialObj... 'BytesAvailableFcnMode'... 'TimeOut'. eventData) %serial_PICDEM_BytesAvailableFcn bytes from serial object % This is the callback function after a 'terminator' is received % Code for callback function – Display function and processing end 5 .10. ‘to PICDEM') (then if the PIC sends data this will automatically print) On 10/8/2009 at 10:32pm (59 secs) received 12 char(s) = From PICDEM >> Event driven receive serialObj = serial(portStr.

1/26/2011 MATLAB GUIDE Graphical User Interface Development Environment Panels • Group objects • Tag – uipanel_nameForPanel – Handy to disable/enable whole panel • Name – Title on Panel 6 .

uipanel_ADC handles.connected handles.uipanel_buzzer handles.uipanel_connect handles.pushbutton_stopBuzzer handles.pushbutton_startBuzzer handles.text_RA0value handles. handles. handles.edit_comPort handles.1/26/2011 Pushbuttons • Tag – pushbutton_nameForButton – pushbutton_goLeft • String – Label on button • BackgroundColor.user.text2. FontSize.edit_sendMessage handles.pushbutton_getRA0 handles.pushbutton_sendMessage handles.text1. etc.figure1 7 .text_receivedMessages handles.pic handles.user.pushbutton_disconnect handles.pushbutton_connect handles. Position • Callback function Handles structure using tags handles.uipanel_allMessages handles.

'String') – Getting value as a number • str2double(get(handles.tagName.'String')) • Callback – Often callback function is not used – Within callback can use hObject instead of handles struct 8 .1/26/2011 Callbacks • Functions that get called when an event happens – Much like an interrupt with a PIC – Event driving programming! – hObject is the object that was selected • We’ll use callbacks for – Pushbuttons – Radio Buttons Edit Text Objects • Tag – edit_nameForEditBox – edit_comPort • String – Getting string currently in the edit box • get(handles.tagName.

text_RA0value.'String'.'String').tagName.'String'. Static Text • Tag – text_nameForStaticText – text_RA0value – Sometimes renaming tag is not necessary • String – Setting string in the static text • set(handles.newStringValue).500).edit_sendMessage.'String'. – Example • set(handles.500).1/26/2011 handles struct • A struct variable with a reference to every object in your GUI! • Set functions – set(handles.text_RA0value. 9 . • Get functions – get(handles.