m14388-1.5

Embed Size (px)

Citation preview

  • 7/30/2019 m14388-1.5

    1/7

    C o n n e x i o n s m o d u l e : m 1 4 3 8 8 1

    U s i n g R T D X w i t h a M A T L A B G U I

    T h o m a s S h e n

    B a s e d o n U s i n g t h e S e r i a l P o r t w i t h a M A T L A B G U I

    b y

    J a s o n L a s k a

    M a t t h e w B e r r y

    D a n i e l S a c h s

    T h i s w o r k i s p r o d u c e d b y T h e C o n n e x i o n s P r o j e c t a n d l i c e n s e d u n d e r t h e

    C r e a t i v e C o m m o n s A t t r i b u t i o n L i c e n s e

    A b s t r a c t

    E x p l a i n s h o w t o s e n d a n d r e c e i v e d a t a w i t h t h e D S P t h r o u g h t h e U S B p o r t u s i n g R T D X . E x a m p l e

    c o d e i s s h o w n i n C a s w e l l a s M A T L A B f o r i n t e r f a c i n g o n t h e P C . S o m e e x a m p l e c o d e f o r c r e a t i n g a

    M A T L A B G U I i s a l s o s h o w n .

    1 I n t r o d u c t i o n

    T h e U S B p o r t o n t h e D S P b o x c a n a l s o b e u s e d t o t r a n s m i t d a t a b e t w e e n t h e D S P a n d t h e P C d u r i n g

    r e a l - t i m e o p e r a t i o n . T e x a s I n s t r u m e n t s c a m e u p w i t h R e a l T i m e D a t a E x c h a n g e ( R T D X ) t o a l l o w u s e r s

    r e a l - t i m e b i d i r e c t i o n a l e x c h a n g e o f d a t a b e t w e e n t h e t a r g e t a n d h o s t . T h i s a l l o w s t h e s i m u l a t i o n o f d a t a

    i n p u t a n d o u t p u t w h i c h c a n b e u s e d a s f e e d b a c k f r o m t h e D S P f o r a v a r i e t y o f a p p l i c a t i o n s . B o t h i n p u t a n d

    o u t p u t d a t a a r e b u e r e d u n t i l r e a d , a l l o w i n g t r a n s m i s s i o n o f l a r g e r a m o u n t s o f d a t a .

    2 S e t t i n g U p I n p u t / O u t p u t C h a n n e l s

    T h e R T D X w o r k s b y s e t t i n g u p i n p u t a n d o u t p u t c h a n n e l s t o t h e D S P . R T D X f u n c t i o n a l i t y i s s u p p l i e d

    t h r o u g h t h e i n c l u d e l e r t d x . h s o b e s u r e i t i s i n c l u d e d i n y o u r m a i n . c a n d a n y o t h e r l e s t h a t u s e r t d x

    f u n c t i o n s .

    D e p e n d i n g o n w h e t h e r t h e r e w i l l b e i n p u t a n d / o r o u t p u t f r o m t h e c o m p u t e r i n y o u r p r o j e c t , a d d i n p u t

    a n d o u t p u t c h a n n e l s i n t h e m a i n . c l e u s i n g t h e c o m m a n d s . T h e s e a r e d e c l a r e d l i k e g l o b a l v a r i a b l e s n e a r

    t h e t o p o f t h e c o d e a f t e r t h e i n c l u d e l e s . T h e y d o N O T g o i n t h e m a i n ( ) f u n c t i o n o r a n y o t h e r f u n c t i o n .

    R T D X _ C r e a t e I n p u t C h a n n e l ( i c h a n ) ;

    R T D X _ C r e a t e O u t p u t C h a n n e l ( o c h a n ) ;

    V e r s i o n 1 . 5 : M a r 2 6 , 2 0 0 8 3 : 5 6 p m - 0 5 0 0

    h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 6 2 / 1 . 1 /

    h t t p : / / c r e a t i v e c o m m o n s . o r g / l i c e n s e s / b y / 2 . 0 /

    h t t p : / / c n x . o r g / c o n t e n t / m 1 4 3 8 8 / 1 . 5 /

  • 7/30/2019 m14388-1.5

    2/7

    C o n n e x i o n s m o d u l e : m 1 4 3 8 8 2

    B y d e f a u l t , t h e s e c h a n n e l s a r e d i s a b l e d o n t h e D S P . Y o u m a y e n a b l e t h e m i n t h e m a i n l o o p s o t h a t t h e y w i l l

    b e e n a b l e d f o r t h e d u r a t i o n o f t h e p r o g r a m . T h i s c a n b e a c c o m p l i s h e d w i t h t h e f o l l o w i n g i n s t r u c t i o n s :

    R T D X _ e n a b l e I n p u t ( & i c h a n ) ;

    R T D X _ e n a b l e O u t p u t ( & o c h a n ) ;

    I n o t h e r C l e s t h a t u t i l i z e t h e d e c l a r e d i n p u t a n d o u t p u t c h a n n e l s , y o u w i l l n e e d t o d e c l a r e t h e i n p u t a n d

    o u t p u t c h a n n e l s a g a i n w i t h a n e x t e r n s o t h a t y o u r l e s k n o w w h a t t h e v a r i a b l e s a r e .

    e x t e r n R T D X _ i n p u t _ c h a n n e l i c h a n ;

    e x t e r n R T D X _ o u t p u t _ c h a n n e l o c h a n ;

    L a s t l y , R T D X M U S T b e m a n u a l l y e n a b l e d o n t h e D S P b o a r d s . G o t o T o o l s - >R T D X - >C o n f i g u r a t i o n

    C o n t r o l a n d s e l e c t ' E n a b l e R T D X ' i n t h e w i n d o w t h a t o p e n s . A n o t h e r h e l p f u l w i n d o w f o r d e b u g g i n g i s t h e

    ' C h a n n e l V i e w e r C o n t r o l ' a c c e s s e d t h r o u g h T o o l s - > R T D X - >C o n f i g u r a t i o n C o n t r o l . T h i s w i n d o w d i s p l a y s

    t h e n u m b e r o f c o m p l e t e d a n d o u t s t a n d i n g t r a n s f e r s b e t w e e n c o m p u t e r a n d b o a r d .

    3 U s i n g t h e D S P t o A c c e s s t h e U S B P o r t

    T h e d a t a b u e r c a n b e w r i t t e n t o i n C , b u t r e q u i r e s t h e b l o c k m e t h o d o f i n p u t / o u t p u t u s e d i n L a b 4

    1

    a n d L a b 5

    2

    . T h e s a m p l e - b y - s a m p l e m e t h o d u s e d i n L a b s 1 t h r o u g h 3 w i l l n o t w o r k w i t h R T D X . R T D X

    f u n c t i o n a l i t y i s s u p p l i e d t h r o u g h t h e i n c l u d e l e r t d x . h s o b e s u r e i t i s i n c l u d e d i n y o u r m a i n . c l e a n d a n y

    o t h e r l e s t h a t u s e r t d x f u n c t i o n s .

    3 . 1 U s i n g C t o S e n d / R e c e i v e

    T h e r e a r e s e v e r a l f u n c t i o n s f o r t r a n s m i t t i n g a n d r e c e i v i n g d a t a w i t h i n t h e C e n v i r o n m e n t :

    R T D X _ r e a d N B ( ) t a k e s t h r e e a r g u m e n t s : t h e r s t i s a p o i n t e r t o t h e i n p u t c h a n n e l , t h e s e c o n d i s a

    p o i n t e r t o t h e v a r i a b l e i n w h i c h t o s t o r e r e a d d a t a , a n d t h e t h i r d i s t h e n u m b e r o f b y t e s t o r e a d . T h i s

    i s a n o n - b l o c k i n g r e a d , m e a n i n g i f n o d a t a i s a v a i l a b l e t o b e r e a d , i t w i l l m e r e l y r e t u r n . H o w e v e r , t h e r e

    w i l l t h e n b e a n o u t s t a n d i n g r e a d a n d t h e v a r i a b l e w i l l b e u p d a t e d w h e n s o m e d a t a i s n a l l y r e a d . I t

    r e t u r n s ' R T D X _ O K ' o n s u c c e s s , ' 0 ' o n f a i l u r e ( t h e t a r g e t b u e r i s f u l l ) , a n d ' R T D X _ R E A D _ E R R O R '

    w h e n t h e c h a n n e l i s c u r r e n t l y b u s y r e a d i n g .

    R T D X _ r e a d ( ) a l s o t a k e s t h r e e i n p u t s l i k e R T D X _ r e a d N B ( ) a n d b u t o n s u c c e s s f u l r e a d , i t r e t u r n s t h e

    n u m b e r o f b y t e s o f d a t a a c t u a l l y i n t h e b u e r . T h e d i e r e n c e f r o m R T D X _ r e a d N B ( ) i s i t ' s a b l o c k i n g

    r e a d , m e a n i n g R T D X _ r e a d ( ) w o n ' t r e t u r n u n t i l s o m e t h i n g i s r e a d . I f t h e c h a n n e l i s b u s y o r n o t e n a b l e d ,

    ' R T D X _ R E A D _ E R R O R ' w i l l b e r e t u r n e d .

    R T D X _ w r i t e ( ) t a k e s t h r e e a r g u m e n t s : t h e r s t i s t h e p o i n t e r t o t h e o u t p u t c h a n n e l , t h e s e c o n d i s a

    p o i n t e r t o t h e b u e r c o n t a i n i n g t h e d a t a t o w r i t e , a n d t h e t h i r d i s t h e s i z e o f t h e b u e r i n b y t e s . I t

    r e t u r n s a n i n t e g e r , n o n - z e r o o n s u c c e s s a n d ' 0 ' o n f a i l u r e .

    R T D X _ s i z e o f I n p u t ( ) t a k e s a p o i n t e r t o a n i n p u t c h a n n e l a n d r e t u r n s t h e n u m b e r o f b y t e s o f d a t a

    a c t u a l l y r e a d f r o m t h e b u e r . I t i s u s e d i n c o n j u n c t i o n w i t h R T D X _ r e a d N B ( ) a f t e r a r e a d o p e r a t i o n i s

    c o m p l e t e d .

    R T D X _ c h a n n e l B u s y ( ) t a k e s a p o i n t e r t o a n i n p u t c h a n n e l a n d r e t u r n s a n i n t i n d i c a t i n g t h e s t a t u s o f

    t h e c h a n n e l . A r e t u r n o f ' 0 ' m e a n s t h e c h a n n e l i s n o t b u s y w h i l e n o n - z e r o m e a n s t h e c h a n n e l i s b u s y .

    T h i s i s u s u a l l y u s e d i n c o n j u n c t i o n w i t h R T D X _ r e a d N B ( ) t o c h e c k i f a n o t h e r r e a d r e q u e s t n e e d s t o b e

    i s s u e d .

    1

    h t t p : / / c n x . o r g / c o n t e n t / m 1 3 8 0 9 / l a t e s t /

    2

    h t t p : / / c n x . o r g / c o n t e n t / m 1 3 8 0 5 / l a t e s t /

    h t t p : / / c n x . o r g / c o n t e n t / m 1 4 3 8 8 / 1 . 5 /

  • 7/30/2019 m14388-1.5

    3/7

    C o n n e x i o n s m o d u l e : m 1 4 3 8 8 3

    M o r e i n f o r m a t i o n a b o u t t h e R T D X m o d u l e a n d t h e c o m m a n d s t h a t c a n b e u s e d w i t h i t a r e i n t h e T M S 3 2 0

    D S P / B I O S U s e r ' s G u i d e ( s p r u 4 2 3 )

    3

    a n d t h e T M S 3 2 0 C 5 0 0 0 D S P / B I O S A P I R e f e r e n c e G u i d e ( s p r u 4 0 4 )

    4

    .

    E x a m p l e 1

    T h e f o l l o w i n g e x a m p l e s h o w s a s i m p l e C p r o g r a m t h a t w i l l e c h o r e c e i v e d d a t a b a c k t h r o u g h t h e o u t -

    p u t c h a n n e l . T h i s l e s a s s u m e s t h a t t h e m a i n . c l e h a s d e c l a r e d a n d e n a b l e d t h e i n p u t a n d o u t p u t

    c h a n n e l s . T h e p r o j e c t l e a n d a l l t h e n e c e s s a r y l e s a r e a v a i l a b l e f r o m v : / e c e 4 2 0 / 5 5 x / b l o c k _ r t d x .

    M A T L A B G U I l e s t h a t a r e m a d e t o i n t e r f a c e w i t h t h i s p r o j e c t a r e r t d x _ t e x t . m

    5

    a n d r t d x _ e c h o t e x t . m

    6

    .

    # i n c l u d e " d s k 5 5 1 0 _ d u a l 3 0 0 6 c f g . h "

    # i n c l u d e " d s k 5 5 1 0 . h "

    # i n c l u d e " s w i _ p r o c e s s . h "

    # i n c l u d e " d s p l i b . h "

    # i n c l u d e " r t d x . h " / / I n c l u d e f i l e f o r r t d x f u n c t i o n a l i t y

    e x t e r n R T D X _ i n p u t _ c h a n n e l i c h a n ; / / i c h a n h a s b e e n d e c l a r e d i n m a i n . c

    e x t e r n R T D X _ o u t p u t _ c h a n n e l o c h a n ; / / o c h a n h a s b e e n d e c l a r e d i n m a i n . c

    i n t r e c v d ;

    i n t s e n t N e w = 0 ;

    / / a l l d a t a p r o c e s s i n g s h o u l d b e d o n e i n S W I _ P r o c e s s B u f f e r

    v o i d S W I _ P r o c e s s B u f f e r ( )

    {

    s t a t i c u n s i g n e d i n t m b o x _ v a l u e = 0 ;

    s h o r t * p s r c , * p d e s t ;

    m b o x _ v a l u e | = S W I _ g e t m b o x ( ) ;

    / / b u f f e r s a r e o n l y p r o c e s s e d w h e n b o t h t r a n s m i t a n d r e c e i v e a r e r e a d y

    i f ( ( m b o x _ v a l u e & D M A _ R E C E I V E _ D O N E ) & & ( m b o x _ v a l u e & D M A _ T R A N S M I T _ D O N E ) ) {

    m b o x _ v a l u e = 0 ;

    / / g e t b u f f e r p o i n t e r s

    p s r c = r e c e i v e _ b u f f e r [ r e c e i v e _ b u f f e r _ t o _ p r o c e s s _ i n d e x ] ;

    p d e s t = t r a n s m i t _ b u f f e r [ t r a n s m i t _ b u f f e r _ t o _ f i l l _ i n d e x ] ;

    i f ( ! R T D X _ c h a n n e l B u s y ( & i c h a n ) ) { / / r e a d o n l y w h e n n o t b u s y

    R T D X _ r e a d N B ( & i c h a n , & r e c v d , s i z e o f ( r e c v d ) ) ;

    s e n t N e w = 1 ;

    }

    i f ( s e n t N e w = = 1 ) { / / e c h o b a c k w h e n d a t a h a s b e e n r e c e i v e d

    R T D X _ w r i t e ( & o c h a n , & r e c v d , s i z e o f ( r e c v d ) ) ;

    s e n t N e w = 0 ;

    }

    3

    h t t p : / / f o c u s . t i . c o m / l i t / u g / s p r u 4 2 3 f / s p r u 4 2 3 f . p d f

    4

    h t t p : / / f o c u s . t i . c o m / l i t / u g / s p r u 4 0 4 g / s p r u 4 0 4 g . p d f

    5

    h t t p : / / c n x . o r g / c o n t e n t / m 1 4 3 8 8 / l a t e s t / r t d x _ t e x t . m

    6

    h t t p : / / c n x . o r g / c o n t e n t / m 1 4 3 8 8 / l a t e s t / r t d x _ e c h o t e x t . m

    h t t p : / / c n x . o r g / c o n t e n t / m 1 4 3 8 8 / 1 . 5 /

  • 7/30/2019 m14388-1.5

    4/7

    C o n n e x i o n s m o d u l e : m 1 4 3 8 8 4

    r e c e i v e _ b u f f e r _ p r o c e s s e d = 1 ; / / f l a g r e c e i v e b u f f e r a s p r o c e s s e d

    t r a n s m i t _ b u f f e r _ f i l l e d = 1 ; / / f l a g o u t p u t b u f f e r a s f u l l

    }

    }

    4 U s i n g M A T L A B t o A c c e s s t h e D S P B o a r d ( P C )

    M A T L A B c a n b e u s e d t o a c c e s s t h e d a t a c o m i n g f r o m t h e D S P b o a r d . A s i m p l e t y p i n g / e c h o G U I f o r t h e

    b l o c k _ r t d x p r o j e c t h a s b e e n p r o v i d e d . A n i n t e r f a c e c a n a l s o b e p r o g r a m m e d i n V i s u a l B a s i c . T h e s e t u p

    a n d t r a n s f e r / r e c e i v e c o m m a n d s f o r M a t l a b w i l l b e d e s c r i b e d b e l o w .

    4 . 1 S e n d i n g D a t a

    B e f o r e a c c e s s i n g t h e D S P b o a r d , i t m u s t b e i n i t i a l i z e d t h r o u g h M A T L A B . T h i s i s d o n e w i t h t h i s c o d e :

    h = a c t x s e r v e r ( ' R T D X ' ) ;

    w h i c h s e t s t h e p o r t w i t h a l l n e c e s s a r y p a r a m e t e r s . T h e p o r t i s s t i l l n o t o p e n f o r w r i t i n g . T o o p e n t h e p o r t ,

    s p e c i f y t h e n a m e o f t h e c h a n n e l y o u w o u l d l i k e t o o p e n i n t h e c o m m a n d :

    i n v o k e ( h , ' O p e n ' , ' i c h a n ' , ' W ' ) ;

    T o w r i t e t o t h e b u e r , y o u i n v o k e h w i t h a ' W r i t e ' p a r a m e t e r a n d t h e d a t a t o s e n d .

    i n v o k e ( h , ' W r i t e ' , i n t 1 6 ( v ) ) ;

    I n t h i s c a s e , v w a s a c h a r a n d w e w a n t e d t o s e n d t h e A S C I I v a l u e . ( T h e r e i s a l i m i t a t i o n t o t h e A S C I I

    c o n v e r t e r i n M a t l a b : i t d o e s n o t t a k e a l l p o s s i b l e k e y p r e s s e s . ) M u l t i p l e c h a n n e l s c a n b e o p e n e d i n t h i s

    m a n n e r . W h e n t h e r e a r e m u l t i p l e c h a n n e l s o p e n , t h e w r i t e w i l l b e t o t h e m o s t r e c e n t l y o p e n e d c h a n n e l .

    B e f o r e n i s h i n g a f u n c t i o n , o r b e f o r e e x e c u t i n g a r e a d , t h e p o r t s h o u l d b e c l o s e d . T h e p o r t i s c l o s e d w i t h

    t h e c o m m a n d :

    i n v o k e ( h , ' C l o s e ' ) ;

    4 . 2 R e c e i v i n g D a t a

    T o r e a d d a t a f r o m t h e D S P , a r e a d c h a n n e l m u s t b e s e t u p . T h i s i s d o n e u s i n g t h e i n v o k e o p e n c o m m a n d

    w i t h a n ' R ' p a r a m e t e r .

    i n v o k e ( h , ' O p e n ' , ' o c h a n ' , ' R ' ) ;

    R e a d i n g d a t a f r o m t h e D S P b o a r d i s a l i t t l e m o r e c o m p l i c a t e d . I t s e e m s t h a t t h e D S P b o a r d b u e r s a l l t h e

    d a t a . T o g e t t h e l a t e s t p i e c e o f d a t a , y o u m u s t r s t ' S e e k ' t o t h e c u r r e n t m e s s a g e .

    [ s t a t u s , n u m m s g s ] = i n v o k e ( h , ' G e t N u m M s g s ' ) ;

    s t a t u s = i n v o k e ( h , ' S e e k ' , n u m m s g s ) ;

    O n c e a t t h e c o r r e c t m e s s a g e , t h e a c t u a l r e a d i n g c a n b e d o n e .

    [ s t a t u s , v a l u e s ] = i n v o k e ( h , ' R e a d I 2 ' ) ;

    A s w i t h w r i t i n g , t h e p o r t s h o u l d b e c l o s e d a f t e r r e a d i n g .

    h t t p : / / c n x . o r g / c o n t e n t / m 1 4 3 8 8 / 1 . 5 /

  • 7/30/2019 m14388-1.5

    5/7

    C o n n e x i o n s m o d u l e : m 1 4 3 8 8 5

    5 U s i n g M A T L A B G U I F e a t u r e s

    M A T L A B h a s s o m e n i c e G r a p h i c a l U s e r I n t e r f a c e ( G U I ) f e a t u r e s w h i c h c a n b e u s e d t o c o n t r o l t h e o w o f

    d a t a t o a n d f r o m t h e R T D X p o r t . T h e b a s i c i m p l e m e n t a t i o n c o n s i s t s o f a b l a n k w i n d o w ( g u r e ) w h i c h c a n

    h a v e d i e r e n t i n t e r f a c e e l e m e n t s p l a c e d o n i t . T h e s e e l e m e n t s c a n b e s l i d e r s , b u t t o n s , t e x t b o x e s , e t c . . .

    W h e n a n e l e m e n t i s a c c e s s e d ( f o r i n s t a n c e , a s l i d e r i s m o v e d , o r a b u t t o n i s p u s h e d ) , M A T L A B w i l l

    e x e c u t e a " c a l l b a c k r o u t i n e " w h i c h i s a M A T L A B f u n c t i o n d e n e d b y t h e u s e r . D e s g i n i n g t h e s e i n t e r f a c e s i s

    s i m p l e .

    5 . 1 C r e a t i n g a U s e r I n t e r f a c e w i t h S l i d e r s

    D o w n l o a d T h e s e F i l e s

    r t d x _ s l i d e r s . m

    7

    - U s e r I n t e r f a c e

    r t d x _ w r t _ s l i d e r s . m

    8

    - C a l l b a c k F i l e

    E x a m p l e 2

    1 % r t d x _ s l i d e r s - i n i t i a l i z e s R T D X p o r t a n d s e t s u p t h r e e s l i d e r s

    2

    3 h = a c t x s e r v e r ( ' R T D X ' ) ;

    4

    5 % o p e n a b l a n k f i g u r e f o r t h e s l i d e r

    6 F i g = f i g u r e ( 1 ) ;

    7 % o p e n s l i d e r s

    8 % f i r s t s l i d e r

    9 s l d 1 = u i c o n t r o l ( F i g , ' u n i t s ' , ' n o r m a l ' , ' p o s ' , [ . 2 , . 7 , . 5 , . 0 5 ] , . . .

    1 0 ' s t y l e ' , ' s l i d e r ' , ' v a l u e ' , 4 , ' m a x ' , 2 5 4 , ' m i n ' , 0 , ' c a l l b a c k ' , ' r t d x _ w r t _ s l i d e r s ' ) ;

    1 1

    1 2 % s e c o n d s l i d e r

    1 3 s l d 2 = u i c o n t r o l ( F i g , ' u n i t s ' , ' n o r m a l ' , ' p o s ' , [ . 2 , . 5 , . 5 , . 0 5 ] , . . .

    1 4 ' s t y l e ' , ' s l i d e r ' , ' v a l u e ' , 4 , ' m a x ' , 2 5 4 , ' m i n ' , 0 , ' c a l l b a c k ' , ' r t d x _ w r t _ s l i d e r s ' ) ;

    1 5

    1 6 % t h i r d s l i d e r

    1 7 s l d 3 = u i c o n t r o l ( F i g , ' u n i t s ' , ' n o r m a l ' , ' p o s ' , [ . 2 , . 3 , . 5 , . 0 5 ] , . . .

    1 8 ' s t y l e ' , ' s l i d e r ' , ' v a l u e ' , 4 , ' m a x ' , 2 5 4 , ' m i n ' , 0 , ' c a l l b a c k ' , ' r t d x _ w r t _ s l i d e r s ' ) ;

    L i n e s 9 t h r o u g h t h e e n d c r e a t e t h e t h r e e s l i d e r s f o r t h e u s e r i n t e r f a c e . S e v e r a l p a r a m e t e r s a r e u s e d t o s p e c i f y

    t h e b e h a v i o r o f e a c h s l i d e r . T h e r s t p a r a m e t e r , F i g , t e l l s t h e s l i d e r t o c r e a t e i t s e l f i n t h e w i n d o w w e c r e a t e d

    i n L i n e 6 . T h e r e s t o f t h e p a r a m e t e r s a r e p r o p e r t y / v a l u e p a i r s :

    u n i t s : N o r m a l t e l l s M a t l a b t o u s e p o s i t i o n i n g r e l a t i v e t o t h e w i n d o w b o u n d a r i e s .

    p o s : T e l l s M a t l a b w h e r e t o p l a c e t h e c o n t r o l .

    s t y l e : T e l l s M a t l a b w h a t t y p e o f c o n t r o l t o p l a c e . s l i d e r c r e a t e s a s l i d e r c o n t r o l .

    v a l u e : T e l l s M a t l a b t h e d e f a u l t v a l u e f o r t h e c o n t r o l .

    m a x : T e l l s M a t l a b t h e m a x i m u m v a l u e f o r t h e c o n t r o l .

    m i n : T e l l s M a t l a b t h e m a x i m u m v a l u e f o r t h e c o n t r o l .

    c a l l b a c k : T e l l s M a t l a b w h a t s c r i p t t o c a l l w h e n t h e c o n t r o l i s m a n i p u l a t e d . r t d x _ w r t _ s l i d e r s i s a

    M a t l a b l e t h a t w r i t e s t h e v a l u e s o f t h e c o n t r o l s t o t h e R T D X p o r t .

    7

    h t t p : / / c n x . o r g / c o n t e n t / m 1 4 3 8 8 / l a t e s t / r t d x _ s l i d e r s . m

    8

    h t t p : / / c n x . o r g / c o n t e n t / m 1 4 3 8 8 / l a t e s t / r t d x _ w r t _ s l i d e r s . m

    h t t p : / / c n x . o r g / c o n t e n t / m 1 4 3 8 8 / 1 . 5 /

  • 7/30/2019 m14388-1.5

    6/7

    C o n n e x i o n s m o d u l e : m 1 4 3 8 8 6

    E v e r y t i m e a s l i d e r i s m o v e d , t h e r t d x _ w r t _ s l i d e r s . m l e i s c a l l e d :

    E x a m p l e 3

    1 % r t d x _ w r t _ s l i d e r s : w r i t e s v a l u e s o f s l i d e r s o u t t o r t d x

    2

    3 % o p e n r t d x p o r t f o r d a t a t r a n s f e r

    4 s t a t u s = i n v o k e ( h , ' O p e n ' , ' i c h a n ' , ' W ' ) ;

    5

    6 % s e n d v a l u e f r o m s l d 1

    7 v 1 = r o u n d ( g e t ( s l d 1 , ' v a l u e ' ) ) ;

    8 s t a t u s = i n v o k e ( h , ' W r i t e ' , i n t 1 6 ( v 1 ) ) ;

    9

    1 0 % s e n d v a l u e f r o m s l d 2

    1 1 v 2 = r o u n d ( g e t ( s l d 2 , ' v a l u e ' ) ) ;

    1 2 s t a t u s = i n v o k e ( h , ' W r i t e ' , i n t 1 6 ( v 2 ) ) ;

    1 3

    1 4 % s e n d v a l u e f r o m s l d 3

    1 5 v 3 = r o u n d ( g e t ( s l d 3 , ' v a l u e ' ) ) ;

    1 6 s t a t u s = i n v o k e ( h , ' W r i t e ' , i n t 1 6 ( v 3 ) ) ;

    1 7

    1 8 % s e n d r e s e t p u l s e

    1 9 s t a t u s = i n v o k e ( h , ' W r i t e ' , i n t 1 6 ( 2 9 8 9 ) ) ;

    2 0

    2 1 % c l o s e r t d x p o r t

    2 2 s t a t u s = i n v o k e ( h , ' C l o s e ' ) ;

    L i n e 7 r e t r i e v e s t h e v a l u e f r o m t h e s l i d e r u s i n g t h e g e t f u n c t i o n t o r e t r i e v e t h e v a l u e p r o p e r t y . T h e v a l u e

    i s t h e n r o u n d e d o t o c r e a t e a n i n t e g e r , a n d t h e i n t e g e r i s s e n t a s a n 1 6 - b i t q u a n t i t y t o t h e D S P i n L i n e

    8 . T h e o t h e r t w o s l i d e r s a r e s e n t i n t h e s a m e w a y . L i n e 1 9 s e n d s 2 9 8 9 t o t h e D S P , w h i c h c a n b e u s e d t o

    i n d i c a t e t h a t t h e t h r e e p r e v i o u s l y - t r a n s m i t t e d v a l u e s r e p r e s e n t a c o m p l e t e s e t o f d a t a p o i n t s . ( Y o u c a n u s e

    w h a t e v e r v a l u e y o u w a n t . ) T h i s c a n b e u s e d t o p r e v e n t t h e D S P a n d M a t l a b f r o m l o s i n g s y n c h r o n i z a t i o n

    i f a t r a n s m i t t e d c h a r a c t e r i s n o t r e c e i v e d b y t h e D S P a n d p r o v i d e s s o m e e r r o r d e t e c t i o n .

    n o t e : L i n e 2 2 c l o s e s t h e R T D X p o r t . M a k e s u r e y o u c l o s e t h e p o r t a f t e r s e n d i n g a d a t a b l o c k t o

    t h e D S P .

    5 . 2 A d v a n c e d f e a t u r e s

    T h e s l i d e r e x a m p l e s h o w s s o m e b a s i c f e a t u r e s o f t h e g u i t o o l s . T h e h a n d l e f o r t h e R T D X s e r v e r i s g e n e r a t e d

    i n t o t h e w o r k s p a c e s o t h a t i t c a n b e u s e d f o r w r i t i n g . B u t o t h e r e l e m e n t s , s u c h a s t e x t b o x e s c a n n o t b e d e a l t

    w i t h a s e a s i l y . T h e P a r a m e t e r s f r o m t h e s e c a n b e a c c e s s e d t h r o u g h t h e i r r e t u r n e d h a n d l e s . S o m e e x a m p l e s :

    E x a m p l e 4

    % G U I . m

    % * * * * S a m p l e G U I , T e x t a n d a B u t t o n * * *

    % o p e n a b l a n k f i g u r e

    F i g = f i g u r e ( 1 ) ;

    s e t ( F i g , ' N a m e ' , ' T e s t G U I ' ) ;

    h t t p : / / c n x . o r g / c o n t e n t / m 1 4 3 8 8 / 1 . 5 /

  • 7/30/2019 m14388-1.5

    7/7

    C o n n e x i o n s m o d u l e : m 1 4 3 8 8 7

    % S p a c e t o e n t e r t e x t

    e d 2 = u i c o n t r o l ( F i g , ' b a c k g r o u n d c o l o r ' , ' w h i t e ' , ' u n i t s ' , ' N o r m a l i z e d ' , ' p o s ' , [ . 1 , . 6 , . 4 , . 0 5 ] , . . .

    ' s t r i n g ' , ' D e f a u l t T e x t ' , ' s t y l e ' , ' e d i t ' ) ;

    % B u t t o n

    b u t 1 = u i c o n t r o l ( F i g , ' f o r e g r o u n d c o l o r ' , ' b l u e ' , ' u n i t s ' , ' N o r m a l i z e d ' , ' p o s ' , [ . 1 , . 4 , . 5 , . 1 ] , . . .

    ' s t r i n g ' , ' P r e s s M e ! ' , ' s t y l e ' , ' p u s h b u t t o n ' , ' c a l l b a c k ' , ' S a m p l e G U I ' ) ;

    A T e x t b o x i s c r e a t e d w i t h d e f a u l t t e x t i n i t t h a t s a y s : " D e f a u l T e x t " . A b u t t o n i s a l s o c r e a t e d ,

    w h i c h w h e n p r e s s e d , w i l l e x e c u t e t h e c a l l b a c k f u n c t i o n S a m p l e G U I . m

    % S a m p l e G U I . m

    % G e t T e x t

    t e s t T e x t = g e t ( e d 2 , ' s t r i n g ' )

    N o w t e s t T e x t h o l d s w h a t e v e r s t r i n g w a s e n t e r e d i n t o t h e t e x t b o x . T h e f u n c t i o n g e t ( ) i s u s e d t o

    r e t r i e v e t h e d a t a f r o m t h e ' s t r i n g ; p a r a m e t e r i n t h e e d 2 h a n d l e . M A T L A B h e l p u i c o n t r o l g i v e s

    t h e f u l l l i s t o f o p t i o n s f o r i n t e r f a c e e l e m e n t s .

    h t t p : / / c n x . o r g / c o n t e n t / m 1 4 3 8 8 / 1 . 5 /