LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert C++ to LabView

Having trouble converting this C++ code to LabView.

 

Suggestions???

 

/***********************
*    nd_kill_node
*    nd_kill_node attempts to stop a node that is in a state that doesn't accept commands. ie streaming, LDC etc
*    Command Format
*        Length:        10 bytes
*        Byte 1:        0xAA        SOP
*        Byte 2:        0xFE        Message Type
*        Byte 3:        0x00        Address Mode
*        Byte 4:        MSB of Node Address
*        Byte 5:        LSB of Node Address
*        Byte 6:        0x02
*        Byte 7:        0x00        Command Byte
*        Byte 8:        0x90        Command Byte
*        Byte 9:        MSB Checksum
*        Byte 10:    LSB Checksum
*    Good Response:
*        Length:        1 Byte
*        Byte 1:        0xAA        Valid packet response from base station
*
*    PRE:    hPort is a legitimate, open, port handle of type HANDLE
*            usNode is an unsigned short holding the node's address to stop
*    POST:    if command is sent successful, 0 is returned
*            otherwise, some error code
*
* Note:Must call nd_kill_node_status to poll the status of the kill node command
* you can also call abort the kill node command by sending any byte to the
* basestation. Pinging the basestation will suffice.
***********************/
int nd_kill_node_init(/* in */ HANDLE hPort,
                      /* in */ unsigned short usNode)
{

   
   

    unsigned char ucCmd[10] = {    0xAA,            //    SOP
                                0xFE,            //    Message Type
                                0x00,            //    Address Mode
                                usNode >> 8,    //    MSB of Node Address
                                usNode & 0xFF,    //    LSB of Node Address
                                0x02,            //    Command Length
                                0x00,            //    MSB of Command Byte
                                0x90,            //    LSB of Command Byte
                                (0x190 + (usNode >> 😎 + (usNode & 0xFF)) >> 8,        //    MSB of the checksum
                                (0x190 + (usNode >> 😎 + (usNode & 0xFF)) & 0xFF    //    LSB of the checksum
    };

    unsigned char ucResponse;        //    holds the response
    DWORD    dwBytes_written = 0,    //    number of bytes written to the port
            dwBytes_read = 0;        //    number of bytes read from the port
    int iResult,                    //    return value of port read/write functions
        iPos;                        //    position in the console that the command was written to
    CString strFormat;                //    formatted string for output to command information window

    // before we send the kill node command send a byte to interupt the base station
    // this will stop it from listening for streaming, HSS or LDC data
    unsigned char ucByte = 0x01;
    if ((iResult = port_write(hPort, &ucByte, 1, dwBytes_written, iPos)) != 0)
        return iResult;
    strCmd_info[iPos] = "Send byte to stop the base station from streaming.";

    //now purge the buffer
    port_purge(hPort);

    /*    send the command to the serial port    */
    if ((iResult = port_write(hPort, ucCmd, 10, dwBytes_written, iPos)) != 0)
        return iResult;

    /*    append to the command description    */
    strFormat.Format("Attempt to kill node on node %i\r\nSOP: %#04x\t\t\tMessage Type: %#04x\t\tAddress Mode: %#04x\r\nMSB Node Address: %#04x\tLSB Node Address: %#04x\r\nCommand Length: %#04x\t\tMSB of Command Byte: %#04x\tLSB of Command Byte: %#04x\r\nMSB of Checksum: %#04x\t\tLSB of Checksum: %#04x",
            usNode, ucCmd[0], ucCmd[1], ucCmd[2], ucCmd[3], ucCmd[4], ucCmd[5], ucCmd[6], ucCmd[7],
            ucCmd[8], ucCmd[9]);
    strCmd_info[iPos] = strFormat;


    /*    read the response from the serial port    */
    if ((iResult = port_read(hPort, &ucResponse, 1, dwBytes_read, iPos)) != 0)
        return iResult;

    /*    the only legitimate response is a 0xAA    */
    if (ucResponse != 0xAA) {
        /*    append to the command description    */
        strFormat.Format("Failed to start kill node on node %i\r\nResponse: %#04x", usNode, ucResponse);
        strCmd_info[iPos] = strFormat;
        return ERROR_INVALID_RESPONSE;
    }

    /*    append to the command description    */
    strFormat.Format("Kill node command started successful for node %i\r\nResponse: %#04x", usNode, ucResponse);
    strCmd_info[iPos] = strFormat;

    return 0;
}

0 Kudos
Message 1 of 4
(5,739 Views)
It would help if you told us where you are having problems. Instead of trying to "convert" the code to LabVIEW, just figure out what it does and document/flowchart it.  Then start thinking in G based on your flowchart.
Message Edited by Ravens Fan on 11-25-2009 06:01 PM
0 Kudos
Message 2 of 4
(5,735 Views)

Hi markfranklin,

 

Ae you able to convert the C++code to LabVIEW, if Yes send me your mail id  or please help me to understand what all constraints are there while converting C++code to LabVIEW ( like constructors concept, structure concept convertion to LabVIEW)..

 

Thanks in Advance

Geeta Kannammanavar

0 Kudos
Message 3 of 4
(5,409 Views)

You should not try to convert C++ code verbatim to LabVIEW. The fact that you talk about constructers indicates that you have not much of an understanding of LabVIEW. A self study of one of the basic LabVIEW courses may give you some better ideas.

 

Basically you do not want to translate the specifics of a language, here C++, into another language, but the functionality of some code. That usually means you will have to understand both programming paradigmas, here sequential, optionally object oriented programming in C++, there data flow, optionally object oriented code. They can do both much the same but the way you aproach them is quite a bit different.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 4 of 4
(5,386 Views)