I am able to send AT cmd to the modem. However, I can't see the
response. Setting blocking to 0 or 1 can't solve the problem.
#!/usr/bin/tclsh8.3
set devname "/dev/ttyS0"
set port [open $devname RDWR]
fconfigure $port -mode 19200,n,8,1 -blocking 0
puts -nonewline $port "AT\r"
flush $port
foreach line [split [read $port] \n] {
puts $line
}
close $port
Here's a snippet from one of my apps. Perhaps it will help:
set com [open /dev/ttyS4 RDWR]
fconfigure $com -mode 115200,n,8,1 -handshake rtscts -blocking 0 \
-buffering none -translation binary
puts -nonewline $com "ATZ\r"
flush $com
after 100
puts "Modem send: [gets $com]"
puts "Modem echo: [gets $com]"
Steve
As already pointed out the modem and the communication needs some time.
Sending 3 characters @19200 bps physically takes ~1.5 milliseconds.
You may consider to
(a) setup a fileevent callback to keep your tcl-application alive.
(b) setup an after callback, continously checking for serial data.
(a) guaranties the fastest reaction, but when communicating
line-by-line, you need to be aware that you might receive only part
of the incoming line in a single [fileevent] callback.
(b) might be a bit easier to implement, because you can use [gets].
In both cases setting up a proper [fconfigure -timeout] can be helpful.
Regards,
Rolf.
--
---------------------------------------------------------------
Rolf Schroedter, German Aerospace Center
Remove .nospam to reply: mailto:Rolf.Sc...@dlr.de.nospam
Thank you very much!! You saved my day :P
Francis