How to implement synchronous in Live code

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

How to implement synchronous in Live code

Post by QuangNgo » Mon Dec 12, 2011 5:11 am

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to implement synchronous in Live code

Post by Mark » Mon Dec 12, 2011 6:05 am

Quang,

How exactly do you start the Java process? You might want to try "open process".

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

Re: How to implement synchronous in Live code

Post by QuangNgo » Mon Dec 12, 2011 7:08 am

Thanks Mark,

Here the way I start Java console

Code: Select all

put "java -jar Demo.jar" into tCommand
   get shell(tCommand)

Regards,
Quang

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to implement synchronous in Live code

Post by Mark » Mon Dec 12, 2011 12:17 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

Re: How to implement synchronous in Live code

Post by QuangNgo » Tue Dec 13, 2011 11:06 am

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to implement synchronous in Live code

Post by Mark » Tue Dec 13, 2011 1:33 pm

Quang,

Can you post (the relevant part) of your script?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

Re: How to implement synchronous in Live code

Post by QuangNgo » Wed Dec 14, 2011 10:13 am

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to implement synchronous in Live code

Post by Mark » Wed Dec 14, 2011 1:19 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

Re: How to implement synchronous in Live code

Post by QuangNgo » Thu Dec 15, 2011 8:12 am

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

Bicgatepc02
Posts: 3
Joined: Fri Feb 22, 2013 11:44 am

Re: How to implement synchronous in Live code

Post by Bicgatepc02 » Sat Feb 23, 2013 7:13 am

whats it like on windows?

Post Reply