// Control a GALEP programmer by sending script commands to its GalepX socket
STRING* strScript = // command script that lets GALEP blink its LEDs
"#include \"gxAPI/gxBasic1.h\"
string s = gxGetCurrentEndDevice();
gxDeviceIdentity(s);
";
TEXT* txtReceive = { flags = SHOW; }
function main()
{
// open a TCP socket on GalepX port 1233
if (!socket_connect("localhost",1233,1)) {
printf("Can't connect to GalepX!");
} else
{
// send the script to the socket
var sent = socket_send(_chr(strScript),str_len(strScript));
if (sent) txt_addstring(txtReceive,strScript);
// receive the response
char input[1001];
while(1) {
wait(1);
int received = socket_receive(input,1000);
if (received) {
// display the response
input[received] = 0; // add '0' end mark
txt_addstring(txtReceive,input);
}
}
}
}
See also:
send_data, socket_receive, socket_connect