public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* printf goes to serial port?
@ 2008-12-19 18:02 Alex Martin
  2008-12-19 19:31 ` Gary R. Van Sickle
  0 siblings, 1 reply; 12+ messages in thread
From: Alex Martin @ 2008-12-19 18:02 UTC (permalink / raw)
  To: cygwin

Hello,

I have a cygwin environment, running some software I am writing to talk 
to some serial devices.

Somehow, trying to debug why I could not see printf output to console, I 
ran a serial port sniffer and voila all of my printf commands are 
writing on the serial port.

Any idea how to fix this?

Thanks,
Alex Martin

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: printf goes to serial port?
  2008-12-19 18:02 printf goes to serial port? Alex Martin
@ 2008-12-19 19:31 ` Gary R. Van Sickle
  2008-12-19 19:35   ` Matt Wozniski
  2008-12-19 20:19   ` Alex Martin
  0 siblings, 2 replies; 12+ messages in thread
From: Gary R. Van Sickle @ 2008-12-19 19:31 UTC (permalink / raw)
  To: cygwin

> From: Alex Martin
> 
> Hello,
> 
> I have a cygwin environment, running some software I am 
> writing to talk to some serial devices.
> 
> Somehow, trying to debug why I could not see printf output to 
> console, I ran a serial port sniffer and voila all of my 
> printf commands are writing on the serial port.
> 

I can't say that it would cross my mind to look for my missing printf output
on a serial port, even if I was using a serial port in other parts of the
program to talk to something.  Whatever it was that gave you the hunch to do
that is probably at the core of your problem.

> Any idea how to fix this?
> 

Well, no, not really, since you've given very few details to go on.  I'd
SWAG that you've somewhere, somehow, redirected stdout to the serial port
you're trying to talk to those devices on.

> Thanks,
> Alex Martin
> 

-- 
Gary R. Van Sickle


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: printf goes to serial port?
  2008-12-19 19:31 ` Gary R. Van Sickle
@ 2008-12-19 19:35   ` Matt Wozniski
  2008-12-19 20:35     ` Alex Martin
  2008-12-19 20:19   ` Alex Martin
  1 sibling, 1 reply; 12+ messages in thread
From: Matt Wozniski @ 2008-12-19 19:35 UTC (permalink / raw)
  To: cygwin

On Fri, Dec 19, 2008 at 2:30 PM, Gary R. Van Sickle wrote:
>> From: Alex Martin
>>
>> Hello,
>>
>> I have a cygwin environment, running some software I am
>> writing to talk to some serial devices.
>>
>> Somehow, trying to debug why I could not see printf output to
>> console, I ran a serial port sniffer and voila all of my
>> printf commands are writing on the serial port.
>>
>
> I can't say that it would cross my mind to look for my missing printf output
> on a serial port, even if I was using a serial port in other parts of the
> program to talk to something.  Whatever it was that gave you the hunch to do
> that is probably at the core of your problem.

My slightly wild guess is that you do an open() on the serial device
without a controlling terminal and without passing the O_NOCTTY flag,
causing the serial device to become your controlling terminal.

~Matt

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: printf goes to serial port?
  2008-12-19 19:31 ` Gary R. Van Sickle
  2008-12-19 19:35   ` Matt Wozniski
@ 2008-12-19 20:19   ` Alex Martin
  2008-12-19 20:38     ` Gary R. Van Sickle
  1 sibling, 1 reply; 12+ messages in thread
From: Alex Martin @ 2008-12-19 20:19 UTC (permalink / raw)
  To: cygwin

Well, I was using a port monitor to debug some of the traffic between my 
serial device, and my software, when I noticed the output accidentally.

I am not sure when the behavior started. It used to work fine, I was 
using printf to debug things, then I turned off all of those printf 
statements, and continued development on the gui side (fox toolkit) of 
my application, and then had to go in and modify my low level serial 
class and was trying to get my printf debug output again, to no avail.

I have updated cygwin a few times, otherwise I cannot think of anything 
specific.

What other details can I provide?

Alex Martin

Gary R. Van Sickle wrote:
>> From: Alex Martin
>>
>> Hello,
>>
>> I have a cygwin environment, running some software I am 
>> writing to talk to some serial devices.
>>
>> Somehow, trying to debug why I could not see printf output to 
>> console, I ran a serial port sniffer and voila all of my 
>> printf commands are writing on the serial port.
>>
> 
> I can't say that it would cross my mind to look for my missing printf output
> on a serial port, even if I was using a serial port in other parts of the
> program to talk to something.  Whatever it was that gave you the hunch to do
> that is probably at the core of your problem.
> 
>> Any idea how to fix this?
>>
> 
> Well, no, not really, since you've given very few details to go on.  I'd
> SWAG that you've somewhere, somehow, redirected stdout to the serial port
> you're trying to talk to those devices on.
> 
>> Thanks,
>> Alex Martin
>>
> 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: printf goes to serial port?
  2008-12-19 19:35   ` Matt Wozniski
@ 2008-12-19 20:35     ` Alex Martin
  0 siblings, 0 replies; 12+ messages in thread
From: Alex Martin @ 2008-12-19 20:35 UTC (permalink / raw)
  To: cygwin


Matt Wozniski wrote:
> On Fri, Dec 19, 2008 at 2:30 PM, Gary R. Van Sickle wrote:
>>> From: Alex Martin
>>>
>>> Hello,
>>>
>>> I have a cygwin environment, running some software I am
>>> writing to talk to some serial devices.
>>>
>>> Somehow, trying to debug why I could not see printf output to
>>> console, I ran a serial port sniffer and voila all of my
>>> printf commands are writing on the serial port.
>>>
>> I can't say that it would cross my mind to look for my missing printf output
>> on a serial port, even if I was using a serial port in other parts of the
>> program to talk to something.  Whatever it was that gave you the hunch to do
>> that is probably at the core of your problem.
> 
> My slightly wild guess is that you do an open() on the serial device
> without a controlling terminal and without passing the O_NOCTTY flag,
> causing the serial device to become your controlling terminal.
> 
> ~Matt
> 
Hello,

I do this:
//snip
     if (port == 1) {
        fd = ::open("/dev/ttyS0", O_NONBLOCK | O_RDWR | O_NOCTTY );
     }
//snip

Can you point me to some info about "controlling terminal"? I have been 
living in a strict c++/cygwin/fox-toolkit world and I am not familiar 
with terminals and things.

If I try to run my .exe from a cygwin prompt, it doesnt start up. If I 
run my exe from a cmd.exe window, it starts up my app but then returns 
to a prompt instead of staying open to catch printfs and such.

Any ideas?

Thanks for your help.

Alex Martin

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: printf goes to serial port?
  2008-12-19 20:19   ` Alex Martin
@ 2008-12-19 20:38     ` Gary R. Van Sickle
  2008-12-19 21:01       ` Alex Martin
  0 siblings, 1 reply; 12+ messages in thread
From: Gary R. Van Sickle @ 2008-12-19 20:38 UTC (permalink / raw)
  To: cygwin

> From:  Alex Martin
> 
> Well, I was using a port monitor to debug some of the traffic 
> between my serial device, and my software, when I noticed the 
> output accidentally.
> 
> I am not sure when the behavior started. It used to work 
> fine, I was using printf to debug things, then I turned off 
> all of those printf statements, and continued development on 
> the gui side (fox toolkit) of my application, and then had to 
> go in and modify my low level serial class and was trying to 
> get my printf debug output again, to no avail.
> 
> I have updated cygwin a few times, otherwise I cannot think 
> of anything specific.
> 
> What other details can I provide?
> 

Well, whatever details you have.  I'm still in "pull mode" here, which isn't
conducive to problem-solving.  So far I've been able to gather:

1.  You are developing some sort of app that communicates over a serial port
to some other device.
2.  You "have a cygwin environment".
3.  The app has a GUI, using something called "fox toolkit" (with which I am
not familiar).
4.  You had debug printf()s that used to work, then a bunch of stuff
changed, and now they work differently.

A few gaps that need filling before anything better than SWAGs can come your
way:
- Is this app a Cygwin app, or is Cygwin involved only perhiperally (e.g.
you're using Cygwin make to run the MinGW toolchain), or is Cygwin not
directly involved at all and you're saying "My non-Cygwin-related app was
working fine, I changed a bunch of stuff in the app and also upgraded
Cygwin, and now the app is broke and I'm thinking Cygwin could be to blame"?
- Since your app is a GUI app, where did you expect your printf()s to go?

> Alex Martin
> 

-- 
Gary R. Van Sickle
 
> Gary R. Van Sickle wrote:
> >> From: Alex Martin
> >>
> >> Hello,
> >>
> >> I have a cygwin environment, running some software I am writing to 
> >> talk to some serial devices.
> >>
> >> Somehow, trying to debug why I could not see printf output to 
> >> console, I ran a serial port sniffer and voila all of my printf 
> >> commands are writing on the serial port.
> >>
> > 
> > I can't say that it would cross my mind to look for my 
> missing printf 
> > output on a serial port, even if I was using a serial port in other 
> > parts of the program to talk to something.  Whatever it was 
> that gave 
> > you the hunch to do that is probably at the core of your problem.
> > 
> >> Any idea how to fix this?
> >>
> > 
> > Well, no, not really, since you've given very few details 
> to go on.  
> > I'd SWAG that you've somewhere, somehow, redirected stdout to the 
> > serial port you're trying to talk to those devices on.
> > 
> >> Thanks,
> >> Alex Martin
> >>
> > 
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Problem reports:       http://cygwin.com/problems.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
> 


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: printf goes to serial port?
  2008-12-19 20:38     ` Gary R. Van Sickle
@ 2008-12-19 21:01       ` Alex Martin
  2008-12-19 21:23         ` Gary R. Van Sickle
  2008-12-19 21:32         ` Larry Hall (Cygwin)
  0 siblings, 2 replies; 12+ messages in thread
From: Alex Martin @ 2008-12-19 21:01 UTC (permalink / raw)
  To: cygwin



Gary R. Van Sickle wrote:
>> From:  Alex Martin
>>
>> Well, I was using a port monitor to debug some of the traffic 
>> between my serial device, and my software, when I noticed the 
>> output accidentally.
>>
>> I am not sure when the behavior started. It used to work 
>> fine, I was using printf to debug things, then I turned off 
>> all of those printf statements, and continued development on 
>> the gui side (fox toolkit) of my application, and then had to 
>> go in and modify my low level serial class and was trying to 
>> get my printf debug output again, to no avail.
>>
>> I have updated cygwin a few times, otherwise I cannot think 
>> of anything specific.
>>
>> What other details can I provide?
>>
> 
> Well, whatever details you have.  I'm still in "pull mode" here, which isn't
> conducive to problem-solving.  So far I've been able to gather:
> 
> 1.  You are developing some sort of app that communicates over a serial port
> to some other device.
> 2.  You "have a cygwin environment".
> 3.  The app has a GUI, using something called "fox toolkit" (with which I am
> not familiar).
> 4.  You had debug printf()s that used to work, then a bunch of stuff
> changed, and now they work differently.
> 
> A few gaps that need filling before anything better than SWAGs can come your
> way:
> - Is this app a Cygwin app, 

No, it is a windows app.

I am using cygwin primarily because I get the /dev/ttyS* devices. I 
could not find info on how to talk to a serial port in the windows world 
without using "MFC" which I refuse to touch.

or is Cygwin involved only perhiperally (e.g.
> you're using Cygwin make to run the MinGW toolchain), 

No mingw. Using all of cygwin's make, g++, etc.

or is Cygwin not
> directly involved at all and you're saying "My non-Cygwin-related app was
> working fine, I changed a bunch of stuff in the app and also upgraded
> Cygwin, and now the app is broke and I'm thinking Cygwin could be to blame"?

I do not think the app is broken. Somehow stdout is going to the serial 
port, my code relating to file descriptors (a serialio class that 
provides functions like open, close, read, write, flush), opening and 
closing the devices, etc has never changed (that is, the code is the 
same code since back when printf worked). Other code has changed, that 
is, the gui layout, function flow, etc.

> - Since your app is a GUI app, where did you expect your printf()s to go?

Well, someone taught me to use cygwin in this manner, and I have been 
doing so for a long time, that is, I can use a cygwin window to invoke 
my windows app, and the cygwin console would catch printfs (stdout 
chatter), so you can use it as a debug console.

> 
>> Alex Martin
>>
> 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: printf goes to serial port?
  2008-12-19 21:01       ` Alex Martin
@ 2008-12-19 21:23         ` Gary R. Van Sickle
  2008-12-19 21:32         ` Larry Hall (Cygwin)
  1 sibling, 0 replies; 12+ messages in thread
From: Gary R. Van Sickle @ 2008-12-19 21:23 UTC (permalink / raw)
  To: cygwin

> From: Alex Martin
> Gary R. Van Sickle wrote:
> >> From:  Alex Martin
> >>
> >> Well, I was using a port monitor to debug some of the 
> traffic between 
> >> my serial device, and my software, when I noticed the output 
> >> accidentally.
> >>
> >> I am not sure when the behavior started. It used to work 
> fine, I was 
> >> using printf to debug things, then I turned off all of 
> those printf 
> >> statements, and continued development on the gui side (fox 
> toolkit) 
> >> of my application, and then had to go in and modify my low level 
> >> serial class and was trying to get my printf debug output 
> again, to 
> >> no avail.
> >>
> >> I have updated cygwin a few times, otherwise I cannot think of 
> >> anything specific.
> >>
> >> What other details can I provide?
> >>
> > 
> > Well, whatever details you have.  I'm still in "pull mode" 
> here, which 
> > isn't conducive to problem-solving.  So far I've been able 
> to gather:
> > 
> > 1.  You are developing some sort of app that communicates over a 
> > serial port to some other device.
> > 2.  You "have a cygwin environment".
> > 3.  The app has a GUI, using something called "fox toolkit" (with 
> > which I am not familiar).
> > 4.  You had debug printf()s that used to work, then a bunch 
> of stuff 
> > changed, and now they work differently.
> > 
> > A few gaps that need filling before anything better than SWAGs can 
> > come your
> > way:
> > - Is this app a Cygwin app,
> 
> No, it is a windows app.
> 
> I am using cygwin primarily because I get the /dev/ttyS* 
> devices.

...ok, so it's a Cygwin app.  You won't have /dev/anything otherwise.

> I could not find info on how to talk to a serial 
> port in the windows world without using "MFC" which I refuse to touch.
> 

I... Um, you can most certainly talk to serial ports under Windows without
using MFC (is MFC even still around?  I thought it was all ".NET" this and
"ATL" that nowadays.  I must not be getting as old as I thought I was).
Search MSDN for... Well, here:
http://msdn.microsoft.com/en-us/library/ms810467.aspx

> or is Cygwin involved only perhiperally (e.g.
> > you're using Cygwin make to run the MinGW toolchain),
> 
> No mingw. Using all of cygwin's make, g++, etc.
> 

Ok, again, that's a Cygwin app.  You're linking with the Cygwin DLL.

> or is Cygwin not
> > directly involved at all and you're saying "My 
> non-Cygwin-related app 
> > was working fine, I changed a bunch of stuff in the app and also 
> > upgraded Cygwin, and now the app is broke and I'm thinking 
> Cygwin could be to blame"?
> 
> I do not think the app is broken.

I never do either, until I find out where I broke it. ;-)

> Somehow stdout is going to 
> the serial port, my code relating to file descriptors (a 
> serialio class that provides functions like open, close, 
> read, write, flush), opening and closing the devices, etc has 
> never changed (that is, the code is the same code since back 
> when printf worked). Other code has changed, that is, the gui 
> layout, function flow, etc.
> 
> > - Since your app is a GUI app, where did you expect your 
> printf()s to go?
> 
> Well, someone taught me to use cygwin in this manner, and I 
> have been doing so for a long time, that is, I can use a 
> cygwin window to invoke my windows app, and the cygwin 
> console would catch printfs (stdout chatter), so you can use 
> it as a debug console.

Hmm, well, maybe you have uncovered a Cygwin bug, or a deliberate change in
Cygwin behavior.  Next step: Which Cygwin DLL version behaved as above, and
which version now is sending that info to the serial port?  Make sure to use
the same app (which you have assured me is not broken ;-)) when you test
this; rule #1 is to change only one thing at a time so you can rule it out
without the confounding factors of other things changing on you.

-- 
Gary R. Van Sickle


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: printf goes to serial port?
  2008-12-19 21:01       ` Alex Martin
  2008-12-19 21:23         ` Gary R. Van Sickle
@ 2008-12-19 21:32         ` Larry Hall (Cygwin)
  1 sibling, 0 replies; 12+ messages in thread
From: Larry Hall (Cygwin) @ 2008-12-19 21:32 UTC (permalink / raw)
  To: cygwin

Alex Martin wrote:
> 
> 
> Gary R. Van Sickle wrote:

<snip>

>> A few gaps that need filling before anything better than SWAGs can 
>> come your
>> way:
>> - Is this app a Cygwin app, 
> 
> No, it is a windows app.
> 
> I am using cygwin primarily because I get the /dev/ttyS* devices. 

If you're using /dev/ttyS*, then you're using cygwin1.dll.  That makes
it a Cygwin app.  You're not going to get POSIX/Linux support from a
vanilla Win32 environment.  I feel obliged to mention that because of
you're using the Cygwin DLL, whatever you're working on needs to comply
with the Cygwin licensing scheme if you're distributing it in any way.

> or is Cygwin involved only perhiperally (e.g.
>> you're using Cygwin make to run the MinGW toolchain), 
> 
> No mingw. Using all of cygwin's make, g++, etc.
> 
> or is Cygwin not
>> directly involved at all and you're saying "My non-Cygwin-related app was
>> working fine, I changed a bunch of stuff in the app and also upgraded
>> Cygwin, and now the app is broke and I'm thinking Cygwin could be to 
>> blame"?
> 
> I do not think the app is broken. Somehow stdout is going to the serial 
> port, my code relating to file descriptors (a serialio class that 
> provides functions like open, close, read, write, flush), opening and 
> closing the devices, etc has never changed (that is, the code is the 
> same code since back when printf worked). Other code has changed, that 
> is, the gui layout, function flow, etc.

Given the description so far, this is starting to sound like a case of
mixed CRTs, Cygwin's and MS's.  Only one can be in charge of stdin/stdout/
stderr if you expect to get sane results.  And calls to CRT I/O functions
have to occur entirely in one or the other to see consistent results.

>> - Since your app is a GUI app, where did you expect your printf()s to go?
> 
> Well, someone taught me to use cygwin in this manner, and I have been 
> doing so for a long time, that is, I can use a cygwin window to invoke 
> my windows app, and the cygwin console would catch printfs (stdout 
> chatter), so you can use it as a debug console.

That's not guaranteed.  It really sounds to me like you just want a
way to look at some messages when they are triggered.  You'd be
better off with something like "OutputDebugString()" and DebugView
<http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx>
if the application isn't a console app.  And even if it is, this
could go a long way towards unraveling any mixing and matching
that you may have inadvertently done with I/O and CRTs.

-- 
Larry Hall                              http://www.rfk.com
RFK Partners, Inc.                      (508) 893-9779 - RFK Office
216 Dalton Rd.                          (508) 893-9889 - FAX
Holliston, MA 01746

_____________________________________________________________________

A: Yes.
 > Q: Are you sure?
 >> A: Because it reverses the logical flow of conversation.
 >>> Q: Why is top posting annoying in email?

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: printf goes to serial port?
  2009-01-04 21:30 ` Dave Korn
@ 2009-01-04 21:45   ` Bob van Loosen
  0 siblings, 0 replies; 12+ messages in thread
From: Bob van Loosen @ 2009-01-04 21:45 UTC (permalink / raw)
  To: cygwin

Dave Korn wrote:
>   Well... that requires editing every single printf in the whole 
> program, no?
>
>   It might be easier to just at the start of main() open the first 
> three file
> descriptors, so that 0, 1 and 2 are allocated.  If you open 0 from 
> /dev/null
> in read mode and open 1 and 2 for write to /dev/null, all your stdio 
> should
> behave sensibly.  Then if you decide you want the printfs after all, 
> you can
> just change the open to point to a real file and bingo!  Instant log 
> file!
>   
Here's an even better solution:

stdin = fopen("/dev/null", "r");
stdout = fopen("/dev/null", "w");
stderr = fopen("/dev/null", "w");

And then use fprintf on the respective file pointer, this ensures that 
any output will go to /dev/null, even if the file descriptors don't 
start at 0, which can happen (think library constructors).

Bob.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: printf goes to serial port?
  2009-01-04 19:22 Bob van Loosen
@ 2009-01-04 21:30 ` Dave Korn
  2009-01-04 21:45   ` Bob van Loosen
  0 siblings, 1 reply; 12+ messages in thread
From: Dave Korn @ 2009-01-04 21:30 UTC (permalink / raw)
  To: cygwin

Bob van Loosen wrote:
> Because of this, the app doesn't get the standard file descriptors for
> stdin, stdout and stderr, also when you open a file the file descriptors
> start at 0.
>
> So what happens is, my app opens a config file, which then becomes
> stdin, then it opens a serial port, which becomes stdout, causing all
> printf statements to go out the serial port.
> The solution is quite simple, just disable all printf statements for a
> cygwin build.

  Well... that requires editing every single printf in the whole program, no?

  It might be easier to just at the start of main() open the first three file
descriptors, so that 0, 1 and 2 are allocated.  If you open 0 from /dev/null
in read mode and open 1 and 2 for write to /dev/null, all your stdio should
behave sensibly.  Then if you decide you want the printfs after all, you can
just change the open to point to a real file and bingo!  Instant log file!

> I have no idea how to get console output when using the
> -mwindows flag, but I don't really need it.

  You probably need to call AllocConsole and open stdio channels to
CONIN$/CONOUT$, but that's off the top of my head and without looking it up.

    cheers,
      DaveK

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: printf goes to serial port?
@ 2009-01-04 19:22 Bob van Loosen
  2009-01-04 21:30 ` Dave Korn
  0 siblings, 1 reply; 12+ messages in thread
From: Bob van Loosen @ 2009-01-04 19:22 UTC (permalink / raw)
  To: cygwin

Hi, I was pointed to this discussion at the archives: 
http://www.cygwin.com/ml/cygwin/2008-12/msg00489.html

I have a similar problem with my app, all printf statements go out the 
serial port.
The problem is, I'm using the -mwindows flag to get a sort of "real" 
windows app, so no console output.
Because of this, the app doesn't get the standard file descriptors for 
stdin, stdout and stderr, also when you open a file the file descriptors 
start at 0.

So what happens is, my app opens a config file, which then becomes 
stdin, then it opens a serial port, which becomes stdout, causing all 
printf statements to go out the serial port.
The solution is quite simple, just disable all printf statements for a 
cygwin build. I have no idea how to get console output when using the 
-mwindows flag, but I don't really need it.

I didn't notice this at first because my homemade rs232 hardware expects 
0xFF and then 12 bytes (for 12 pwm channels) which is sent to it every 
16 ms or so, so any garbage sent to it basically gets ignored because 
the hardware waits for the 0xFF prefix.
However, some people use hardware that doesn't expect a prefix, so if it 
expects 9 bytes at a time for 9 pwm channels, and the data from the 
printf statements is sent out the serial port, the hardware gets out of 
sync.
This is a really bad design for a protocol, but there's a howto for the 
hardware on the net somewhere so a lot of people use it.

Bob.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-01-04 20:34 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-19 18:02 printf goes to serial port? Alex Martin
2008-12-19 19:31 ` Gary R. Van Sickle
2008-12-19 19:35   ` Matt Wozniski
2008-12-19 20:35     ` Alex Martin
2008-12-19 20:19   ` Alex Martin
2008-12-19 20:38     ` Gary R. Van Sickle
2008-12-19 21:01       ` Alex Martin
2008-12-19 21:23         ` Gary R. Van Sickle
2008-12-19 21:32         ` Larry Hall (Cygwin)
2009-01-04 19:22 Bob van Loosen
2009-01-04 21:30 ` Dave Korn
2009-01-04 21:45   ` Bob van Loosen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).