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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access to 2 sessions of Procomm

Status
Not open for further replies.

SAMMEE2

Technical User
Apr 16, 2004
61
US
I've tried to research this, but I can't find exactly what I want to do.

I have 3 Procomm sessions open all the time, they communicate with 3 different phone switches via direct connect com1, com2 & com3.

How can I( is it possible? ) have a script running in one session enact commands into the other sessions?

For instance if I start the following script and have it run on each com port.

Proc Main
integer iDay, iMonth, iYear, iMin, iHour, iSec
string sSend

ltimeints $LTIME iYear iMonth iDay iHour iMin iSec

strfmt sSend "STAD %02d %02d %d %02d %02d %02d" iDay iMonth iYear iHour iMin iSec
set txpace 15
transmit "****^M"
waitfor ">"
transmit "ld 2^M"
waitfor "."
transmit "TTAD^M"
waitfor "."
transmit sSend
transmit "^M"
waitfor "."
pause 2
transmit "TTAD^M"
waitfor "."
pause 2
transmit "****^M"


; I can't use a [ set modem connection "direct connect-Com2" ] here because com2 is already running.

EndProc

Ideally I'd like to be able to run a script in say com1 and have it be able to go to com2 or com3 execute whatever commands and then come back to the original com1.

Is DDE the only way? If it is I can't figure out how to know what the specific session names are.





 
DDE is really the only way to do this. I have a couple sample scripts that show how to do this on the samples page of my site. Basically you will need one master session that launches the additional Procomm sessions, which will give you the task ID to reference the child sessions via DDE.

 
Basically you will need one master session that launches the additional Procomm sessions, which will give you the task ID to reference the child sessions via DDE.

I can use the following script to initially launch the other sessions. I normally never stop them so they stay running all of the time.

I don't understand where or how I see this task ID. This script seems to say to show it, but I don't know where to look to see it.


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


 
I've added this before the "endproc" in the above example.

USERMSG "`"%s`" PATH OF `"%i`"." PATHNAME PWHWND

I'm unclear if the number provided here is the task ID.

This is from some help files and appears to me to be double talk.

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.
 
Here is an example from my site:

proc main
string pathname
integer pwhwnd
long pwchanid

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

It uses ddexecute to have the child session run the HINTS scripts. You can access just about any Procomm functionality in the child script via ddeexecute (the help file should have the correct syntax to use).

 
I'm going to have to do some more studying.

While this will open another Procomm session and run commands in it.
The key thing for me is how to access and run commands in another already running Procomm session.

That's the part that currently eludes me.
 
The only really good way to have one session of Procomm run commands (or really, instruct to run commands) in another Procomm window is via the DDE method above. In your case, you could keep the three (I believe?) Procomm windows that you need open for each com port. After you have launched the two child sessions from the main session, you can send commands via DDE, using the same handle, as long as you don't close either of the child sessions. So basically I think you have what you need, you'll just need to have a parent script that launches the two child sessions of Procomm, and then the proper method/scheduling in that main script to send commands and receive responses from the two child sessions. Does that sound like it will work?


 
I'm losing it at "handle".
The above script opens another session each time, doesn't it?
I don't know how to address it after it has been opened.
 
Try taking a look at the script here:


I forgot that I had that on the site, but it shows how to launch two different Procomm sessions and how to access them.

For your case, you would want to run the script at the link above in your main Procomm window to open the two child windows. Once you have done that, you can access those two child windows (see the ddeexecute commands in the script) whenver necessary.


 
Thanks very much, I'll see if I can make that work for me.
 
Not having much success ,I'm afraid. I can get it to open the "child" sessions and get it to run a script in it...but, I can't then readdress it. I get a DDE failed to initialize from a user msg I inserted.

I'm guessing the global variable that "sees' it initially is lost when a new script is run.

I seldom close the Procomm sessions so getting it to "talk" to a running session is vital.
 
Yes, It works, but as I say I am not able to readdress it without closing and re-opening the session, which is unsuitable.
 
After you have made the initial DDE connection, you can just issue a second ddeexecute command to have the child script run the command you desire. Your parent script (unless it has been closed) will still have the DDE channel number (the pwchanid variable in my sample) that can be used to access the child session.

 
This works, will work on Procomm 4.7 or 4.8. Make sure you edit the PW4 to be PW5 if that's what you have.

This parent will open 2 other sessions that will communicate with each other. I close the parent after the 2 child sessions are opened.

proc main

string szFnamea = "tida.txt"
string szFnameb = "tidb.txt"
string szFnamec = "tidc.txt"
string szFnamed = "tidd.txt"
string wida, widb, widc, widd

s0 = $pwtaskpath
s1 = $pwtaskpath
addfilename s0 "PW4.EXE"
addfilename s1 "PW4.EXE"
if run s0
pause 5
i1 = $mainwin
if run s1
pause 5
i2 = $mainwin
if ddeinit l1 "PW4" "System" i1 ;Establish DDE connection with first instance.
; ddeexecute l1 "EXECUTE test3.WAX"
else
errormsg "Error initializing DDE channel"
endif
if ddeinit l2 "PW4" "System" i2 ;Establish DDE connection with second instance.
; ddeexecute l2 "EXECUTE test4.WAX"
else
errormsg "Error initializing DDE channel"
endif
endif
else ;Problems running program.
errormsg "Error running %s" s0
endif


fopen 0 szFnamea CREATE text
ltoa l1 wida
fputs 0 wida

fopen 1 szFnameb CREATE text
itoa i1 widb
fputs 1 widb

fopen 2 szFnamec CREATE text
ltoa l2 widc
fputs 2 widc

fopen 3 szFnamed CREATE text
itoa i2 widd
fputs 3 widd

fclose 0
fclose 1
fclose 2
fclose 3

endproc

Child 1 example:
proc main
string szFnamec = "tidc.txt"
string szFnamed = "tidd.txt"
string widc
string widd
long pwchanid2
integer pwhwnd2
fopen 0 szFnamec read
fgets 0 widc
fopen 1 szFnamed read
fgets 1 widd
fclose 0
fclose 1
atol widc pwchanid2
atoi widd pwhwnd2

usermsg "pwchanid2 %ld" pwchanid2
usermsg "pwhwnd2 %i" pwhwnd2


if ddeinit pwchanid2 "PW4" "System" pwhwnd2
ddeexecute pwchanid2 "EXECUTE hints.WAX"
endif
endproc

Child 2 Sample:
proc main
string szFnamea = "tida.txt"
string szFnameb = "tidb.txt"
string wida
string widb
long pwchanid1
integer pwhwnd1
fopen 0 szFnamea read
fgets 0 wida
fopen 1 szFnameb read
fgets 1 widb
fclose 0
fclose 1
atol wida pwchanid1
atoi widb pwhwnd1

usermsg "pwchanid1 %ld" pwchanid1
usermsg "pwhwnd1 %i" pwhwnd1

if ddeinit pwchanid1 "PW4" "System" pwhwnd1
ddeexecute pwchanid1 "EXECUTE startup.WAX"
endif
endproc

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top