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

Controlling multiple COM ports within one script

Status
Not open for further replies.

patelda7

Programmer
May 29, 2003
6
US
Hi,
We are trying to automate our Modem-like Wireless HW testing which are atteched to multiple COM ports on same machine. Basically I need to send commands and xfer files from one COM ports and verify response and receive file on 2nd COM port. How can achieve this using single script?

Ex.
Send "Connect Device 2" from COM1
I receive "Accept Connection y/n?" on COM2
Send "y" on COM2
I receive "Connection Ready" on COM1

and so on.
Any help is appriciated. Thanks.
 
If you wish to test the same steps over and over, you can record a script with Procomm's Script Recorder that can be used to repeat the same operations over and over. To enable the Script Recorder, select the Tools | Scripts | Start Recorder menu item. Procomm Plus will now monitor all incoming data and your outgoing responses to that data. Start performing the tasks (keyboard-based only!) that you want Procomm Plus to record. Once done, select the Tools | Scripts | Stop Recorder menu item. You will be prompted to save your recorded script; some editing of the script may be necessary. When you view your script, you will see that it is composed of waitfor/transmit commands. If all looks well, compile your script and see if it executes as expected. You will need to add the necessary logic to send or receive a file as the script recorder can only capture keystrokes.



aspect@aspectscripting.com
 
Knob,
Thanks for response. I have already created all scripts for testing. However the problem is I have to run two scripts in two seprate instance of procomm, one for each COM port. Problem here is, timing. Since data and command response are comming immediatly on other side, I need to capture them as I am sending data from one side. The goal is to have one script to control both com ports. Is there anything in ASPECT such as assigning handle when opening new comport so that I can send, receive data from particular handle (comport) and make decisions in scripts.

Thanks
Dharmesh
 
I can't really think of a good way to handle this with just one script since the time to switch from one com port to another after you have sent one string on one port and are waiting for it on another port would be almost instantaneous. You would need to use the set modem connection command to switch from one com port to another, but I don't think it would work very well.

Are the two scripts talking to each other, or communicating through the device?


aspect@aspectscripting.com
 
The following example shows how you can use DDE to write messages in two seperate Procomm windows using a single script. Hope this helps.

Code:
proc main
string pwexe
integer handle2
long window2
clear
termwrites "This message was generated from a script running in this window`r`n`r`n"
pause 5
termwrites "Switching to second window`r`n`r`n"
pause 2
strfmt pwexe "%s\PW5.exe /nostartup" $pwtaskpath
if run pwexe
   pause 2
   handle2 = $mainwin
   while ddeinit window2 "PW5" "System" handle2
      ddeexecute window2 "ASPECTCMD termwrites `"This message was generated from a script running in another window``r``n``r``n`""
      pause 5
      ddeexecute window2 "ASPECTCMD termwrites `"This window will be closing down in 5`""
      pause 1
      ddeexecute window2 "ASPECTCMD termwrites `"``b4`""
      pause 1
      ddeexecute window2 "ASPECTCMD termwrites `"``b3`""
      pause 1
      ddeexecute window2 "ASPECTCMD termwrites `"``b2`""
      pause 1
      ddeexecute window2 "ASPECTCMD termwrites `"``b1`""
      pause 1
      ddeexecute window2 "PWEXIT"
      exitwhile
   endwhile
endif
termwrites "End of example`r`n"
endproc
 
PS: Look under DDE Server Commands in Aspect Help for a list of valid DDE server commands.
 
For your case, I would use the port receiving the input as the main window and the port you are transmitting data on as your second window. Use the ddeinit statement without the while loop at the beginning of your script. Then you can use ddeexecute commands to transmit the strings on the output port, followed by waitfor commands to receive the responses on the input port. For example;
Code:
ddeexecute window2 "TRANSMIT `"foo^M`""
waitfor "bah"
ddeexecute window2 "TRANSMIT `"hello^M`""
waitfor "goodbye"
Personally, I have never needed to use this scenario so I can not guarantee whether it will work or not. Let us know how it goes.

PS: Don't forget to use the ddeterminate command
ie. ddeterminate window2
at the end of the script to drop the DDE link between the two Procomm windows.
 
Thanks guys,
We are making progress here with dde commands. Limitation of sending from one port and receiving on other port is resolved. I have also utilized "EXECUTE" commnad to run different script on 2nd window which helps to do 'waitfor' on second window as well. Only the missing piece is how to pass variables and results from/to main script. Is there any super GLOBAL varibles, I could not find anything in "chain", "execute" commands.

Just to describe little more on what I am working on. We have wireless device whcih can be used as wireless modem. I am trying test all features by atteching two modems on my PC, and sending commands from one modem and validating responses on second modem. There are lots of features such as security, bonding, etc, which requires commands to be entered on both side such as pin codes to make connection successful. Once connection is up, I send or receive files from one end to other.

This also bring another issue which would be good to utilize is to if there is a way to check CRC errors during file transfer and report at end of test or capture it in some variable.

Thanks
Dharmesh
 
One more thing,
konb mentiond that we can change com port in Modemsetup. What is syntex for this command?

Dharmesh
 
There are 40 Global variables that once set, remain constant until changed. These can be used between scripts. These variables are as follows;

s0 through to s9 are global string variables
i0 through to i9 are global integer variables
l0 through to l9 are global long variables
f0 through to f9 are global float variables

You can set the device or port to use using the set modem connection command. For example;

set modem connection "direct connect-Com1"

As for CRC checking, there is a crc16 command to check a string but I am not familiar with using it. However, Procomm does have a variable called $XFERSTATUS which indicates the status of the current file transfer. When no file transfer is in progress it is set to 0. When file transfer is in progress it is set to 1. When a transfer is completed successfully it is set to 2 and when a file transfer is aborted it is set to 3.
 
Another way of passing a single integer variable from a child to a parent script would be to use an exit code. If you exit your child script with an exit code ie. exit 42, then the $EXITCODE variable (which will be set at 42) can be read by the parent script to determine the childs status.
 
This is just great! you have all answers. Both commands Global, and setModem works perfect.

If it is not too much, I want to ask one more question. I have spent several hours but haven't figure this out. Like modem, I have similar wireless device, which does not have modem tone, but rather it can be used as normal serial connection (cable replacement). Similary modem scripts, I want to run some scripts on serial connection using dialing directory with script associated with each entry. But everytime I start calls, it gives me warning from Window Telephony "procomm is unable to use this connection". Is there any way I can use dialing directory to run some scripts on normal serial connection?

Thanks a lot for your help
Dharmesh
 
Unfortunately, Procomm will not use a direct connection to dial a dialling directory entry. A way to get around this is to extract the information required from the dialling directory and then use at commands to dial. See example below.
Code:
proc main
string AC ; string to contain Area Code
string CC ; string to contain Country Code
string PH ; string to contain Phone Number

dialload "PW5.DIR"                      ; load dialling directory
set dialentry access DATA "My Entry"    ; access entry required
fetch dialentry areacode AC             ; get area code
fetch dialentry country CC              ; get country code
fetch dialentry phonenumber PH          ; get phone number

set modem connection "direct connect-Com1"

commandmode on                          ; turn on modem command mode
transmit "atd"                          ; transmit at commands to
transmit CC                             ; dial country code
transmit AC                             ; area code and
transmit PH                             ; phone number
transmit "^M"
waitfor "CONNECT" 60                    ; wait 60 secs for connect msg

if $CARRIER                             ; if connection successful
   ; carry on running script
   
else                                    ; if no connection made
   ; process connection error
   
endif
endproc
When normally dialling through the dialling directory, you can use the $CNCTMSG variable to determine the connection status and/or reason for connection failure. However, I do not know whether this will work when manually dialled as shown above.

 
PS: Just a tip, some modems expect a response (ie.dial tone) before dialling out. If this causes a problem, the at command ATX0 will turn off response codes on most hayes compatible modems. Running this command before the ATD command should negate the need for your device to provide a dial tone.
 
Thanks,
Seems like this solution is similar to what I ended up using. Which is creating text file which contains scripts as well as other information as far as which port to execute the script.

As far as switching com port using modemsetup command, I sometimes gets comport lockup and when I restart the scipt,it goes back to normal. Just wondering if anyone seens this problem.

Dharmesh
 
Sorry, I haven't experienced that problem before. Perhaps your script is still doing some processing at the time you are switching ports. Try inserting a slight pause just before execute the set modem command. The pause length doesn't need to be very long. Adding a pause should let the script catch up to where you are before switching the port.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top