next up previous
Next: Decription of RTDX_Service_2 Up: Tutorial 2 Previous: Tutorial 2

Description of main

In the following we will shortly describe the main routine along the program code:

int main()
{
    long sendnum = 0;
    long recnum = 0;
    string action = "";

    RTDX_Service_2* RTDXS = new RTDX_Service_2();
    if (RTDXS->Init()> 0) {
        cerr << "RTDX Error: "
             << "Failure on RTDX-initialization"
             << endl;
        return 1;
    }

    if (RTDXS->SetBoardAndProcessor(L"C6416 Revision 1.1 DSK",
                                    L"CPU_1") == 1) {
        cerr << "RTDX Error: "
             << "Could not set board/processor in RTDX"
             << endl;
        return 1;
    }

    if (RTDXS->StartRTDX() != 0) {
        cerr << "RTDX Error: " 
             << "Could not start RTDX"
             << endl;
        return 1;
    }

    if (RTDXS->OpenWriteChannel() != Success) {
        cerr << "RTDX Error: " 
             << "Could not open channel 'ichan'"
             << endl;
        return 1;
    }

    if (RTDXS->OpenReadChannel() != Success) {
        cerr << "RTDX Error: "
             << "Could not open channel 'ochan'"
             << endl;
        return 1;
    }

Routine main starts with the declaration of the number to be sent (sendnum), the number to be received (recnum) and the string action, which will contain the keyboard-entered action code. Next the RTDXS_Service-class is instantiated, point to by RTDXS. In RTDX->Init the 'COM'-interface is activated and two RTDX-Objects are created, one for a write- and one for a read channel. In RTDX->SetBoardAndProcessor the name of the board and the processor are initialized for both RTDX-Objects. It is assumed that only one board is connected and that there is only one processor on the board. The names are transferred as 'wide character' parameters in the call. Next the RTDX-interface is configured and enabled using function StartRTDX and the write- and the read-channel are opened.

    do {
        cout << endl
             << "Enter 's' for send and 'q' for quit:  ";
        cin >> action;
        cout << endl;

        if (action == "s") {
            cout << "Enter number to be sent: ";
            cin >> sendnum;
            cout << endl

            // Send number
            RTDXS->WriteToClient(sendnum);

            // wait for response
            do {
                recnum = RTDXS->ReadFromClient();
            } while (recnum < 0);
            cout << "Response received:  "
                 << recnum << endl << endl << endl;
        }
    } while (action != "q");
    return 0;
}

In the last part of the main-program the user is asked to chose between sending a number to the DSP-board (input 's') or to quit (input 'q'). If the user chooses to enter 's', he is asked for an integer number. After entering the number, it is sent to the DSP-board via function WriteToClient. Finally the routine waits for a valid response from the client in blocking mode and displays the result, when received. Then the selection between sending or quitting the program starts allover again.


next up previous
Next: Decription of RTDX_Service_2 Up: Tutorial 2 Previous: Tutorial 2
H. Rogalla 2005-12-07