NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Help on serial ports
On Tue, Jun 22, 2010 at 12:11:15PM +0200, Volker Wolfram wrote:
> No I try to communicate with 2 USB-RS232 Adapters and a nullmodem cable. I try
> to send data from one /dev/ttyU0 to /dev/ttyU1 and catch the data on the last
> device. But all fails. I tried many steps but all fails. Except one following
> setup: one minicom client comunicates via /dev/ttyU0 and another client do it
> on /dev/ttyU1. So I think my serial line adapters and the nullmodem cable work
> well. But what should I do with my scripts? Can anyone help me?
>
> Exactly how are you communicating with the port? I wrote an SMS daemon in C.
> It talks to the modem via a serial port. I had to do a *lot* of low level
> hacking to get that port talking to me. I would be happy to post the code if
> it is going to help.
> --
> Michael Smith
I bet the problem is that the connection cable doesn't have a Data Carrier
Detect pin connected, and NetBSD is blocking the open() call until that signal
is detected. This result in a never-returning [open].
> here is my code for sending a character:
> #!/usr/pkg/bin/tclsh
>
> set serialHandle [ open "/dev/ttyU0" r+ ]
> fconfigure $serialHandle -translation binary -mode "9600,n,8,1"
> fconfigure $serialHandle -encoding binary
> fconfigure $serialHandle -blocking 0 -buffering none -handshake none
>
> fileevent $serialHandle writable [ puts $serialHandle "m" ]
> close $serialHandle
try this:
#!/usr/pkg/bin/tclsh
proc sendData {fd data} {
puts $fd $data
close $fd
exit
}
set device "/dev/ttyU0"
exec /bin/sh -c "sleep 1 && stty -f $device clocal" &
set serialHandle [open $device r+]
fconfigure $serialHandle -translation binary -mode "9600,n,8,1"
fconfigure $serialHandle -encoding binary
fconfigure $serialHandle -blocking 0 -buffering none -handshake none
fileevent $serialHandle writable [list sendData $serialHandle "m"]
# I guess you have this line, but I'll add it anyway
vwait forever
> and here the code for the receiver:
> #!/usr/pkg/bin/tclsh
>
> set serialHandle [ open "/dev/ttyU1" r+ ]
> fconfigure $serialHandle -translation binary -mode "9600,n,8,1"
> fconfigure $serialHandle -encoding binary
> fconfigure $serialHandle -blocking 0 -buffering none -handshake none
>
> fileevent $serialHandle readable [ puts stdout [ read $serialHandle ] ]
> close $serialHandle
and this for the receiver:
#!/usr/pkg/bin/tclsh
proc receiveData {fd} {
puts [read $fd]
close $fd
exit
}
set device "/dev/ttyU1"
exec /bin/sh -c "sleep 1 && stty -f $device clocal" &
set serialHandle [open $device r+]
fconfigure $serialHandle -translation binary -mode "9600,n,8,1"
fconfigure $serialHandle -encoding binary
fconfigure $serialHandle -blocking 0 -buffering none -handshake none
fileevent $serialHandle readable [list receiveData $serialHandle]
vwait forever
Hope this helps.
Emiliano
Home |
Main Index |
Thread Index |
Old Index