To create a communication channel between ECLiPSe and Tcl, first create an ECLiPSe queue stream using ECLiPSe's open/3 or open/4 predicate, then connect that stream to a Tcl channel by invoking the ec_queue_connect command from within Tcl code.
ec_queue[ec_stream_nr eclipse_stream_name]If a command argument is provided, this command is set as the handler to be called when data needs to be flushed or read from the channel (see ec_set_queue_handler).
ECLiPSe: open(queue(""), write, my_out_queue). Tcl: set my_in_channel [ec_queue_connect my_out_queue r]Now the queue can be used, e.g. by writing into it with ECLiPSe's write/2 builtin, and reading using Tcl's read command:
ECLiPSe: write(my_out_queue, hello). Tcl: set result [read $my_in_channel 5]The disadvantage of using these low-level primitives is that for reading one must know exactly how many bytes to read. It is therefore recommended to use the EXDR (ECLiPSe external data representation, see section 5.6) format for communication. This allows to send and receive structured and typed data. The primitives to do that are write_exdr/2 on the ECLiPSe side and ec_read_exdr (section 5.6) on the Tcl side:
ECLiPSe: write_exdr(my_out_queue, foo(bar,3)). Tcl: set result [ec_read_exdr $my_in_channel]In the example, the Tcl result will be the list {foo bar 3}. For details about the mapping see section 5.6.
ECLiPSe: open(queue(""), read, my_in_queue) Tcl: set my_out_channel [ec_queue_connect my_in_queue w]Now the queue can be used, e.g. by writing into it with Tcl's puts command and by reading using ECLiPSe's read_string/4 builtin:
Tcl: puts $my_out_channel hello ECLiPSe: read_string(my_in_queue, "", 5, Result).The disadvantage of using these low-level primitives is that for reading one must know exactly how many bytes to read, or define a delimiter character. It is therefore recommended to use the EXDR (ECLiPSe external data representation, see section 5.6) format for communication. This allows to send and receive structured and typed data. The primitives to do that are ec_read_exdr (section 5.6) on the Tcl side and read_exdr/2 on the ECLiPSe side:
Tcl: ec_write_exdr $my_out_channel {foo bar 3} (SI) ECLiPSe: read_exdr(my_in_queue, Result).In the example, the ECLiPSe result will be the term foo("bar",3). For details about the mapping see section 5.6.