exp_send not handling binary data correctly

Posted by none on 2016-08-05 06:58

I'm trying to use Expect to read and write bytes across a serial port to a hardware device. I've got a logic analyzer watching the serial TX and RX lines, so I can see what is sent and received. Everything works ok as long as bit 7 of the data is not set. If bit 7 is set, it looks like 0xC2 is prepended to the real data (i.e. two bytes are sent, 0xC2 followed by the data). A snippet of code that I tested this with:

if {[catch {open $options(-port) r+} handle]} {
return -code error "port $options(-port) failed to open: $handle"

fconfigure $handle -mode $options(-baud),n,8,1
fconfigure $handle -translation binary -buffering none -blocking 0 \
-handshake none -encoding binary

puts -nonewline $handle "\x80"

if {[catch {exp_spawn -open $handle} why]} {
catch {close $handle}

return -code error "failed to spawn: $why"

exp_send -i $spawn_id "\x80"

The "puts" to the serial port causes 0x80 to be sent on the serial port (as seen on the logic analyzer). The "exp_send" to the serial port results in two bytes being sent 0xC2 followed by 0x80.

I'm using Expect 5.45.3 and Tcl 8.6.4. I'm running this on a virtual machine running 64 bit ubuntu, underneath is Windows 7. I've done similar things with Expect in the past, but those were on 32 bit machines.

Any ideas on what I need to do to fix this?