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 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
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., 2022: 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