tags:

views:

737

answers:

3

I have created the following procedure in expect to work with an Agilent Base Station Simulator:

proc get_bss_parameter_value {bss parameter_string} {
global bss_array

set bss_str "$parameter_string?"

puts "String 1"
set bss_str "oa;$bss_array(gpib):$bss_str\r"
send "$bss_str"
expect {nopattern^}

puts "String 2"
set bss_str "en;$bss_array(gpib)"
puts "Sending bss_str: $bss_str"
send "$bss_str\r"
expect .*

set receive_buffer $expect_out(buffer)
puts "receive_buffer START: $receive_buffer"
puts "END"

return $receive_buffer
}

======================================================== OUTPUT:

String 1

>

oa;05:SYST:APPL? String 2 Sending bss_str: en;05 "CDMA 2000 Lab App T"

can't read "expect_out(buffer)": no such variable while executing "set receive_buffer $expect_out(buffer)" (procedure "get_bss_parameter_value" line 20)

======================================================== If "." is replaced by "" in the above code, this is the OUTPUT:

String 1

>

oa;05:SYST:APPL? String 2 Sending bss_str: en;05 receive_buffer START:

oa;05:SYST:APPL?

END Current application is

oa;05:SYST:APPL?

Problem:
1) I am not able to get the value "CDMA 2000 Lab App T" in the expect_out(buffer) variable which should match (due to .*) the output from the Agilent device. Is there something wrong with the code?
2) In both the cases, the command "en;05" is send but not displayed on stdout. Though we can see the expected output in the first case.

A: 

I was under the impression that the expect_out variable was a global. If I'm correct, then you'd need the following:

global expect_out

Or, you can refer to it as a global explicitly by using the namespace qualifier "::"

set receive_buffer $::expect_out(buffer)
RHSeeger
A: 

Note that the [expect] command by default does glob-style matching, not regexp-style. So, where you write:

expect .*

you are actually looking for a string beginning with a literal dot followed by any number of characters. As this fails to match, the expect_out array does not get populated. As you mention

expect *

behaves as you expect because the glob pattern "*" matches any string.

If you truly want ".*", then you need to specify

expect -re .*
set receive_buffer $expect_out(buffer)
glenn jackman
A: 

Hi,

I have done the same as you said like, declaration of expect_out as global and used it in the procedure. But still I am getting the error: can't read "::expect_out(buffer)": no such variable.

Thanks, Vamsi

Vamsi