Announcement

Collapse
No announcement yet.

Problem with serial

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

  • Problem with serial

    Hi,

    Trying to have serial working on 70D:

    //////////////////////////////////:

    setbaud(BAUD_115200); // 115200 bauds so 11520 char/s so 345 char per 30ms loop cycle
    com_Init(comBuffer, 99, ":" );

    repeat
    if(com_Error()) // if there were low level comms errors,
    putstrXY(300,460, "ERROR") ;
    endif
    if ( com_Sync() )
    putstrXY(0,460, "SYNC OK") ;
    else
    putstrXY(0,460, "SYNC KO") ;
    endif
    count := com_Count() ;
    putnumXY(100, 460, DEC, count);
    if ( com_Full() )
    comBuffer[99] := 0 ;
    putstrXY(420,460, comBuffer) ;
    com_Init(comBuffer, 99, ':' );
    endif
    forever

    /////////////////////////////////

    Then using terminal at 115200 to send:
    :SSSS AAAAA RRRR PPP GGG LLL HHH RPM EGT WAT TUR FUE TOI POI VVV AAA EXT EG2 EG3 EG4 CH1 CH2 CH3 CH4


    no sync,

    count always 0

    no error



    Any clue?

    Thanks,

    François

  • #2
    Hi François,

    Apologies for the delayed response. Your inquiry somehow went through without being addressed.

    The main reason why your code is not working is due to
    com_Init(comBuffer, 99, ":" );
    .
    It should be com_Init(comBuffer, 2*sizeof(comBuffer), ':' ). (Take note the ':')

    Also, you may refer to this code for the implementation.
    Code:
    var buffer[50];
    
    func main()
    
        com_SetBaud(COM0,11520); // Optional since by default com0 is set to 115200
        com_Init(buffer, 2*sizeof(buffer), ':');
    
        repeat
            if(com_Error())       // if there were low level comms errors,
                txt_MoveCursor(2,0);
                print("Error");
            endif
    
            txt_MoveCursor(4,0);
            if (com_Sync())       // check if already synced
                print("Synced    ");
            else
                print("Not Synced");
            endif
    
            if(com_Count() && com_Full())       // store bytes in recvBytes until full
                txt_MoveCursor(0,0);
                putstr(buffer);
                com_Init(buffer, 2*sizeof(buffer), ':');        // reinitialize com
            else
                txt_MoveCursor(1,0);
                print("Count:" ,com_Count(), " ");
            endif
        forever
    
    endfunc
    Hope this helps.
    Best regards,
    Last edited by Vince_4D; 14th February 2019, 03:59 PM.
    Vince_4D

    Comment


    • #3
      Thanks,

      Will try. Anyway I also in the mean time did remove the com_init and just printed com_count(), no character was seen. Keep posted!

      François

      Comment


      • #4

        remove the com_init and just printed com_count(), no character was seen
        Hi,
        May I know what you are trying to implement?
        You can send the code snippet here.

        Best regards,
        Vince_4D

        Comment


        • #5
          The snippet is the faulty one at the beginning of this post, but because it didn't work, I tried to see if any characters were moving in

          Comment


          • #6
            I did the changes on com_init buffer length

            Issue is that when typing in the terminal, the sync never comes although typing the ':'


            Tried the ':' and ":" syntax

            Looks as if the display is blind (using the 115200 terminal)

            Comment


            • #7
              And at every loop the count is display (see snippet): it is always at zero.

              And about the purpose: reading a fixed length frame coming from a sensor box, starting with ":"

              Comment


              • #8
                Hi,

                I'm quite astonished as to why it is not working on your end.

                Kindly implement this code. This is a modified version of your code.
                Code:
                var comBuffer[50];
                var count;
                
                func main()
                
                    setbaud(BAUD_115200); // 115200 bauds so 11520 char/s so 345 char per 30ms loop cycle
                    com_Init(comBuffer, 2*sizeof(comBuffer), ':' );
                
                    repeat
                        if(com_Error()) // if there were low level comms errors,
                            putstrXY(0,0, "ERROR") ;
                        endif
                        if ( com_Sync() )
                            putstrXY(0,50, "SYNC OK") ;
                        else
                            putstrXY(0,50, "SYNC KO") ;
                        endif
                        count := com_Count() ;
                        putnumXY(0, 100, DEC, count);
                        print("  ");
                        if (com_Full())
                            putstrXY(0,150, comBuffer) ;
                            com_Init(comBuffer, 2*sizeof(comBuffer), ':' );
                        endif
                    forever
                
                endfunc
                Btw, I tested it using the Terminal utility of WS4. As you know, to start the communication, ':' must be sent first by the host.
                Click image for larger version

Name:	teminal.PNG
Views:	127
Size:	11.5 KB
ID:	67099

                Hope this will help and best regards,

                Vince_4D

                Comment


                • #9
                  I just tried will all default values: no com_init, just a loop with a com_count();

                  Always returns zero from Terminal 115200, just as if terminal was not able to connect to device (although it does)

                  Comment


                  • #10
                    Working: pb is the terminal.

                    I'm using a Mac with a WinXP VM under Virtual BOX

                    Workshop works fine, but terminal does not work. Why ? Don't know...

                    I installed the CP210x driver directly on the MAC and could with a terminal (screen command) directly send my characters to the display.


                    Note that my initial code was OK, the number of expected characters shouldn't be doubled in the com_Init command.

                    KR

                    François
                    Last edited by gazefis; 15th February 2019, 06:39 AM.

                    Comment


                    • #11
                      Hi,
                      no com_init, just a loop with a com_count();
                      If you implement this routine, com_Count() will only return 0 since the function counts the number of characters in the communication buffer which is, in this case, not initialized using com_Init(...) function.

                      If you want to count the number of data coming in (without implementing communication buffer), you can use this code snippet.

                      In repeat-forever loop
                      Code:
                        char := serin();   //serial data coming in com0
                              if(char>=0)
                                  count++;
                                  txt_MoveCursor(0,0);
                                  print(count);
                              endif
                      Hope this will help.

                      Best regards,
                      Vince_4D

                      Comment


                      • #12
                        OK. Indeed I lost some time trying to find out why it didn't initially work (introducing some mistakes such as the one you just pointed out), but that was just the terminal that didn't work, initial code works just fine.

                        If some of you use a MAC with a Windows VM and get into the same issue, try using a Unix terminal (screen command) directly from the MAC, that is even more convenient because the serial driver is a tty, which allows easily to script the simulation of frames coming from a sensor box.

                        For this just load the program using workshop, then stop the VM (just pause it, saving its state), and then use a Mac terminal window!

                        This requires installing the Mac CP210x driver.

                        ​​​​​​​Sorry for making you scratch you head

                        Comment


                        • #13
                          Hi,


                          Honestly speaking, I thought the issue was mainly due to the incorrect code.
                          But I'm glad that you were able to sort it out.
                          Thank you for your inputs. It would be very useful to other users who might encounter the same issue as yours.

                          Kindest regards,
                          Vince_4D

                          Comment


                          • #14
                            I tried everything (didn't post everything). None worked, including your code posted above.

                            With the Mac terminal, all original code works, including one posted at top of this post. There is an issue with terminal in VM (at least with my VM configuration with terminal).

                            I guess this has to do with how USB drivers are bridged from Mac to Windows.

                            Last thing: this is mandatory to pause the VM, so that MacOS claims back the serial acces (as soon as the VM is stopped you see the serial TTY appearing)
                            Last edited by gazefis; 15th February 2019, 12:41 PM.

                            Comment


                            • #15
                              Hi,

                              May I ask what Virtual Machine you are using?

                              Vince_4D

                              Comment

                              Working...
                              X