Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho