View previous topic :: View next topic |
Author |
Message |
jujoab
Joined: 05 Aug 2017 Posts: 41 Location: brazil
|
I am facing a problem with printf and control characters |
Posted: Fri Jan 05, 2018 6:16 pm |
|
|
I am trying to use fprint from prototype to PC via serial cable.
Considering the control characters used, the output is as follows.
My source (simplified):
Code: |
#use rs232(baud=9600,parity=N,xmit=PIN_c5,rcv=PIN_a2,bits=8,stream=PORT1)
void test()
{
printf( "Hello World"); //text plus integer8 (Byte)
printf( "\n\r");
putc('\r');
putc('\r');
putc('\n') ;
putc('\n') ;
printf("testAAA") ;
printf("\n \r1234 ") ;
putc('\r');
putc('\n') ;
printf("5678") ;
putc('\r');
putc('\n') ;
printf("\n\rtest JJBBBBa ") ;
putc('\r');
putc('\n') ;
)
|
The putc were added for test, as the control char within the printf did not work.
I have different outputs depending if hiperterminal or YAT is used for display, but in both the control characters are not working as expected.
------------------------------------
with YAT I get:
Hello World<LF><CR><CR>
<LF><LF><CR>testAAA<LF><CR>1234
5678
<LF><CR>---test JJBBBBa
-------------------------------------------------------------
no hiper terminal have
Hello World
testAAA
1234
5678
---test JJBBBBa
(With many blank lines in between, that appeared only when I do a copy to clipboard, if not the screen lock as above).
-------------------------------------------------------
Any hint where should I look, I am kind of lost.
Thanks
jujo |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Fri Jan 05, 2018 7:38 pm |
|
|
Every 'terminal program' has options for how 'control characters' like \r and \n are to be used. Some, for example, will automatically generate a new line if a carriage return is seen.
I use RealTerm, have for years as it can be setup to show the 'raw data' coming in as you can program it to handle CR, LF as you want it to.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 05, 2018 8:48 pm |
|
|
Quote: | Any hint where should I look, I am kind of lost. |
Post an example of what you expected to see, if it worked correctly. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Sat Jan 06, 2018 6:22 am |
|
|
I also notice the '---' that appear in your 'output' but are NOT in your 'code'...
that's a huge concern !
Jay |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19382
|
|
Posted: Sat Jan 06, 2018 9:03 am |
|
|
Take a deep breath.
If you look at your YAT output:
Code: |
Hello World<LF><CR><CR>
<LF><LF><CR>testAAA<LF><CR>1
|
and compare with your code:
Code: |
printf( "Hello World"); //text plus integer8 (Byte)
printf( "\n\r");
putc('\r');
putc('\r');
putc('\n') ;
putc('\n') ;
printf("testAAA") ;
printf("\n \r1
|
Every \r (carriage return), is being displayed (as <CR>), and every \n (line feed) is also appearing (as <LF>).
You obviously have this setup to display controls rather than act on them, hence the difference to Hyperterm (Advanced terminal settings - the control characters setting for YAT).
The Hyperterm is giving what would be expected (\n moves it to the next line, \r moves back to the left hand column).
The only 'fault' seems to be in the extra --- already noted by Temtronic.
As PCM_programmer says, what do you expect the output to be?. |
|
![](templates/subSilver/images/spacer.gif) |
jujoab
Joined: 05 Aug 2017 Posts: 41 Location: brazil
|
|
Posted: Sat Jan 06, 2018 10:39 am |
|
|
hi
I think I detected the problem, as being the "usb to serial adapter". I will be able to test sometime next week when the new and different brand adapter will arrive. So i think any further work on subject is nor justiofied until such test is done.
Meanwhile, let me answer some of the questions.
If I change the EOL sequence on the YAT to none, i get following:
Hello World<LF><CR><CR><CR><LF><LF><LF><CR>testAAA<LF><CR>1234 <CR><LF>5678<CR><LF><LF><CR>---test JJBBBBa <CR><LF>Hello World<LF><CR><CR><CR><LF><LF>
Instead of <cr><lf> as the default setup which prints:
Hello World<LF><CR><CR>
<LF><LF><CR>testAAA<LF><CR>1234
5678
<LF><CR>---test JJBBBBa
so I conclude the setup is ok.
I have same setup on the hyper terminal.
----------------------------------------------------------------------------
On the question of what I expect to see, i go back to original test:
Code: |
void test11 ()
{
printf( "\n\rHello World"); //text plus integer8 (Byte)
printf("\n\rtestAAA") ;
printf("\n\r1234 ") ;
printf("\n\r5678") ;
printf("\n\r---test JJBBBBa ") ;
} |
where I expect to see
Hello World
testAAA
1234
5678---test JJBBBBa
but instead I get
<LF><CR>Hello World<LF><CR>testAAA<LF><CR>1234 <LF><CR>5678<LF><CR>---test JJBBBBa
thanks a lot to all
jujoab |
|
![](templates/subSilver/images/spacer.gif) |
jujoab
Joined: 05 Aug 2017 Posts: 41 Location: brazil
|
|
Posted: Sat Jan 06, 2018 10:43 am |
|
|
Forgot to ask.
Do you know a simple way to send the messages from the pic to the PC using bluetooth or wifi ? Like having a terminal program at the PC able to display whatever is sent from the PIC ?
thanks
jujoab |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Sat Jan 06, 2018 11:03 am |
|
|
<cr> <lf> text
means you've got the terminal program configured to SHOW control characters. You'll have to see the options for display for your terminal program and turn off or disable or whatever they call it to NOT display control characters ( or unprintable characters).
as for sending data via wireless to a PC screen. how depends on hardware for the PIC, remember most peripherals will be 3 volts...
as for a PC terminal program, any high level language will work QB45, C++,DELPHI,etc. THAT depends upon you. I use DELPHI for the PC side of projects as it produces tight, transportable code INDEPENDENT of Windows and DLLs !
Jay |
|
![](templates/subSilver/images/spacer.gif) |
jujoab
Joined: 05 Aug 2017 Posts: 41 Location: brazil
|
|
Posted: Sat Jan 06, 2018 11:48 am |
|
|
temtronic wrote: | <cr> <lf> text
means you've got the terminal program configured to SHOW control characters. You'll have to see the options for display for your terminal program and turn off or disable or whatever they call it to NOT display control characters ( or unprintable characters).
as for sending data via wireless to a PC screen. how depends on hardware for the PIC, remember most peripherals will be 3 volts...
as for a PC terminal program, any high level language will work QB45, C++,DELPHI,etc. THAT depends upon you. I use DELPHI for the PC side of projects as it produces tight, transportable code INDEPENDENT of Windows and DLLs !
Jay |
thanks
i have tried booth on the YAT:
quote
f I change the EOL sequence on the YAT to none, i get following:
Hello World<LF><CR><CR><CR><LF><LF><LF><CR>testAAA<LF><CR>1234 <CR><LF>5678<CR><LF><LF><CR>---test JJBBBBa <CR><LF>Hello World<LF><CR><CR><CR><LF><LF>
Instead of <cr><lf> as the default setup which prints:
Hello World<LF><CR><CR>
<LF><LF><CR>testAAA<LF><CR>1234
5678
<LF><CR>---test JJBBBBa
so I conclude the setup is ok.
thanks
jujoab |
|
![](templates/subSilver/images/spacer.gif) |
jujoab
Joined: 05 Aug 2017 Posts: 41 Location: brazil
|
|
Posted: Tue Jan 09, 2018 10:38 pm |
|
|
Thanks to all.
I replaced the usb to serial converter and problem went away.
jujoab |
|
![](templates/subSilver/images/spacer.gif) |
|