This page is optimized for mobile devices, if you would prefer the desktop version just
click here
Part 2
- In this part you will be creating a Visual Basic (VB) application that communicates with a target application through the Real Time Data Exchange (RTDX). The VB application will have two buttons that when pressed will send different numbers to the target (DSP board). The target application will print the value received to a LOG object and turn the output cosine either on or off.
- Create a new Visual Basic project (These may not be exactly the steps depending on your version of Visual Studio):
- Start Visual Studio.
- Select Create Project.
- In the Project types: select Visual Basic:Windows.
- Under Templates: select Windows Forms Application.
- The Solution Name will be
CosineOnOff
. - Click OK.
- Add two buttons to your form with the following characteristics:
- (Name): Button1
- Text: On
- (Name): Button2
- Text: Off
- In the Form code in the Form1:(Declarations) section add code for the status constants and other variables. This will be right under the statement
Public Class Form1
. The code should be:
'--------------------------------------------------------------------------
' RTDX Return Status'--------------------------------------------------------------------------
Const Success =&H0 ' Method call is valid
Const Failure =&H80004005 ' Method call failed
Const ENoDataAvailable =&H8003001E ' No data currently available.
Const EEndOfLogFile =&H80030002 ' End of transmission'--------------------------------------------------------------------------
' Variable Declarations'--------------------------------------------------------------------------
Dim rtdx As Object ' Holds the rtdx objectDim bufferstate As Integer ' Holds the number of bytes xmitted
' or pending xmissionDim status As Integer ' RTDX Function call return status
- The first function to be executed when a project is started is
Form:Load
. In this function put the code for initializing the RTDX channel. Name the channelHtoTchan
for Host to Target channel.
Try
rtdx_out = CreateObject("RTDX") status = rtdx.Open("HtoTchan", "W") ' Open channel for writing
Catch ex As Exception 'Exception occured when opening the RTDX object
System.Diagnostics.Debug.WriteLine("Opening of channel HtoTchan failed") rtdx_out = Nothing
End ' Force program terminationEnd Try
- One of the last functions to execute is the
Form:FormClosing
function. In this function put the code for cleaning things up.
status = rtdx.Close() ' Close rtdx
Set rtdx = Nothing ' Free memory reserved for rtdx obj
- In the
Button1:Click
function put the code to be executed when the button is clicked. When the button is clicked it should send a 4 byte integer, the number 1, to the target indicating that button 1 was clicked. The code for doing this is:
Dim Data As IntegerData = 1
status = rtdx.WriteI4(Data, bufferstate)If status = Success ThenDebug.Print "Value "&Data&" was sent to the target"
ElseDebug.Print "WriteI4 failed"
End If
- In the
Button2:Click
function put the code to be executed when the button is clicked. When the button is clicked it should send a 4 byte integer, the number 0, to the target indicating that button 2 was clicked. The code is the same as above, the data is just 0. - Now the target code needs to be updated.
- Save the
DSK6713_audio.c
file asDSK6713_audio2.c
and use this as the main file in your project. - Include a header file so we can use the RTDX.
#include<rtdx.h>
- Create a global input channel called
HtoTchan
. This code will go in the global variables section.
RTDX_CreateInputChannel( HtoTchan );
- Add code to the top of function
processing
:
int data;
int status;int busystatus=0;/* enable the Host to Target channel */
RTDX_enableInput(&HtoTchan );
- In the
while
loop add the code:
/* check to see if the channel is busy before the read */
if (busystatus == 0){
/* Print the data if something was actually read */if (RTDX_sizeofInput(&HtoTchan) == sizeof(data))
{// data received here
LOG_printf(&trace,"Value sent = %d",data);
}status = RTDX_readNB(&HtoTchan,&data, sizeof(data) );
}/* get the status of the channel */busystatus = RTDX_channelBusy(&HtoTchan);
- The above code will read 4 byte values from the
HtoTchan
input channel. When a value is received the program will get to the statement// data received here
and will have the value in the variabledata
. - Since the variable data will contain either a 1 or a 0 this can be used to multiply the cosine value to turn it on and off.
(Int16)(32000.0*y*data);
- Set up RTDX by opening the Configuration window with Tools->RTDX->Configuration Control, right click to select properties and then click on Continuous mode. After closing the properties check the Enable RTDX box.
- Run the target application. It is important that the target application be started before the VB application. If the VB application is started first the channel may not get initialized.
- Run the VB application.
- Verify that the tone that is output can be turned on and off with your VB program.
Read also:
OpenStax, Dsp lab with ti c6x dsp and c6713 dsk. OpenStax CNX. Feb 18, 2013 Download for free at http://cnx.org/content/col11264/1.6
Google Play and the Google Play logo are trademarks of Google Inc.