Announcement

Collapse
No announcement yet.

serial data

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

  • serial data

    Hi,
    I have now managed to get data from a PIC into the display, what I would now like to do is get multiple data in, what I envisage is to send a character first and then the data EG A200 B25 C125 etc and depending on the character read the data in to the correct location.
    Firstly, is this the best way to do it and second, does anyone have any code examples of how to do it.

    Regards,
    bobby

  • #2


    Hi.

    I do the same in my telescope controller project. If you can wait a few days, I can post my code here when it will be finished. 

    Comment


    • #3


      Hi Thomas,
      Thanks for your offer, I would be interested in it.
      I have managed to get something like what I want, the only problem as I see it is that the data always has to be a specific length, although this is not a major problem for what I am doing. I have attached the test code in case others are interested.

      From the PIC I send out as (PDS basic)
      HSerOut ["

      Comment


      • #4


        Hi,
        Managed to send different lengths of data, use the # to signify end of data in the display.
        From the PIC
        'The : is the qualifier the display requires for the start of data
        'The next CHR is to determine what the data is
        'Then the data
        'The # it the end of data for the display

        HSerOut ["",Hex2 DATE,#]
        DelayMS 10
        HSerOut [":M",Hex2 MONTH,#]
        DelayMS 10
        HSerOut [":Y",Hex2 YEAR,#]
        DelayMS 10
        HSerOut [":H",Hex2 HOURS,#]
        DelayMS 10
        HSerOut [":m",Hex2 MINUTES,#]
        DelayMS 10
        HSerOut [":S",Hex2 SECONDS,#]
        DelayMS 10
        HSerOut [":C",Dec5 Count1,#]
        DelayMS 10
        The count is a word value, all others are only 2 digits.

        Hope it helps someone.

        Regards,
        Bobby

        Attached files serial10.4dg (8.3 KB)

        Comment


        • #5

          Hi Bobby.

          Here is my code. I use datagrams with different length and starting with a '_' character followed by a character that identifies the destination od the data. 

          _I......   for info printed on the screen

          _K... a singke Key code from the keyboard.

          My microcontroller sends for example the the following datagram to the display to show the GPS latitude and longitude on the display.

          "_IGddd.mm.sss E+dd.mm.sss S"

          where "ddd.mm.sss E" is GPS latitude and "+dd.mm.sss S" is GPS longitude

          The datagram "_K4" will be send if the key "4" on the keyboard is pressed.

          In my example you can find also how I send the time information.

          Code:
           //arrays for the strings    var sGPSLat[10];      
              var sGPSLon[10];
              var sTime[10];
              var sDate[10];
              var sTemp[10];
              var sHum[10];
          //functions to display the infos on the screenfunc UpdateGPSInfo()
             txt_Set(TEXT_OPACITY, OPAQUE);
             txt_Set(TEXT_COLOUR,GREEN);
             txt_Set(FONT_SIZE, FONT3);
             txt_MoveCursor(1,5);
             print([STR] sGPSLat,"\n"); 
             print([STR] sGPSLon,"\n");
          endfunc
          
          func UpdateTimeInfo()
             txt_Set(TEXT_OPACITY, OPAQUE);
             txt_Set(TEXT_COLOUR,GREEN);
             txt_Set(FONT_SIZE, FONT3);
             txt_MoveCursor(3,5);
             print([STR] sDate,"\n"); 
             print([STR] sTime,"\n");
          endfunc
          
          
          
          //funtion to read  count  characters from the com_buffer to the destfunc ReadStringFromCom(var dest, var count)
          var i;
          var bpt;
          var c;
           i:=0;
           bpt:=str_Ptr(dest);
           repeat 
              c:=serin();        //read character from COM
              str_PutByte(bpt + i,c);      //add character to buffer dest
              i++;               //next position 
           until (i > count-1)
             str_PutByte(bpt + i,0);  //trailing zero.
          endfuncfunc ReadCom()
          var ch;
              repeat 
                 pause(10);                    //give th buffer a little time to fill  
              until((com_Count()>0));
              
              ch:=serin();     //Read the first Character
              if (ch=='K')   //it is a "K" then the next is a keyboard char 
                ch:=serin();    /read the keyboard character
              endif;
              if (ch=='I')       //if it is a "I" for Infostring for printing on the screen
                ch:=serin();                            //read the next character
          
                if (ch=='T')                            //if it is a "T" for Time  
                 ReadStringFromCom(sTime,8);           //8 charcters for time    (hh:mm:ss);
                 ReadStringFromCom(sDate,10);          //10 characters for date(dd.MM.yyyy);
                 UpdateTimeInfo();    //print it
                endif;
          
                if (ch=='G')                           //if it is GPS INfo
                 ReadStringFromCom(sGPSLat,12);          //12 charcters for latitude (ddd.mm.sss E);
                 ReadStringFromCom(sGPSLon,12);          //12 characters for longitude   (+dd.mm.sss S);
                 UpdateGPSInfo(); //print it
                endif;
          
               ch:=0;   //set the return result to 0 if it is no Keyboard char
              endif;
          
              com_Init(combuf, 32, '_' );  //init Com Buffer to clean up after decoding datagram
          
              return(ch); //return the Char if it is a keyboard char else return 0
               
          endfunc
          
          
          
           func main()    com_Init(combuf, 32, '_' );  //init Com Buffer 
           repeat     key:=ReadCom();    if (key!=0)  //if keyboard key        //do something with the  key   endif;  until forever; endfunc;

          Comment

          Working...
          X