13 Replies Latest reply on Sep 23, 2020 12:31 AM by RoRo_4659551

    Terminal Support Component Library

    LePo_1062026

      To all,

       

      I've enhanced some of my previously submitted code shares (Terminal Component - Simplifies UART or USBUART communication and GetString() function that supports input character filtering.  Includes menu-driven commands. ).

       

      I've now expanded these previous submits and placed them in a Component Library that can be easily shared with all your projects and with other users.

       

      Here is a list of the components in the library:

      • Term - Terminal (UART) replacement that can be configured as UART or USBUART types.
      • String_Funcs - This is an enhancement of the GetString() function.  It is easier to use.
      • MenuCmds - This feature was included in the GetString demo code I shared earlier.  It is now a component with some improvements.

       

      With each of the Components, I have include at least one demo project for each component to illustrate how these components can be used.

      I've also included datasheets for the Components, the demo projects and a instructional on how to install a library/component to be shared across all your projects.

       

      All the components have the source code included for educational purposes.  If you know how to write component code, you can modify it.

       

      The components String_Funcs and MenuCmds are designed to work with ANY PSoC. (They are mostly library functions.)

       

      The Term component currently only works with the PSoC5.

       

      I hope everyone who download's this component will find it useful.

       

      Len

       

      Message was edited by: Len Update: Added PSoC6 and PSoC4 demo code examples.

       

      Message was edited by: Len  Update: Added two more PSoC4 demo code examples. Both using the SCB_UART component and one of them with a Bootladable (-049 kit).

        • 1. Re: Terminal Support Component Library
          EktaN_26

          Hello Len,

           

          Thank you for providing Terminal Support Component Library.

          The datasheet provided with all the three components are detailed.

          They contain all the information necessary to use the components.

          I appreciate your valuable input on this.

           

          Thanks and Regards

          Ekta

          • 2. Re: Terminal Support Component Library
            LePo_1062026

            Ekta,

             

            Thank you for your commendation.  I want to help out the PSoC community by providing some tools to make using the PSoC easier.

             

            I have used both MenuCmds and String_Funcs in nearly all my projects.  It makes creating a user interface much faster and using the help commands of '?' and 'h' make it easier not to have to remember what each command is.

             

            Len

            • 3. Re: Terminal Support Component Library
              LePo_1062026

              To all,

               

              Attached is a ModusToolbox (MTB) version of the String_Funcs_Demo.  (It uses the String_Funcs and MenuCmds components)

               

              Import the project into a MTB workspace.

               

              It has six BSP build targets:

              • CY8CPROTO-062-4343W
              • CY8CPROTO-062S3-4343W
              • CY8CKIT-062-WiFi-BT
              • CY8CKIT-062-BLE
              • CY8CPROTO-063-BLE
              • CY8CKIT-062S2-43012

              Chose the one that matches your Kit.

               

              Len

              • 4. Re: Terminal Support Component Library
                RoRo_4659551

                Hi Len,

                 

                Thank you very much for these libraries.

                 

                I am designing a DAQ board using the PSoC CY8C5467AXI-LP108.

                I have designed both USB2.0 and RS232 connectors for UART communication [USB as virtual COM].

                 

                 

                According to Term_v2_2 datasheet UART and USBUART has the same Term_PutString command.

                How can i add an "if" function that checks which COM is open [USB or RS232] so i can proceed in accordance?

                 

                Thanks,

                Roy Roif

                • 5. Re: Terminal Support Component Library
                  LePo_1062026

                  Roy,

                   

                  Thank you for your post and your excellent question!

                   

                  According to Term_v2_2 datasheet UART and USBUART has the same Term_PutString command.

                  How can i add an "if" function that checks which COM is open [USB or RS232] so i can proceed in accordance?

                  Here's the dilemma:

                  The Term component was intended to simplify standard "old-school" serial comm using UART-style API calls even if you chose the USBUART.  This is why the UART API calls don't have an inherent "Hey.  Are you there and awake?" function call.

                   

                  Traditionally the "old-school" serial comm doesn't normally directly validate if the other end of the comm chain is up and running.  At best, it indirectly validates the operation of the other side.  Traditionally, the transmitting sides just dumps the data out on the line HOPING the other side receives it.

                   

                  Here are a few ways of the indirectly providing a kind of flow-control:

                  • The use of HW signals of DTR (Data Terminal Ready [terminals])  and DCE (Data Communication Equipment ready [Modems].
                  • The use of HW signals RTS (Ready To Send) and CTS (Clear To Send) for data rate control.
                  • If remote echo is turned at the Rx-end, the Tx-end can readback the Rx which should be a perfect copy of what was sent.
                  • A more complicated structure is to packetize the data (limited direct string transfer) that allows a ACK/NACK (Acknowledge/No Acknowledge) return packet for every packet sent.

                  As listed above, there is no ONE standardized method to verify the other comm end is open and ready to receive data.  This can be considered an advantage in some applications.

                  For example, imagine your application uses the comm port as a debugging dump (mostly Tx operations).  You can power up your application and dump debug data to an unopened terminal without waiting for the terminal to be open.

                   

                  I use this condition to my advantage.  I've created a number of applications that dumps info to a PC terminal (when open) and accepts PC terminal commands (MenuCmds component).  I can turn on the PC terminal at any time without adversely affecting the running embedded application.  I can initiate a long testing phase of the application with the PC terminal then close the PC terminal program.  Days later, I can open the PC Terminal and monitor the current results of the running embedded application.

                   

                  The USBUART on the other hand does have an official standard for determining if the other end (PC terminal) is up and running.

                   

                  If you use the Term component and chose the USBUART as the port type, I provide a function that monitors if the other end is open and running.  It also supports BLOCKing and NON-BLOCKing operation.

                  /*--------------------------------------------------------------------------------*/
                  //_Bool USBUART_IsTxReady(_Bool allow_blocking)
                  // This prevents a lockup condition if the USB is unplugged or if the host-side has a closed port.
                  // The SysTick Timer must be enabled to detect that the USB is unplugged or the host port is not open.
                  //
                  // Parameters:
                  // allow_blocking = Boolean to determine if the function waits (blocking) or doesn't (non-blocking).
                  // This can be used as a blocking test function or a non-blocking implementation.  Non-blocking is useful for RTOSes
                  //
                  // Returns:
                  // TRUE = port ready to accept new data.
                  // FALSE = port unplugged or failed.  Do not send new data.
                  //---------------------------------------------------------
                  

                  This only applies to the USBUART.  If you chose the UART port type, the results are unknown.

                   

                  I'm open to create a new Term V2.3 with support of end-point validation for both the USBUART (already present) and UART.  We can give it a common API function call name.

                   

                  Propose something.

                   

                  Len

                  1 of 1 people found this helpful
                  • 6. Re: Terminal Support Component Library
                    RoRo_4659551

                    Hi Len,

                     

                    Yes if you can it will be very helpful - same as the USBUART monitor function.

                     

                    In addition, i want the user to press the "ENTER" keyboard after writing a command in order to receive the feedback [currently i just sent back the command itself but it will be the desired analog input value].

                    How do i define the ENTER keyboard in my code? i tried '\n' but for some reason its not working.

                     

                    This is my current debugging code:

                     

                    int main(void)

                    {

                    char buffer[100];

                     

                     

                        CyGlobalIntEnable; /* Enable global interrupts. */

                    Term_Start();

                        /* Place your initialization/startup code here (e.g. MyInst_Start()) */

                    CySysTickStart();

                    CySysTickSetCallback(0,&isr_systick_0);

                       

                        for(;;)

                        {

                    char c;

                        char enter;

                        int r=0;

                        int t=10;

                        int i=0;

                           

                            for(r=0; r<101;r++)

                            {

                            buffer[r]=0;

                            }

                     

                     

                            while(t>0)

                            //while(Term_GetChar()!='\n')

                            {

                                if((c=Term_GetChar())!='\0')

                                {

                                    PIN_LED_BLUE_Write(1);

                                    //CyDelay(100);

                                    buffer[i]=c;

                                    i++;

                                    t--;

                                    Term_PutChar(c);

                                    Term_PutString("");

                                    c='\0';

                                    PIN_LED_BLUE_Write(0);

                                    //CyDelay(100);

                                }

                            }

                            while((enter=Term_GetChar())!='\n');                     /*having problems with this command*/

                            PIN_LED_BLUE_Write(1);

                            //CyDelay(100);

                            Term_PutString("\r\n");

                            //Term_PutString("TX:\r\n");

                            Term_PutString(buffer);

                            Term_PutString("\r\n");

                            PIN_LED_BLUE_Write(0);

                         }

                    }

                    • 7. Re: Terminal Support Component Library
                      LePo_1062026

                      Roy,

                       

                      The USBUART version is easy and completed in the function USBUART_IsTxReady().  There is NO similar standard for UART serial.

                      Hence the request from you or others to propose what to use for the UART to detect end-to-end connection.

                      Until I get a consensus for a good solution, I will hold on a new Term version.

                       

                      About detecting the ENTER key:   Here is an excerpt of a webpage about ENTER character(s) on different systems.

                      • \r represents a line break on old Macs (OS 9 and before)
                      • \n represents a line break on UNIX systems (OS X, Linux)
                      • \r\n represents a line break on Windows.

                       

                      The real issue is dependent on the Terminal program you're using.

                       

                      The same way that I use is I look for a '\n' or a '\r' to cover ENTER on all systems.

                       

                      Len

                      • 8. Re: Terminal Support Component Library
                        RoRo_4659551

                        Hi Len,

                         

                        Yes i tried to use '\n' in my code but for some reason its not working [I am using windows].

                        Any idea why its not working?

                         

                        Thanks,

                        Roy Roif

                        • 9. Re: Terminal Support Component Library
                          LePo_1062026

                          Roy,

                           

                          As I indicated, the real question to ask: What is the terminal program passing to the serial port when the ENTER key is pressed?

                           

                          It's possible that the ENTER results in '\r' instead of '\n'.  Try looking for '\r'.

                           

                          Len

                          • 10. Re: Terminal Support Component Library
                            RoRo_4659551

                            Hi Len,

                             

                            I have modified the "Term_Demo" project and changed the "int maid (void)" according to the code i sent above.

                             

                            The "TopDesign" and the pins are configured the same as in "Term_Demo".

                             

                            I want the user to type a command, for example:

                            royroif123

                            after the user press "ENTER" key the command will be sent.

                            after that the user will receive the string on the screen.

                            [currently for debugging process, afterwards i will send the user the required information for every command].

                             

                            Thanks,

                            Roy Roif

                            • 11. Re: Terminal Support Component Library
                              RoRo_4659551

                              Another question, where can i find the IsTxReady function?

                               

                              Thanks,

                              Roy Roif.

                              • 12. Re: Terminal Support Component Library
                                LePo_1062026

                                Roy,

                                 

                                You named the Term component an instance_name in TopDesign.   Use that instance_name.c

                                 

                                Another way to find it is to search for "IsTxReady" with Find.

                                 

                                Len

                                1 of 1 people found this helpful
                                • 13. Re: Terminal Support Component Library
                                  RoRo_4659551

                                  Found it, thank you very much