title: Expect/TCL and Serial Port interaction
body: <p>My apologies if this has been asked, I did search. I'm trying to use expect to script some serial port operations &amp; am quite confused by the spawn_id unexpectedly going away. The msg. is; spawn id exp10 not open. I'll try to keep this short but with enough info for possible answers, the script goes as follows (mix of actual statements/pseudocode):</p>
  
  <p>set comId [openSerial $baud $dev] ($baud is set 115200, $dev is set /dev/ttyUSB0)</p>
  
  <p>In openSerial:</p>
  
  <pre><code>set portId [open $dev RDWR]
  if 'catch' fconfigure the port for mode(typical), handshake(none), blocking(0), buffering(none) 'error'
  return 0
  else
  spawn -open $portId -noecho
  return $spawn_id
  </code></pre>
  
  <p>So far, so good. Back in the main script where I called openSerial I sleep 5 seconds &amp; puts the spawn id, $comId, which shows as exp10. So then I call my test proc without any parameters. Inside it looks like:</p>
  
  <pre><code>proc test {} {
  expect {
    "string to wait for" { puts "got it"
                           expect "next string to wait for"
                           puts "got it"
                           expect "final string"
                           puts "got it"
                           return }
    timeout { do stuff if timed out }
    }
  }
  </code></pre>
  
  <p>I get the first and second expected output, then expect returns spawn_id exp10 not open. Why does it go away in the middle of running? The expect book does not have much on communicating with serial ports so I'm at a loss as of now. If anyone reads this &amp; has an answer, I will appreciate same. In the interim, I'll keep experimenting.</p>
  
  <p>ACE</p>