| |||||||||||
Processing hex input in Expect Posted by donnerdave (donnerdave), 2 June 2005 Using ActiveState's ActiveTcl v8.4.9.1 and Expect for Windows v1.01 under WinXP.I'm hoping to script / verify a binary message exchange between an embedded system and a PC application (for testing purposes, simulating the PC application with Expect / TCL). First issue: my message exchange can include null characters (i.e. 0x00), which I understand are string delimiters in TCL. How best to "expect" and "puts" these messages with Expect / TCL? Here's a snippet of my existing code: #!/bin/sh # \ exec tclsh "$0" ${1+"$@"} # This is required to declare that we will use Expect package require Expect # This special variable used by the ActiveState Expect for Windows # port will enable actual viewing of the controlled console. # Otherwise it remains hidden (default). set exp::winnt_debug 1 set serial [open com1: r+] fconfigure $serial -mode "19200,n,8,1" -blocking 0 -buffering none set process [exp_spawn -open $serial -noecho] puts stdout "Waiting for Node Alive message ...." #Expect the Node Alive message ... expect "0x7E0x410x000x63" #Send the Node Alive response ... puts "0x7E0x410x000x64" Of course, the "expect" message doesn't match the hex string, rather looks explicitly for the series of characters '0', 'x', ... Second question: how to match the binary characters? Third question: how to send the binary characters in response? Thanks in advance for any help. Best! Dave Posted by admin (Graham Ellis), 3 June 2005 I'm reminded of a thread of a couple of months back - nor archived at http://www.wellho.net/forum/The-Tcl-programming-language/Long-String-to-ASCII.html - which at least starts to provide and answer.To expect (or interact) a null character, use the remove_nulls command with a parameter of 0 to allow nulls into the incoming stream; they can then be explicity matched using the null keyword. remove_nulls has a couple of options that may make it a bit more flexible for you. To quote Don Libes (author of expect) "Nulls can only be matched by themselves ..." - page 156 of Exploring Expect 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 |