Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transferring data between Sessions

Status
Not open for further replies.

mdundas

Technical User
May 18, 2003
1
US
I just found this forum and I think that it is great! I have been writing ProComm script programs to support wireless switches for the past 10+ years. I have picked up some excellent tips reading the threads the past two days.

I have programs that run two sessions of ProComm. Each session runs its own script. Is there an easy and effective way to transfer data between the sessions. I am currently creating a file with one session to be read with the other session and vice versa. One session is allowed to access the files on odd seconds, the other on even seconds.

The problem I have is that there are times when both programs try to access the files at the same time.
 
You should be able to use DDE to communicate from one Procomm session to the other, but I have never done this myself. I have a snippet of text at home from somewhere (I thought the readme file, but it's not in there) that mentions this is more difficult than normal because each Procomm session runs in the same thread I believe. I'll dig up that text when I get home tonight and post it here.


aspect@aspectscripting.com
 
DDE would be the preferred method but if your only problem is that both sessions are trying to access the file at the same time, then maybe creating file locks is the answer.

You could have both your scripts create an flag file when accessing the file and delete it when completed. Then each script can look for the other scripts flag file before attempting to access it.

Code:
#script 1
proc main
strings hisflag="flag1",herflag="flag2",myfile="file.txt"
again:
if isfile herflag                ; If other flagfile exists
   pause 1                       ; pause 1 second and
   goto again                    ; try again
else                             ; Otherwise
   fopen 0 hisflag create text   ; Create your Flag File
   fclose                        ;
   fopen 0 myfile readwrite text ; Open your file
                                 ;
   fclose 0                      ; Close your file
   delfile hisflag               ; Delete your flag file
endif
endproc

#script 2
proc main
strings hisflag="flag1",herflag="flag2",myfile="file.txt"
again:
if isfile hisflag                ; If other flagfile exists
   pause 1                       ; pause 1 second and
   goto again                    ; try again
else                             ; Otherwise
   fopen 0 herflag create text   ; Create your Flag File
   fclose                        ;
   fopen 0 myfile readwrite text ; Open your file
                                 ;
   fclose 0                      ; Close your file
   delfile herflag               ; Delete your flag file
endif
endproc
 
Oops, replace "strings" with "string" in the above exmples.
 
Here is the information I mentioned previously:

-----------------------------------------------------------------------------
#9. The RUN command in ASPECT is not giving me the correct Task ID. How do I communicate between two instances of Procomm Plus 4.5x?
-----------------------------------------------------------------------------
This tip applies to Procomm Plus 4.x for Windows.

When using the RUN command, you can obtain the Task ID and you have noticed that it is the same for both instances of Procomm that are running. In fact, the ID obtained is not the Task ID, but the Process ID. No matter how many
instances of Procomm Plus you have running, they all have the same Process ID. So you cannot use the Task ID (or Process ID here) to access the other instances of Procomm.

The book states that you should be able to manipulate a second instance of PW4 by using a specific instance handle:
"use PW4xxxxx, where the digits xxxxx correspond to the unsigned integer value of Procomm Plus's instance handle. You can obtain this handle value from within the ASPECT script by using the run command to launch another instance of Procomm Plus. "

Of course, using the RUN command gets the wrong ID. Additionally, the documentation here is incorrect - the xxxxx has to be replaced by the Thread ID instead of the Task ID (or Process ID). Unfortunately, the Thread ID is not obtainable by ASPECT. Therefore, you find that you cannot manipulate separate instances through their
Task ID and you cannot manipulate more than two instances through DDE.

RESOLUTION:
1) The DDE can be used to access the second instance by using "PW4" as the handle. This seems to work as long as no more instances of Procomm are executed.
2) Write a DLL that makes a Win32 API call to obtain the Thread ID, thereby allowing ASPECT to directly access the multiple instances.

The following example demonstrates how to setup a DDE link with a second instance of Procomm Plus.

proc main
string pathname
integer pwhwnd
long pwchanid

pathname = $pwtaskpath ;Get PW's path.
addfilename pathname "PW4.EXE" ;Add Procomm's EXE.
if run pathname ;Run the program.
pause 2
pwhwnd = $mainwin ;Get the active window ID.
if ddeinit pwchanid "PW4" "System" pwhwnd ;Establish DDE connection.
usermsg "DDE channel successfully established!"
else
errormsg "Error initializing DDE channel"
endif
else ;Problems running program.
errormsg "Error running %s" pathname
endif
endproc


Note: This example requires that new instances of Procomm Plus must receive focus, at least long enough to grab the window ID of the new instance.

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top