Announcement

Collapse
No announcement yet.

32-PT GFX Pointers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 32-PT GFX Pointers

    Hello I am using a 32-PT GFX to display data from an inverter and having some trouble using pointers in 4DGL. The data I get from the inverter controller is in the following format: 'v','1','2','5','.','5',';' the first character tells me the type of data then the rest is the value followed by a semi colon to end the data. Heres the code:

    HTML Code:
    /*********************************************
    * Paramters: Input - Received Data
    * Return: None
    *
    * Description: function to set pointer to correct
    *              data array.
    *
    * Author: Adam Oliver
    *********************************************/
    func dataType(var data)
    if(data == 'V') //Max Voltage Data [V]
    *ptr := &MaxVolt[0];
    display("Max Voltage",3);
    dataRdyFlag := 1;
    endif
    endfunc
    
    /*********************************************
    * Paramters: Input - Received Data
    * Return: None
    *
    * Description: Sends data off the the proper array
    *
    * Author: Adam Oliver
    *********************************************/
    func parseData(var data)
    *ptr := data; //Place data into array
    ptr++;
    endfunc
    
    /*********************************************
    * Paramters: None
    *                   
    * Return: Character from COM0
    *
    * Description: Receives data from COM0
    *
    * Author: Adam Olvier
    *********************************************/
    func receive()
    
    var i := 0;
    var com_data;
    
    repeat
    
    com_data := serin(); //update array
    if(com_data != -1) //ensure clean data
    rxBuf[i] := com_data;
    endif
    
    if(!dataRdyFlag)
    dataType(rxBuf[i]); // Set Data Type
    endif
    if((dataRdyFlag)) //if flag set
    parseData(rxBuf[i]);
    i++;
    endif
    
    until (i == 7);
    i := 0;
    dataRdyFlag := 0; //reset flag
    rxBuf[0] := 0; //reset data type
    
    
    
    I have tried the following methods of printing the arrays:
    
    
    for(i:=0; i < 7; i++)
    print( [CHR] MaxVolt[i]);
    next
    
    for(i:=0; i < 7; i++)
    print(*ptr++);
    next
    So I am reading data in from the serial port then checking for the first character and then depending on the character use pointers to select the proper array. Then using that pointer i want to save the rest of the incoming data to the array. I gave an example for maximum voltage data. The display function is just a print function but with several positions on the screen that does work.
    I have also confirmed my serial function does work because it will give me back the correct data type for all the 7 types I just cannot seem to send the characters to an array using pointers.

  • #2


    Since arrays are arrays of integers, not arrays of bytes, the first print method is the correct one.



    Put some prints into your code to aid debugging.



    I think you will find that moving the first endif in receive to after the third will improve your code markedly
    Mark

    Comment

    Working...
    X