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:56PM 0:00.00 stty -f
/dev/ttyU0
joskam 22302 0.0 0.0 236 176 p1- IE 3:54PM 0: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
[email protected]:/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 0xfee00000: 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 0xfec00000, version 20, 24 pins
acpimcfg0 at acpi0 addr 0xf8000000, 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 present
acpibat1 at acpi0: BAT1 not present
acpibat2 at acpi0: BAT2 not present
acpibtn0 at acpi0: PWRB
acpibtn1 at acpi0: LID0
acpivideo0 at acpi0: GFX0
acpivout0 at acpivideo0: DD02
cpu0: Enhanced SpeedStep 2893 MHz: speeds: 2900, 2800, 2700, 2600, 2500,
2400, 2300, 2200, 2100, 2000, 1900, 1800, 1700, 1600 MHz
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 "Intel Xeon E3-1200v2 Host" rev 0x09
ppb0 at pci0 dev 1 function 0 "Intel Xeon E3-1200v2 PCIE" rev 0x09: msi
pci1 at ppb0 bus 1
vga1 at pci0 dev 2 function 0 "Intel HD Graphics 2500" rev 0x09
intagp0 at vga1
agp0 at intagp0: aperture at 0xe0000000, size 0x10000000
inteldrm0 at vga1
drm0 at inteldrm0
No connectors reported connected with modes
Cannot find any crtc or sizes - going 1024x768
inteldrm0: 1024x768
wsdisplay0 at vga1 mux 1: console (std, vt100 emulation)
wsdisplay0: screen 1-5 added (std, vt100 emulation)
"Intel 6 Series MEI" rev 0x04 at pci0 dev 22 function 0 not configured
ehci0 at pci0 dev 26 function 0 "Intel 6 Series USB" rev 0x05: apic 2 int 16
usb0 at ehci0: USB revision 2.0
uhub0 at usb0 "Intel EHCI root hub" rev 2.00/1.00 addr 1
ppb1 at pci0 dev 28 function 0 "Intel 6 Series PCIE" rev 0xb5: msi
pci2 at ppb1 bus 2
ppb2 at pci0 dev 28 function 1 "Intel 6 Series PCIE" rev 0xb5: msi
pci3 at ppb2 bus 3
re0 at pci3 dev 0 function 0 "Realtek 8168" rev 0x06: RTL8168E/8111E-VL
(0x2c80), apic 2 int 17, address 80:ee:73:73:59:f7
rgephy0 at re0 phy 7: RTL8169S/8110S PHY, rev. 5
ppb3 at pci0 dev 28 function 3 "Intel 6 Series PCIE" rev 0xb5: msi
pci4 at ppb3 bus 4
re1 at pci4 dev 0 function 0 "Realtek 8168" rev 0x06: RTL8168E/8111E-VL
(0x2c80), apic 2 int 19, address 80:ee:73:73:59:f6
rgephy1 at re1 phy 7: RTL8169S/8110S PHY, rev. 5
ehci1 at pci0 dev 29 function 0 "Intel 6 Series USB" rev 0x05: apic 2 int 23
usb1 at ehci1: USB revision 2.0
uhub1 at usb1 "Intel EHCI root hub" rev 2.00/1.00 addr 1
pcib0 at pci0 dev 31 function 0 "Intel H61 LPC" rev 0x05
ahci0 at pci0 dev 31 function 2 "Intel 6 Series AHCI" rev 0x05: msi, AHCI 1.3
scsibus0 at ahci0: 32 targets
sd0 at scsibus0 targ 1 lun 0: <ATA, Samsung SSD 840, EXT0> SCSI3 0/direct
fixed naa.50025388a00f2d01
sd0: 114473MB, 512 bytes/sector, 234441648 sectors, thin
ichiic0 at pci0 dev 31 function 3 "Intel 6 Series SMBus" rev 0x05: apic 2 int 18
iic0 at ichiic0
spdmem0 at iic0 addr 0x50: 2GB DDR3 SDRAM PC3-10600 SO-DIMM
spdmem1 at iic0 addr 0x52: 2GB DDR3 SDRAM PC3-10600 SO-DIMM
isa0 at pcib0
isadma0 at isa0
com0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo
com1 at isa0 port 0x2f8/8 irq 3: ns16550a, 16 byte fifo
pckbc0 at isa0 port 0x60/5
kbc: cmd word write error
pcppi0 at isa0 port 0x61
spkr0 at pcppi0
it0 at isa0 port 0x2e/2: IT8728F rev 1, EC port 0xa30
mtrr: Pentium Pro MTRR support
uhub2 at uhub0 port 1 "Intel Rate Matching Hub" rev 2.00/0.00 addr 2
umass0 at uhub2 port 2 configuration 1 interface 0 "Generic USB Storage" rev
2.00/94.54 addr 3
umass0: using SCSI over Bulk-Only
scsibus1 at umass0: 2 targets, initiator 0
sd1 at scsibus1 targ 1 lun 0: <Generic, STORAGE DEVICE, 9454> SCSI0 0/direct
removable
uhub3 at uhub1 port 1 "Intel Rate Matching Hub" rev 2.00/0.00 addr 2
uftdi0 at uhub3 port 6 "FTDI P1 Converter Cable" rev 2.00/6.00 addr 3
ucom0 at uftdi0 portno 1
vscsi0 at root
scsibus2 at vscsi0: 256 targets
softraid0 at root
scsibus3 at softraid0: 256 targets
root on sd0a (32b01165a87fc2c2.a) swap on sd0b dump on sd0b