Page 1 of 1
How to implement synchronous in Live code
Posted: Mon Dec 12, 2011 5:11 am
by QuangNgo
Dear all,
I do all researching on the internet about how to implement synchronous communication among cards. Let me explain it more specific for you guys understand what I am doing.
I have the application which is written by java console.There is one module in my application invoke this Java console.Everything is work really well if I only use it individual.However, I am not able to work with other modules at the same time. I meant that if you want to execute Java console while you are doing other modules such as retrieve data from mySQL, you have to wait until Java console is finished.
Is there any way to work simultaneously among these modules. Could you please give me some advise for this issue ?
Thanks a lot for your help
Regards,
Quang
Re: How to implement synchronous in Live code
Posted: Mon Dec 12, 2011 6:05 am
by Mark
Quang,
How exactly do you start the Java process? You might want to try "open process".
Mark
Re: How to implement synchronous in Live code
Posted: Mon Dec 12, 2011 7:08 am
by QuangNgo
Thanks Mark,
Here the way I start Java console
Code: Select all
put "java -jar Demo.jar" into tCommand
get shell(tCommand)
Regards,
Quang
Re: How to implement synchronous in Live code
Posted: Mon Dec 12, 2011 12:17 pm
by Mark
Hi Quang,
Yes, you need to try open process if you want to read from/write to the process or you could even use the launch command if you don't need to communicated with the process.
Kind regards,
Mark
Re: How to implement synchronous in Live code
Posted: Tue Dec 13, 2011 11:06 am
by QuangNgo
Hi Mark,
I try to use "open process" but it seem to be not working. I am not able to use other functions at the same time. Must wait until the console is finished.
Regards,
Quang
Re: How to implement synchronous in Live code
Posted: Tue Dec 13, 2011 1:33 pm
by Mark
Quang,
Can you post (the relevant part) of your script?
Mark
Re: How to implement synchronous in Live code
Posted: Wed Dec 14, 2011 10:13 am
by QuangNgo
Hi Mark,
just let you know clearly what i am doing:
1.Java console: will loop 10 times and within 10 times if user give their card ,the result will be the number.
2.Live code: Open main menu with many user tasks and "ReadCard"card is the one of these. For example, I will open "User"cards retrieving user information and also open "ReadCard" card.As we discuss before, I can't use "User" card until Java console is finished.
Here is my code, That work well except one thing is to work simultaneously.
Code: Select all
open process "java -jar Demo.jar" for read
repeat forever
put empty into it
set the defaultfolder to "C:\"
read from process "java -jar Demo.jar" for -1 line
if it is a number then ---return ID card
put it into cd fld "FIDCard"
close process "java -jar Demo.jar"
exit repeat
end if
if it contains "Time out" then --After 10 seconds
answer info "Time out"
exit repeat
end if
end repeat
Regards,
Quang
Re: How to implement synchronous in Live code
Posted: Wed Dec 14, 2011 1:19 pm
by Mark
Hi Quang,
The problem is that your repeat loop blocks the interface. It has nothing to do with the jar or with using cards or anything else. Any repeat loop, e.g.
Code: Select all
put 0 into x
repeat
add 1 to x
wait 1 tick
if x > 180 then exit repeat
end repeat
will lock up LiveCode completely for 3 seconds.
You need to read from process with message:
Code: Select all
...
-- somewhere in a handler
read from process "java -jar Demo.jar" for -1 line with message "rcvData"
...
-- different handler
on rcvData theData
if it is a number then
...
end if
end rcvData
You'll also need a line to kill the process, e.g.
Code: Select all
...
send "killProcess" to me in 10 seconds
...
on killProcess
close process "java -jar Demo.jar"
end killProcess
Actually, the close process command didn't work in previous versions of LC. If this doesn't work, you might be able to use the kill command (which didn't work in previous version of LC either) or use a shell command to kill the process.
This video tells a little more about using processes.
Kind regards,
Mark
Re: How to implement synchronous in Live code
Posted: Thu Dec 15, 2011 8:12 am
by QuangNgo
Hi Mark,
I resolved the problem. I still use get shell(tCommand).However, turn off loop in Java console. Now it work fine.
Thank you very much for your help
Regards,
Quang
Re: How to implement synchronous in Live code
Posted: Sat Feb 23, 2013 7:13 am
by Bicgatepc02
whats it like on windows?