| ||||||
Windows COM port communication with Expect Posted by lanceh (lanceh), 17 April 2008 Does anyone have an example of an Expect script for communicating with a device connected to a Windows XP workstation's COM port?Please...no theories about that it should be possible. I'd rather know if some has successfully done this before I put more time into trying to get this to work. I've tried and apparently, I'm overlooking something. Posted by lanceh (lanceh), 8 October 2008 I'm surprised no one has wanted to use Expect to control a device serially through a PC Communication port, live a WTI switch connected serially to a network switch(unconfigured).Below is something I found useful for communication over a TCP connection, but I haven't had time to get it to work with COM ports yet: proc send_string {expectTimeout spawnid stringToSend expectedOutput} { global displayLevel if {![info exists displayLevel]} {set displayLevel 3} if {$displayLevel >= 7} { send_user "\n\nINFO: (send_string) received: ($expectTimeout)" send_user "\nINFO: (send_string) received: ($spawnid)" send_user "\nINFO: (send_string) received: ($stringToSend)" send_user "\nINFO: (send_string) received: ($expectedOutput)\n" } set timeout $expectTimeout set spawn_id $spawnid expect "*" send -i $spawnid "$stringToSend\r" expect { "$expectedOutput" {set recBuffer $expect_out(buffer)} timeout {send_user "\nCRITICAL: Timeout(send_string) on spawnid($spawnid)!\n Sent=($stringToSend)\n Expected output=($expectedOutput)" set recBufferTimeout "" append recBufferTimeout $expect_out(buffer) set recBuffer "" append recBuffer $recBufferTimeout send_user "\n\nINFO: (send_string) The expected output after sending the string($stringToSend) was not found within ($expectTimeout) seconds.\n [timestamp]\n Content of receiver buffer=($recBufferTimeout)\n\n\n" #Grab stats via serial console. source "lib//lib_grab_stats_on_timeout.tcl" global flag_breakForLoop set flag_breakForLoop "yes" } } set timeout 30 if {$displayLevel >= 9} {send_user "\nDEBUG: (send_string) returning: recBuffer=($recBuffer)\n\n\n"} return $recBuffer } Posted by Custard (Custard), 25 November 2008 I don't know if this helps, but this is an extract from a bit of code I wrote in 1996 which connects to windows (95!) com ports.Code:
I believe you can 'spawn' to an opened file handle with Code:
HTH Bruce This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
| ||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |