Subject: Re: Serial port hangs unless I run Hyperterminal?
From: andyburgess <[email-masked]>
To: Eric Blake <[email-masked]>
Cc: [email-masked]
Date: Mon, 23 Jan 2006 20:30:45 +0000 (GMT)

Eric,

Thanx for your quick reply!

> Code snippets?  
OK - open port function

following function called with
 
serial = open_port("COM1");
-----------------------------
int open_port(char *port)
{
	int fd = 0;

	fd = open(port, O_RDWR | O_NOCTTY );
	return (fd);
}	
-----------------------------
// writing to port (I don't use tcgetattr or tcsetattr ATM).
int res;
res = write(fd, cmd, strlen(cmd));
if (res < 1)
{   printf("write failed\n");
    return (-1);
}
-----------------------------
//read feedback
char buf[350];
res = read(fd, buf, 1254);
-----------------------------

> Are you using the correct port?  
I'm not 100% sure - perhaps you can tell me. I'm using COM1 as encoded in
program snippet above. From what you say below - sounds like wrong one!

> More details would have
> been nice.  Cygwin serial port setting commands emulate Linux, so you
> should use on "/dev/ttyS0" and not on "COM1".
Right - so from the above I should do:

        serial = open_port("/dev/ttyS0"); 

instead?

> Also, from the command line, you can use "stty -f /dev/ttyS0" to read and
> set the settings of your port, rather than relying on hyperterm.
Right did that - though it seemed to be capital F parameter on my Cygwin.
Hope it's the same setting! The reply was (after Hyperterminal had been run,
and program was running OK):

speed 0 baud; line = 0;
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof =
<undef>;
swtch = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>;
lnext = <undef>; flush = <undef>; min = 0; time = 0;
-cread
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

I presume the "-" prefixed settings mean "off", and the hashes -
continuations? Is there anything there a cause for concern - they all look
pretty uninitialised to me! Nice to see all those settings available to be
viewed outside of tcgetattr - I'd wondered how I could do that.

If I used "/dev/ttyS0" instead of COM1, would the tcget/setattr's work? Does
it mean that currently I'm somehow getting some settings passed from the
Win32 environment for my current COM1 settings? If so, is there a way I can
interrogate these to set up for use with correct ttyS0?

Apologies for not understanding /dev/ttyS0. I've done fair amounts of stuff
on DOS, and a fair bit of unix (scripts, but rusty), but until recently had
never programmed serial ports on any POSIX or DOS system, or even used any
Unix "device" myself!

I presume COM2, COM3 etc would be mapped to ttyS1, ttyS2 etc?

> - --
> Life is short - so eat dessert first!
Sounds like a 'top' idea!

Cheers for your help!
Andy

-- 
 __  __  __  __      __ ___   _____________________________________________
|__||__)/ __/  \|\ ||_   |   /
|  ||  \\__/\__/| \||__  |  /...Internet access for all Acorn RISC machines
___________________________/ [email-masked]

--
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/