Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-11 Thread Jurjen Oskam
Stuart Henderson stu at spacehopper.org writes:

 
 On 2014-01-10, Jurjen Oskam jurjen at osk.am wrote:
  Philip Guenther guenther at gmail.com writes:
 
  Oh, you're running 5.4-stable?  I thought you were running -current
  and was worried there was another hang in there.  I'm now 99% sure
  you're hitting the one I fixed back in October.
 
 
  I'm sorry, but I don't know which hang you fixed in October. With this
  information, do you think it's the same hang?
 
 It's this one, which is in 5.4-stable updated after 2013/11/12
 http://ftp.openbsd.org/pub/OpenBSD/patches/5.4/common/003_vnode.patch

Hmm, I'm running -stable as provided by M:Tier, which should have that fix
in it:

OpenBSD 5.4 (GENERIC.MP) #1: Tue Nov 12 10:57:06 CET 2013
r...@binpatch-54-amd64.mtier.org:/home/jasper/binpatchng/work-binpatch54-
amd64/src/sys/arch/amd64/compile/GENERIC.MP

# pkg_info
binpatch54-amd64-kernel-2.0 Binary Patch for 003_vnode.patch
  [...]

It seems like this is a different issue then. What can I do to investigate
this further?

Regards,

Jurjen Oskam



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-10 Thread Jurjen Oskam
Philip Guenther guenther at gmail.com writes:

 
 On Thu, Jan 9, 2014 at 8:20 AM, Jurjen Oskam jurjen at osk.am wrote:
  OK, I've got it to work using a /dev/cua* device. I still have problems 
  with processes not exiting though. Since this machine has real com
  ports, I also made a cable that is attached to cua01 (no USB involved).
 ...
  Then when I kill it, I get this:
 
  $ kill 13670
  $ ps
PID TT  STAT   TIME COMMAND
  15727 p0  Is  0:00.01 -ksh (ksh)
  13444 p0  S+  0:00.02 kdump -l -T
  26314 p1  Is  0:00.00 -ksh (ksh)
  13670 p1  SE+ 0:00.01 (perl)
   6996 p2  Ss  0:00.00 -ksh (ksh)
  13352 p2  R+/10:00.00 ps
 
 What's the output of ps -Owchan,procflags,f for the process?

$ ps -Owchan,procflags,f
ps: procflags: keyword not found
  PID WCHAN F TT  STAT   TIME COMMAND
 1579 pause  408e p0  Is  0:00.00 -ksh (ksh)
21410 ttyout  80006086 p0  IE+ 0:00.00 (perl)
 8608 pause  408e p1  Ss  0:00.00 -ksh (ksh)
27149 -  4006 p1  R+/10:00.00 ps -Owchan

(Running 5.4-stable, so that's why procflags isn't recognized. I'll try a
snapshot to see what happens.)

Regards,

Jurjen Oskam



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-10 Thread Philip Guenther
On Fri, Jan 10, 2014 at 7:33 AM, Jurjen Oskam jur...@osk.am wrote:
 (Running 5.4-stable, so that's why procflags isn't recognized. I'll try a
 snapshot to see what happens.)

Oh, you're running 5.4-stable?  I thought you were running -current
and was worried there was another hang in there.  I'm now 99% sure
you're hitting the one I fixed back in October.


Philip Guenther



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-10 Thread Jurjen Oskam
Philip Guenther guenther at gmail.com writes:


 Oh, you're running 5.4-stable?  I thought you were running -current
 and was worried there was another hang in there.  I'm now 99% sure
 you're hitting the one I fixed back in October.

I did some more experimenting, and I found that the issue does not happen
when I leave out the crtscts option to stty.

With crtscts however, things get weird:

Opening and immediately closing cua01 is no problem:

open cua01
stty 9600 sane parenb -parodd crtscts cs7 igncr
close cua01 # device probably didn't send anything yet
exit# exits normally



Opening cua01 and closing it later *is* a problem:

open cua01
stty 9600 sane parenb -parodd crtscts cs7 igncr
sleep 15# to make sure the device on the other end has sent some data
close cua01 # HANGS, but is interruptible after which everything is nicely
  cleaned up
exit# never reached



Interrupting a read from cua01 results in a process that can't exit:

open cua01
stty 9600 sane parenb -parodd crtscts cs7 igncr
while-loop {
read cua01  # blocks when the other end isn't sending anything; if the
  process is interrupted now it won't ever exit;
  cua01 is not released and only a reboot clears the process
}
close cua01 # HANGS, but is interruptible after which everything is nicely
  cleaned up
exit# never reached


Again, if I leave out crtscts (and leave everything else the same),
everything works as expected: no hangs at all, and interrupting a read is no
problem.

I'm sorry, but I don't know which hang you fixed in October. With this
information, do you think it's the same hang?

Thanks,

Jurjen Oskam



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-10 Thread Stuart Henderson
On 2014-01-10, Jurjen Oskam jur...@osk.am wrote:
 Philip Guenther guenther at gmail.com writes:

 Oh, you're running 5.4-stable?  I thought you were running -current
 and was worried there was another hang in there.  I'm now 99% sure
 you're hitting the one I fixed back in October.


 I'm sorry, but I don't know which hang you fixed in October. With this
 information, do you think it's the same hang?

It's this one, which is in 5.4-stable updated after 2013/11/12
http://ftp.openbsd.org/pub/OpenBSD/patches/5.4/common/003_vnode.patch



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-09 Thread Jurjen Oskam
Philip Guenther guenther at gmail.com writes:

 This is where Remco's response comes into play.  As described on the
 tty(4)/cua(4) manpage, /dev/ttyU* blocks on open until the external
 device signals that it's active via some hardware signal (DTR, iirc).
 If you want to initiate an outgoing connection to a potentially
 inactive device, use the matching /dev/cuaU* device.

OK, I've got it to work using a /dev/cua* device. I still have problems with
processes not exiting though. Since this machine has real com ports, I also
made a cable that is attached to cua01 (no USB involved).

This little Perl script shows the problem:

#!/usr/bin/perl -w

$|=1;
close(STDIN) or die;
open(STDIN,/dev/cua01);
system(/bin/stty 9600 sane parenb -parodd crtscts cs7 igncr);
system(/bin/stty);
while (my $line = ) {
print $line;
}

I run it using ktrace:

$ ktrace -i ./try.pl
speed 9600 baud;
lflags: echoe echoke echoctl
iflags: igncr
cflags: cs7 parenb crtscts
/XMX5XMXABCE35164

0-0:96.1.1(31333031333735352020202020202020)
1-0:1.8.1(02932.937*kWh)
   [ ... output snipped ...]

It shows as follows in the output of ps:

$ ps
  PID TT  STAT   TIME COMMAND
15727 p0  Ss  0:00.01 -ksh (ksh)
13444 p0  S+  0:00.02 kdump -l -T
26314 p1  Ss  0:00.00 -ksh (ksh)
13670 p1  S+  0:00.01 /usr/bin/perl -w ./try.pl
 6996 p2  Ss  0:00.00 -ksh (ksh)
29731 p2  R+/10:00.00 ps

Then when I kill it, I get this:

$ kill 13670
$ ps
  PID TT  STAT   TIME COMMAND
15727 p0  Is  0:00.01 -ksh (ksh)
13444 p0  S+  0:00.02 kdump -l -T
26314 p1  Is  0:00.00 -ksh (ksh)
13670 p1  SE+ 0:00.01 (perl)
 6996 p2  Ss  0:00.00 -ksh (ksh)
13352 p2  R+/10:00.00 ps

... and after a while, this:

$ ps
  PID TT  STAT   TIME COMMAND
15727 p0  Is  0:00.01 -ksh (ksh)
13444 p0  S+  0:00.02 kdump -l -T
26314 p1  Is  0:00.00 -ksh (ksh)
13670 p1  IE+ 0:00.01 (perl)
 6996 p2  Ss  0:00.00 -ksh (ksh)
23612 p2  R+/10:00.00 ps

The terminal on which the Perl script was running didn't return the prompt.
The script was also no longer running, because it didn't display new data
coming from cua00 anymore.

The last few lines from ktrace.out are:

 13670 perl 1389283736.782851 RET   write 2
 13670 perl 1389283736.782855 CALL  read(0,0x10dbb9977000,0x2000)
 13670 perl 1389283738.376985 PSIG  SIGTERM SIG_DFL

The read normally blocks for 10 seconds, because that is the interval the
meter sends it data. The kill happened while this read was waiting for data.

I am now no longer able to terminate the process. Disconnecting its terminal
just gives:

$ ps
  PID TT  STAT   TIME COMMAND
15727 p0  Is  0:00.01 -ksh (ksh)
13444 p0  S+  0:00.02 kdump -l -T
13670 p1- IE  0:00.01 (perl)
 6996 p2  Ss  0:00.00 -ksh (ksh)
32590 p2  R+/10:00.00 ps

Killing it with -9 also does not work.

cua01 is still busy though:

$ stty -f /dev/cua01
stty: /dev/cua01: Device busy


The only way to get rid of the process is to reboot the system.


Am I doing anything wrong here? I expected the process to just exit and
release cua01 after I killed it.

Regards,

Jurjen Oskam



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-09 Thread Philip Guenther
On Thu, Jan 9, 2014 at 8:20 AM, Jurjen Oskam jur...@osk.am wrote:
 OK, I've got it to work using a /dev/cua* device. I still have problems with
 processes not exiting though. Since this machine has real com ports, I also
 made a cable that is attached to cua01 (no USB involved).
...
 Then when I kill it, I get this:

 $ kill 13670
 $ ps
   PID TT  STAT   TIME COMMAND
 15727 p0  Is  0:00.01 -ksh (ksh)
 13444 p0  S+  0:00.02 kdump -l -T
 26314 p1  Is  0:00.00 -ksh (ksh)
 13670 p1  SE+ 0:00.01 (perl)
  6996 p2  Ss  0:00.00 -ksh (ksh)
 13352 p2  R+/10:00.00 ps

What's the output of ps -Owchan,procflags,f for the process?


Philip Guenther



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-08 Thread Stuart Henderson
On 2014-01-07, Jurjen Oskam jur...@osk.am wrote:
 open(METER,/dev/ttyUSB0) or die;
 while(METER) {
   # do stuff
 done

http://www.jibble.org/currentcost/ uses Device::SerialPort
(p5-Device-SerialPort-1.04p0v0 in packages) to setup the serial port
from perl. This might be easier than wrapping your perl script in a
shell script.



Cannot set stty parameters and read from /dev/ttyU0

2014-01-07 Thread Jurjen Oskam
Hi everybody,

Earlier I had a Linux machine (well, a Raspberry Pi actually) which
I used to read out my energy meter. The energy meter was connected
to a USB port with a custom FTDI cable. The energy meter only
supports reading from it, writing to it is not possible.

On Linux, I set the necessary parameters on the USB tty as follows:

/bin/stty -F /dev/ttyUSB0 9600 sane evenp crtscts cs7 igncr

And after that, issuing cat /dev/ttyUSB0 resulted in the output
I'm interested in: the energy meter outputs its data every ten seconds.

Wrapping this in a Perl script was easy: just set issue the stty
command before invoking the Perl script, and in Perl I could just open
/dev/ttyUSB0 for reading and process the output line by line:

open(METER,/dev/ttyUSB0) or die;
while(METER) {
  # do stuff
done

This worked fine.


I replaced the Raspberry Pi with a more powerful amd64 machine
(full dmesg below). The USB cable shows up as:

uftdi0 at uhub3 port 6 FTDI P1 Converter Cable rev 2.00/6.00 addr 3
ucom0 at uftdi0 portno 1


But now I can't figure out how to read from /dev/ttyU0.

The first problem I'm having is that the stty setting doesn't seem to
stick:

$ stty -f /dev/ttyU0
ispeed 0 baud; ospeed 9600 baud;
lflags: echoe echoke echoctl
cflags: cs8 -parenb

$ stty -f /dev/ttyU0 9600 sane parenb -parodd crtscts cs7 igncr
$

$ stty -f /dev/ttyU0
ispeed 0 baud; ospeed 9600 baud;
lflags: echoe echoke echoctl
cflags: cs8 -parenb

When I do a cat /dev/ttyU0 in one terminal, it just hangs without
displaying anything. If I execute stty -f /dev/ttyU0 in another terminal,
cat suddenly outputs a few lines of garbage and then exits.


When I again do a cat /dev/ttyU0 in one terminal, but then use stty in
another terminal to set the correct settings, the cat command starts
outputting the correct data: several lines of output every ten seconds.
After while, it stops though, and I can't interrupt the cat command
anymore. A stty in another terminal also hangs uninterruptibly. Even a
kill -9 and disconnecting the SSH session doesn't work:

joskam   21226  0.0  0.0   180   152 p0  D+ 3:56PM0:00.00 stty -f
/dev/ttyU0
joskam   22302  0.0  0.0   236   176 p1- IE 3:54PM0:00.00 (cat)

I did read the manual pages, but I probably overlooked something.


How can I set the correct parameters on /dev/ttyU0 and read from it?


Thank you,

Jurjen Oskam



Full dmesg:

OpenBSD 5.4 (GENERIC.MP) #1: Tue Nov 12 10:57:06 CET 2013
   
r...@binpatch-54-amd64.mtier.org:/home/jasper/binpatchng/work-binpatch54-
amd64/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 4204191744 (4009MB)
avail mem = 4084551680 (3895MB)
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0xeb420 (76 entries)
bios0: vendor American Megatrends Inc. version 2.04 date 04/16/2013
bios0: Shuttle Inc. DS61
acpi0 at bios0: rev 2
acpi0: sleep states S0 S1 S3 S4 S5
acpi0: tables DSDT FACP APIC MCFG SLIC HPET SSDT SSDT SSDT
acpi0: wakeup devices P0P1(S4) USB1(S3) USB2(S3) USB3(S3) USB4(S3) USB5(S3)
USB6(S3) USB7(S3) PXSX(S4) RP01(S4) PXSX(S4) RP02(S4) PXSX(S4) RP03(S4)
PXSX(S4) RP04(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Pentium(R) CPU G2020 @ 2.90GHz, 2893.81 MHz
cpu0:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,
CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,
DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,POPCNT,DEADLINE,
XSAVE,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
cpu0: apic clock running at 99MHz
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Pentium(R) CPU G2020 @ 2.90GHz, 2893.43 MHz
cpu1:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,
CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,
DS-CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,POPCNT,DEADLINE,
XSAVE,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 0, core 1, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 24 pins
acpimcfg0 at acpi0 addr 0xf800, bus 0-63
acpihpet0 at acpi0: 14318179 Hz
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus -1 (P0P1)
acpiprt2 at acpi0: bus 2 (RP01)
acpiprt3 at acpi0: bus 3 (RP02)
acpiprt4 at acpi0: bus -1 (RP03)
acpiprt5 at acpi0: bus 4 (RP04)
acpiprt6 at acpi0: bus -1 (RP05)
acpiprt7 at acpi0: bus -1 (RP06)
acpiprt8 at acpi0: bus -1 (RP07)
acpiprt9 at acpi0: bus -1 (RP08)
acpiprt10 at acpi0: bus 1 (PEG0)
acpiec0 at acpi0: Failed to read resource settings
acpicpu0 at acpi0: C3, C2, C1, PSS
acpicpu1 at acpi0: C3, C2, C1, PSS
acpipwrres0 at acpi0: FN00
acpipwrres1 at acpi0: FN01
acpipwrres2 at acpi0: FN02
acpipwrres3 at acpi0: FN03
acpipwrres4 at acpi0: FN04
acpitz0 at acpi0: critical temperature is 106 degC
acpitz1 at acpi0: critical temperature is 106 degC
acpibat0 at acpi0: BAT0 not 

Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-07 Thread Theo de Raadt
 /bin/stty -F /dev/ttyUSB0 9600 sane evenp crtscts cs7 igncr

^^ --- no a standard stty option
 The first problem I'm having is that the stty setting doesn't seem to
 stick:

 $ stty -f /dev/ttyU0
 ispeed 0 baud; ospeed 9600 baud;
 lflags: echoe echoke echoctl
 cflags: cs8 -parenb
 
 $ stty -f /dev/ttyU0 9600 sane parenb -parodd crtscts cs7 igncr

-f is not -F

When the tty is closed, it reverts to the default configuration.
There is no support for this -F method.

What you need to instead is wrap all this in a way which keeps the
tty open

(
stty 9600 sane parenb -parodd crtscts cs7 igncr
do your IO loop
) /dev/ttyU0 01 02

Something like that.



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-07 Thread Philip Guenther
On Tue, Jan 7, 2014 at 8:23 AM, Theo de Raadt dera...@cvs.openbsd.org wrote:
 What you need to instead is wrap all this in a way which keeps the
 tty open

 (
 stty 9600 sane parenb -parodd crtscts cs7 igncr
 do your IO loop
 ) /dev/ttyU0 01 02

 Something like that.

I think the desired redirections on the subshell-close would make that
last line:
) /dev/ttyU0 0

(open /dev/ttyU0 read-write as stdin, and then dup that to stdout)


Philip Guenther



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-07 Thread Remco
Jurjen Oskam wrote:

 uftdi0 at uhub3 port 6 FTDI P1 Converter Cable rev 2.00/6.00 addr 3
 ucom0 at uftdi0 portno 1
 
 
 But now I can't figure out how to read from /dev/ttyU0.
 

I usually use /dev/cuaU0 when reading from serial-to-USB converters.

Unless your cable is different in some way I think running cu(1) on a cua(4) 
device (something like cu -l/dev/cuaU0 -s9600) may show you the desired 
information.



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-07 Thread Jurjen Oskam
Philip Guenther guenther at gmail.com writes:

 On Tue, Jan 7, 2014 at 8:23 AM, Theo de Raadt deraadt at
cvs.openbsd.org wrote:
  What you need to instead is wrap all this in a way which keeps the
  tty open
 
  (
  stty 9600 sane parenb -parodd crtscts cs7 igncr
  do your IO loop
  ) /dev/ttyU0 01 02
 
  Something like that.
 
 I think the desired redirections on the subshell-close would make that
 last line:
 ) /dev/ttyU0 0
 
 (open /dev/ttyU0 read-write as stdin, and then dup that to stdout)

Thank you for the responses. I sort of figured out that the stty settings
are set to default each time the device is opened, but now that's confirmed
I ran into the problem that open() does not seem to be returning.

I created the following simple shell script:

#!/bin/sh

( stty 9600 sane parenb -parodd crtscts cs7 igncr
while read line
do
echo $line
done
) /dev/ttyU0 0

Running it results in no output at all, without the prompt coming back.
Interrupting the process results in the following ktrace snippet:

   486 sh   1389125130.342774 CALL  
open(0x208ee2c50,0x202O_RDWR|O_CREAT,0x1b6S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
|S_IROTH|S_IWOTH)
   486 sh   1389125130.342776 NAMI  /dev/ttyU0
   486 sh   1389125151.417307 PSIG  SIGINT caught handler=0x4214f0 
mask=0
   486 sh   1389125151.417312 RET   open -1 errno 4 Interrupted system 
call

Looking at the timestamps, the open() only returns when I Ctrl-C the process.

The same happens with the following trivial Perl script:

#!/usr/bin/perl -w

$|=1;
open(METER,/dev/ttyU0) or die;
print opened terminal\n;
close(METER);


Running it produces no output without the prompt coming back, at least not
until I Ctrl-C the Perl script:

 15860 perl 1389125426.222462 CALL  open(0x12f6694a1d70,0O_RDONLY)
 15860 perl 1389125426.222465 NAMI  /dev/ttyU0
 15860 perl 1389125451.261414 PSIG  SIGINT SIG_DFL

Again, open() doesn't seem to return.

Am I doing something wrong here?

Regards,

Jurjen Oskam



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-07 Thread Philip Guenther
On Tue, Jan 7, 2014 at 12:17 PM, Jurjen Oskam jur...@osk.am wrote:
 Thank you for the responses. I sort of figured out that the stty settings
 are set to default each time the device is opened, but now that's confirmed
 I ran into the problem that open() does not seem to be returning.

 I created the following simple shell script:

 #!/bin/sh

 ( stty 9600 sane parenb -parodd crtscts cs7 igncr
 while read line
 do
 echo $line
 done
 ) /dev/ttyU0 0

 Running it results in no output at all, without the prompt coming back.
 Interrupting the process results in the following ktrace snippet:

486 sh   1389125130.342774 CALL
 open(0x208ee2c50,0x202O_RDWR|O_CREAT,0x1b6S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
 |S_IROTH|S_IWOTH)
486 sh   1389125130.342776 NAMI  /dev/ttyU0
486 sh   1389125151.417307 PSIG  SIGINT caught handler=0x4214f0
 mask=0
486 sh   1389125151.417312 RET   open -1 errno 4 Interrupted system
 call

 Looking at the timestamps, the open() only returns when I Ctrl-C the process.

This is where Remco's response comes into play.  As described on the
tty(4)/cua(4) manpage, /dev/ttyU* blocks on open until the external
device signals that it's active via some hardware signal (DTR, iirc).
If you want to initiate an outgoing connection to a potentially
inactive device, use the matching /dev/cuaU* device.


Philip Guenther



Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-07 Thread Alexander Hall

On 01/07/14 21:17, Jurjen Oskam wrote:

Philip Guenther guenther at gmail.com writes:


On Tue, Jan 7, 2014 at 8:23 AM, Theo de Raadt deraadt at

cvs.openbsd.org wrote:

What you need to instead is wrap all this in a way which keeps the
tty open

 (
 stty 9600 sane parenb -parodd crtscts cs7 igncr
 do your IO loop
 ) /dev/ttyU0 01 02

Something like that.


I think the desired redirections on the subshell-close would make that
last line:
 ) /dev/ttyU0 0

(open /dev/ttyU0 read-write as stdin, and then dup that to stdout)


Thank you for the responses. I sort of figured out that the stty settings
are set to default each time the device is opened, but now that's confirmed
I ran into the problem that open() does not seem to be returning.

I created the following simple shell script:

#!/bin/sh

( stty 9600 sane parenb -parodd crtscts cs7 igncr
while read line
do
echo $line
done
) /dev/ttyU0 0

Running it results in no output at all, without the prompt coming back.


No surprise, really, as you redireced the printed lines back into the 
tty... :-)


Either print it to stderr (echo $line 2), or I simply suspect you 
don't want the '0' part.


/Alexander


Interrupting the process results in the following ktrace snippet:

486 sh   1389125130.342774 CALL
open(0x208ee2c50,0x202O_RDWR|O_CREAT,0x1b6S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
|S_IROTH|S_IWOTH)
486 sh   1389125130.342776 NAMI  /dev/ttyU0
486 sh   1389125151.417307 PSIG  SIGINT caught handler=0x4214f0
mask=0
486 sh   1389125151.417312 RET   open -1 errno 4 Interrupted system
call

Looking at the timestamps, the open() only returns when I Ctrl-C the process.

The same happens with the following trivial Perl script:

#!/usr/bin/perl -w

$|=1;
open(METER,/dev/ttyU0) or die;
print opened terminal\n;
close(METER);


Running it produces no output without the prompt coming back, at least not
until I Ctrl-C the Perl script:

  15860 perl 1389125426.222462 CALL  open(0x12f6694a1d70,0O_RDONLY)
  15860 perl 1389125426.222465 NAMI  /dev/ttyU0
  15860 perl 1389125451.261414 PSIG  SIGINT SIG_DFL

Again, open() doesn't seem to return.

Am I doing something wrong here?

Regards,

Jurjen Oskam




Re: Cannot set stty parameters and read from /dev/ttyU0

2014-01-07 Thread Daniel Bolgheroni
On Tue, Jan 07, 2014 at 03:05:39PM +, Jurjen Oskam wrote:
 Hi everybody,
 
 Earlier I had a Linux machine (well, a Raspberry Pi actually) which
 I used to read out my energy meter. The energy meter was connected
 to a USB port with a custom FTDI cable. The energy meter only
 supports reading from it, writing to it is not possible.

Some years ago I used a Arduino Duemilanove in a project. This board
uses the FTDI chipset uftdi(4). As Remco, it worked pretty well for me
too, using cu(1) or tip(1) + /dev/cuaUx.

-- 
db