• Support
  • Articles
  • Resources
  • Products

Passing Data Between Macros

Moderator: boris

6 postsPage 1 of 1

jcorra
Newbie

Posts:
10
Joined: Mon Mar 06, 2017 4:36 am
by jcorra » Wed Mar 08, 2017 2:19 pm
Is there a way to pass data between macros, or are they pretty much isolated from each (as long as one isn't currently calling another)? For example, if I use the exec to launch another macro that will run at the same time as my current macro, I use the parameters to pass initial information from the calling macro to the called macro, but not actively/dynamically in the middle of the macro. I know that I can use the SendMulticast to send data to the device connected to the other running macro, but the macro won't see it directly (only the possible response from the device). I know that I could use a file to pass data (one macro opens the file inserts the data to pass, closes it, the other macro opens the file, gets the data, replaces it with new data for the other macro, and closes it), but I would have to be very careful on the timing to make sure that both macros aren't trying to open and modify the file at the same time. Is there a more direct way to communicate, or am I trying to do something that is beyond what Tera Term will support?
boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1596
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Wed Mar 08, 2017 3:50 pm
You can try using commands clipb2var and var2clipb, but timing will still be the issue and you will need to make sure Clipboard content is not overwritten by other applications while your macros are exchanging the data.
Thanks.
Best regards,
Boris
IshmaelCallMe
Guru

Posts:
672
Joined: Thu Jan 26, 2006 2:28 am
by IshmaelCallMe » Wed Mar 08, 2017 4:02 pm
I have used gettitle and a autoit program to set title as a poor mans IPC before, but it is pretty limited. There is a better way to use files as communication, though. Create the file with an "address" in the file name, which is the intended recipient, along with a incrementing number to make the file name unique. The recipient macro then deletes each file after reading it. Each macro will only read/delete files that match its own "address". The sending macro should create the file using a dummy name, and then rename it after it is complete in order to prevent the recipient macro from opening the file before it is complete.
jcorra
Newbie

Posts:
10
Joined: Mon Mar 06, 2017 4:36 am
by jcorra » Wed Mar 08, 2017 9:23 pm
Thank you for those suggestions. The method with the file might work pretty well with the FileLock/Unlock since in my application the two macros would be relatively synchronized to each other and could take turns communicating with each other. How does the abbreviation part of the FileLock work? Can it be used to test to see if the file is locked (so for example, I could lock the file before making changes to it and then unlock). If I can check the lock status of the file, then I could follow a procedure something like:

Code: Select all

  1. macro 1 opens unique file N
  2. macro N opens file N
  3. macro N waits for file N to be locked
  4. macro 1 locks file N
  5. macro 1 moves pointer to start of file N
  6. macro 1 modifies file N
  7. macro 1 unlocks file N
  8. macro 1 waits for file N to be locked
  9. macro N waits for file N to be unlocked
  10. macro N locks file N
  11. macro N moves pointer to start of file N and reads info from macro 1
  12. macro N erases contents of file N
  13. macro N then moves pointer back to start of file N and writes data for macro 1
  14. macro N unlocks file N
  15. macro N waits for file N to be locked
  16. macro 1 waits for file N to be unlocked
  17. .
  18. .


The Get/SetEnv would have been a very convenient way to do this, but it seems to not actually change the environmental variables and only modifies some kind of shadow or duplicate of the real system variables that is local to the macro so not visible to other macros.
IshmaelCallMe
Guru

Posts:
672
Joined: Thu Jan 26, 2006 2:28 am
by IshmaelCallMe » Thu Mar 09, 2017 6:33 pm
Looks like if your macros get out of lockstep for any reason, they could both end up waiting for the other to unlock or lock the file. But, good luck and let us know if you get it working reliably.
jcorra
Newbie

Posts:
10
Joined: Mon Mar 06, 2017 4:36 am
by jcorra » Thu Mar 09, 2017 8:09 pm
Yes, I would probably add some kind of timeout just in case they got out of sync.

I also found that if I turn local echo on, then each terminal can "see" what is transmitted out of it by the SendMulticast command from another macro. I can now use this to pass information as long as I am careful about what "extra" data gets sent out to the device connected to each serial port and make sure that it doesn't mess up the device or interfere with the desired communication with the device.

Ideally, I was wanting to set up something like this:
COM1 (connected to itself: RX->TX)=Main macro
COMa (connected to device a)=drone macro sitting and waiting for a character to be received, which it then forwards to the Main macro
.
.
.
COMn (connected to device n)=drone macro sitting and waiting for a character to be received, which it then forwards to the Main macro

The concept was to have multiple serial channels open at the same time, and the Main macro could use the SendMulticast to send a message to the desired device at will, then wait for the response to come back from the device and act on it. The Drone macros would have been launched by the Main macro, which would have assigned a name and COM# to each drone so it would know what names to use. This would have worked fine except that the SendMulticast doesn't let me send 0x00 or 0x01 which are necessary in the serial protocol I am forced to use. I think this concept should work fine for other serial protocols that only use printable characters.

Alternately, I considered making the drones "smarter" and was looking for a way to communicate from the Main macro to a Drone macro when it needed to send a specific message (which would still allow the Main macro to remain in control).
Display posts from previous:
Sort by:

6 postsPage 1 of 1

Users browsing this forum: No registered users
cron