[Scilab-users] Sockets in scilab 6.0

Adrian Weeks aweeks at hidglobal.com
Wed Jun 27 09:18:16 CEST 2018


Hi James,

If I remember correctly, you can have different translation on the input and output channels and I think you need to enclose the parameters in braces:

	"fconfigure $tclsocket1 -blocking 0 -translation {lf binary}"

I also notice that you're using command 'flush'. You could try experimenting with:

	"fconfigure $tclsocket1 -buffering line"

which, I think, causes transmission of the string immediately it gets the LF.
If you haven't seen it already, here's the documentation:

	http://docs.activestate.com/activetcl/8.5/tcl/tcl/TclCmd/fconfigure.html

When I was setting up the TCL functions in Scilab I found it very helpful to install and run TCL itself on my PC. It gives you a small window into which you can type commands directly, to see what happens. I connected an oscilloscope to the serial port to see what came out.

Adrian Weeks.
Engineer, Hardware Engineering EMEA.
Office: +44 (0) 2920 528500 | Direct: +44 (0) 2920 528523 
Email: aweeks at hidglobal.com


HID Global, 3 Cae Gwrydd, Green Meadow Springs, Cardiff, CF15 7AB , United Kingdom
www.hidglobal.com

-----Original Message-----
From: users <users-bounces at lists.scilab.org> On Behalf Of James Holland
Sent: 26 June 2018 19:20
To: users at lists.scilab.org
Subject: Re: [Scilab-users] Sockets in scilab 6.0

For testing I've stripped out all the code and put it into one script so I don't need to keep rebuilding and reloading. What I have now is:


id =1;
commande = "*IDN?";
address = "192.168.1.72"
port = 3000;

// SOCKET_open

	TCL_EvalStr(["set tclsocket"+string(id)+" [socket "+address+"
"+string(port)+"]";"fconfigure $tclsocket"+string(id)+" -blocking 0 -translation binary"]);

//send data
	TCL_EvalStr([	"puts $tclsocket"+string(id)+" """+commande+"""";
					"flush $tclsocket"+string(id)]);

sleep(10);   //100ms wait for data to be returned


//get Data
	mat=[];

	mat=[];
	cmd=["set tclsocketlong 0;";
	"while {$tclsocketlong >= 0} {";
	"set tclsocketlong [gets $tclsocket"+string(id)+" tclsocketligne];";
	"if {$tclsocketlong >= 0} {";
//	"flush $tclsocket"+string(id)+";";

// bug en cas de ""
	
    "ScilabEval ""mat=\[\""[string map {\"" \""\"" \'' \''\''} $tclsocketligne]\"";mat\];""";
//	"ScilabEval ""mat=\[TCL_GetVar(''tclsocketligne'');mat\];""";
	"}";
	"}"];

	res = TCL_EvalStr(strcat(cmd," "));


The scope does send back a response even though I have one linefeed appended. However if I set the translation mode to binary I still get the linefeed. The response from the scope (terminated with a LF) is not being fed back, cmd is an empty matrix. What I really want to do is set outmode to binary and inmode to LF but '-translation lf binary' gives me the following
error:


TCL_EvalStr,  at line 2
	wrong # args: should be "fconfigure channelId ?optionName? ?value?
?optionName value?..."
    while executing
"fconfigure $tclsocket1 -blocking 0 -translation lf binary"



I haven't yet found an example showing inmode outmode





--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
users at lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users



More information about the users mailing list