Re: [eclipse-clp-users] Problem with embedding into TCL/TK

From: Joachim Schimpf <jschimpf_at_...311...>
Date: Fri, 25 May 2018 00:45:59 +0100
On 23/05/18 16:53, Michael Maisuradze via ECLiPSe-CLP-Users wrote:
> 
> Hello,
> I am working on a project that is mainly built with eclipse prolog.
> Evidently for some part of our project I needed to implement graphical 
> interface, and started to try with TCL/TK.
> 
> My objective is to call certain prolog predicates from the Graphical Interface, 
> and then receive the output in TCL/TK in a manner that I would be able to 
> structure and display the output as an organized table. So far what I could do 
> is to just redirect the output of prolog to the TCL/TK program window frame.
...
> 
> To get structured data from eclipse to TCL I did as described in the Manual.
> 
> In TCL:
> set my_in_channel  [ec_queue_create my_out_queue fromec]
> set result  [ec_read_exdr $my_in_channel]
> 
> In Eclipse:
> write_exdr(my_out_queue,  [FSPA, SSPA, TSPA,FPPA,SPPA,TPPA] ),
> flush(my_out_queue).
> 
> What I wanted to get was the *result* variable in TCL with the list of a data 
> provided from prolog output. And this should have worked according to embedding 
> manual. Unfortunately I get an error
> Error in startup script: conversion error while reading exdr format
>     while executing
> "ec_read_exdr $my_in_channel"


Hi Michael,

you are probably trying to read data on the TCL side _before_ it has been 
written on the ECLiPSe side.

You should call ec_read_exdr only from inside a TCL handler that is invoked when 
data arrives on the channel.  Your TCL code should roughly look like this:

     set my_in_channel [ec_queue_create my_out_queue fromec my_handler]

     proc my_handler {stream_nr} {
         set channel [ec_streamnum_to_channel $stream_nr]

         set result [ec_read_exdr $channel]

         # do something with $result here!
     }

The my_handler will be invoked every time the ECLiPSe-side flushes my_out_queue. 
The handler then reads the term that the ECLiPSe-side has written before the flush.

Note that all operations here are serialised:
1. ECLiPSe side writes data, which goes into a buffer
2. ECLiPSe side flushes; this transfers control to the TCL side
3. TCL side executes handler, which can read data from the buffer
4. when handler finishes, control returns to ECLiPSe


Hope this helps,

Joachim
Received on Thu May 24 2018 - 23:46:12 CEST

This archive was generated by hypermail 2.3.0 : Thu Feb 22 2024 - 18:13:20 CET