LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-05-2014, 03:10 PM   #1
eliasson
LQ Newbie
 
Registered: May 2011
Posts: 7

Rep: Reputation: 0
Expect spawn_id closes unexpectedly


Hello,

I'm having a problem getting an expect script to work with a serial port. In the past, I've had success with expect using telnet & ssh, but I left scripting for some time. Now I'm back to it & working on automating some operations taking place over a serial port. So I have a simple script that opens the serial port, expects a set of 3 strings to come across, & lets me know they arrived. This is a simple test but I can't get it to consistently work. Most of the time, the script fails with; 'expect: spawn_id exp10 not open'. I'm too dense to pull out of the book on expect any reason why this happens & am hoping someone here may help. I'll try to post enough script details for a possible answer while not overdoing it ...

proc openSerial {baud_rate ser_dev} {
set portId [open $ser_dev RDWR]
if {[catch {chan configure $portId -mode "$baud_rate,n,8,1" } error]} {
exp_send_user "could not configure &ser_dev parms\n"
return 0
} else {
spawn -open $portId -noecho
return $spawn_id
}
return 0
}

Main body of script ...

Opening the serial port:
set baud 115200
set serDev /dev/ttyUSB0
set comId00 [openSerial $baud $serDev]
sleep 5
puts "serial spawn id is $comId00\n"

At this point I see exp10 output as the spawn ID ... so I do the following:

expect {
"<first string>"
{ puts "got it ...\n"
expect "<next string>"
puts "got string 2 ...\n"
expect "<last string>"
puts "got final string ...\n" }
timeout { do timeout stuff ... }
}

When I run this, I see string 1 & string 2 as expected. Then I see the 'spawn id not open' message & the script fails. I guess I don't really understand what's happening with spawn & how that relates to the serial port? I need to continue working with this port & can't even get started so far. Any help will be appreciated.

ACE
 
Old 02-21-2014, 01:45 PM   #2
eliasson
LQ Newbie
 
Registered: May 2011
Posts: 7

Original Poster
Rep: Reputation: 0
Solved this ...

So, after much pulling of hair & gnashing of teeth, I got past this problem. Turns out the script was ok, it was my interaction with the serial port after power up, or power cycle, of the host. The 'putty' utility was not having any problem accessing the port after power up, so I compared what 'putty' was doing to initialize the port with the port settings directly after power up. I now 'exec' a short C program to set the port attributes based on those 'putty' uses, before running 'opening' the port in the script, & it's working.

ACE
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Gnome Hearts 0.3 closes unexpectedly sequimbob Linux - Games 7 03-27-2016 11:20 AM
Kdenlive rendering stops, “melt”(MLT) closes unexpectedly williepabon Linux - Software 0 12-29-2012 03:45 AM
Ies4linux closes unexpectedly chris1379 Linux - Software 2 09-12-2009 01:10 PM
Expect script exiting unexpectedly (eof) deadeyes Linux - Software 5 09-02-2009 02:23 AM
Firefox closes unexpectedly when viewing videos, games etc. asm06230 Linux - Software 1 01-28-2009 03:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration