<< Chapter < Page Chapter >> Page >

Receiving data

To read data from the DSP, a read channel must be set up. This is done using the invoke open command with an 'R' parameter. invoke(h,'Open','ochan','R'); Reading data from the DSP board is a little more complicated. It seems that the DSP board buffers all the data. To get the latest piece of data, you must first 'Seek' to the current message. [status,nummsgs] = invoke(h,'GetNumMsgs');status = invoke(h,'Seek',nummsgs); Once at the correct message, the actual reading can be done. [status, values] = invoke(h,'ReadI2'); As with writing, the port should be closed after reading.

Using matlab gui features

MATLAB has some nice Graphical User Interface (GUI) features which can be used to control the flow of data to and from the RTDX port. The basic implementation consists of a blank window (figure) which can have differentinterface elements placed on it. These elements can be sliders, buttons, text boxes, etc...

When an element is accessed (for instance, a slider is moved, or a button is pushed), MATLAB will execute a "callback routine" which is a MATLAB function defined by the user. Desgining these interfacesis simple.

Creating a user interface with sliders

1 % rtdx_sliders - initializes RTDX port and sets up three sliders 23 h = actxserver('RTDX'); 45 % open a blank figure for the slider 6 Fig = figure(1);7 % open sliders 8 % first slider9 sld1 = uicontrol(Fig,'units','normal','pos',[.2,.7,.5,.05],...10 'style','slider','value',4,'max',254,'min',0,'callback','rtdx_wrt_sliders'); 1112 % second slider 13 sld2 = uicontrol(Fig,'units','normal','pos',[.2,.5,.5,.05],... 14 'style','slider','value',4,'max',254,'min',0,'callback','rtdx_wrt_sliders');15 16 % third slider17 sld3 = uicontrol(Fig,'units','normal','pos',[.2,.3,.5,.05],...18 'style','slider','value',4,'max',254,'min',0,'callback','rtdx_wrt_sliders');
Got questions? Get instant answers now!

Lines 9 through the end create the three sliders for the user interface. Several parameters are used to specify the behavior of each slider. The first parameter,Fig, tells the slider to create itself in the window we created in Line 6. The rest of the parameters are property/value pairs:

  • units : Normal tells Matlab to use positioning relative to the window boundaries.
  • pos : Tells Matlab where to place the control.
  • style : Tells Matlab what type of control to place. slider creates a slider control.
  • value : Tells Matlab the default value for the control.
  • max : Tells Matlab the maximum value for the control.
  • min : Tells Matlab the maximum value for the control.
  • callback : Tells Matlab what script to call when the control is manipulated. rtdx_wrt_sliders is a Matlab file that writes the values of the controls to the RTDX port.
Every time a slider is moved, the rtdx_wrt_sliders.m file is called:

1 % rtdx_wrt_sliders : writes values of sliders out to rtdx 23 % open rtdx port for data transfer 4 status = invoke(h,'Open','ichan','W');5 6 % send valuefrom sld1 7 v1 = round(get(sld1,'value'));8 status = invoke(h,'Write',int16(v1)); 910 % send value from sld2 11 v2 = round(get(sld2,'value'));12 status = invoke(h,'Write',int16(v2)); 1314 % send value from sld3 15 v3 = round(get(sld3,'value'));16 status = invoke(h,'Write',int16(v3)); 1718 % send reset pulse 19 status = invoke(h,'Write',int16(2989));20 21 % close rtdx port22 status = invoke(h,'Close');
Got questions? Get instant answers now!

Line 7 retrieves the value from the slider using the get function to retrieve the value property. The value is then rounded off to create an integer, and the integeris sent as an 16-bit quantity to the DSP in Line 8. The other two sliders are sent in the same way. Line 19 sends 2989 to the DSP, which can be used toindicate that the three previously-transmitted values represent a complete set of data points. ( You can use whatever value you want. ) This can be used to prevent the DSP and Matlab from losing synchronization if a transmittedcharacter is not received by the DSP and provides some error detection.

Line 22 closes the RTDX port. Make sure you close the port after sending a data block to the DSP.

Advanced features

The slider example shows some basic features of the gui tools. The handle for the RTDX server is generated into the workspace so that it can be used for writing. But other elements, such as text boxescannot be dealt with as easily. The Parameters from these can be accessed through their returned handles. Some examples:

%GUI.m %****Sample GUI, Text and a Button***%open a blank figure Fig = figure(1);set(Fig,'Name','Test GUI'); %Space to enter texted2 = uicontrol(Fig,'backgroundcolor','white','units','Normalized','pos',[.1,.6,.4,.05],...'string','Default Text','style','edit'); %Buttonbut1 = uicontrol(Fig,'foregroundcolor','blue','units','Normalized','pos',[.1,.4,.5,.1],...'string','Press Me!','style','pushbutton','callback','SampleGUI');

A Text box is created with default text in it that says: "Defaul Text". A button is also created, which when pressed, will execute the callback function SampleGUI.m

%SampleGUI.m %Get TexttestText = get(ed2,'string')

Now testText holds whatever string was entered into the text box. The function get() is used to retrieve the data from the 'string; parameter in the ed2 handle. MATLAB help uicontrol gives the full list of options for interface elements.

Got questions? Get instant answers now!

Questions & Answers

Discuss the differences between taste and flavor, including how other sensory inputs contribute to our  perception of flavor.
John Reply
taste refers to your understanding of the flavor . while flavor one The other hand is refers to sort of just a blend things.
Faith
While taste primarily relies on our taste buds, flavor involves a complex interplay between taste and aroma
Kamara
which drugs can we use for ulcers
Ummi Reply
omeprazole
Kamara
what
Renee
what is this
Renee
is a drug
Kamara
of anti-ulcer
Kamara
Omeprazole Cimetidine / Tagament For the complicated once ulcer - kit
Patrick
what is the function of lymphatic system
Nency Reply
Not really sure
Eli
to drain extracellular fluid all over the body.
asegid
The lymphatic system plays several crucial roles in the human body, functioning as a key component of the immune system and contributing to the maintenance of fluid balance. Its main functions include: 1. Immune Response: The lymphatic system produces and transports lymphocytes, which are a type of
asegid
to transport fluids fats proteins and lymphocytes to the blood stream as lymph
Adama
what is anatomy
Oyindarmola Reply
Anatomy is the identification and description of the structures of living things
Kamara
what's the difference between anatomy and physiology
Oyerinde Reply
Anatomy is the study of the structure of the body, while physiology is the study of the function of the body. Anatomy looks at the body's organs and systems, while physiology looks at how those organs and systems work together to keep the body functioning.
AI-Robot
what is enzymes all about?
Mohammed Reply
Enzymes are proteins that help speed up chemical reactions in our bodies. Enzymes are essential for digestion, liver function and much more. Too much or too little of a certain enzyme can cause health problems
Kamara
yes
Prince
how does the stomach protect itself from the damaging effects of HCl
Wulku Reply
little girl okay how does the stomach protect itself from the damaging effect of HCL
Wulku
it is because of the enzyme that the stomach produce that help the stomach from the damaging effect of HCL
Kamara
function of digestive system
Ali Reply
function of digestive
Ali
the diagram of the lungs
Adaeze Reply
what is the normal body temperature
Diya Reply
37 degrees selcius
Xolo
37°c
Stephanie
please why 37 degree selcius normal temperature
Mark
36.5
Simon
37°c
Iyogho
the normal temperature is 37°c or 98.6 °Fahrenheit is important for maintaining the homeostasis in the body the body regular this temperature through the process called thermoregulation which involves brain skin muscle and other organ working together to maintain stable internal temperature
Stephanie
37A c
Wulku
what is anaemia
Diya Reply
anaemia is the decrease in RBC count hemoglobin count and PVC count
Eniola
what is the pH of the vagina
Diya Reply
how does Lysin attack pathogens
Diya
acid
Mary
I information on anatomy position and digestive system and there enzyme
Elisha Reply
anatomy of the female external genitalia
Muhammad Reply
Organ Systems Of The Human Body (Continued) Organ Systems Of The Human Body (Continued)
Theophilus Reply
what's lochia albra
Kizito
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Digital signal processing laboratory (ece 420 55x). OpenStax CNX. Jan 18, 2010 Download for free at http://cnx.org/content/col10397/1.10
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Digital signal processing laboratory (ece 420 55x)' conversation and receive update notifications?

Ask