Document directory
- 2.1 send a large number of commands
- 2.2 Automatic Test
1. Serial Port script
Some serial port tools (such as serial port debugging Assistant) have the timed sending function, but only one fixed command can be sent. I need to send hundreds of commands and want to find a tool that can execute serial port scripts. Then I foundProcomm plus.
Procomm plus has many features. I only need the serial port script function, so I didn't execute the installer. After decompression, I directly run pw5.exe in the programs directory. Select Options-> System Options-> Modem connection... from the menu, and select the serial port or modem to be opened from the "current modem/connection" drop-down list. You can click and set the encoding format and baud rate at the bottom of the main window. The encoding format can be raw ASCII. In the main window, you can directly tap the AT command to see the response, which is similar to that of the Super Terminal.
Select Tools> scripts from the menu to view the script-related menus, including execution, compilation, editing, and recording scripts. The procomm plus script system is called aspect. It has powerful functions and can define variables, process control such as for and while, and even accept user input dialog boxes. Procomm plus has complete tutorials and help documentation.
Of course, I will not read the document first. The first step is to record a script to see what it looks like, and then write your own script. The source file of the script is a file suffixed with was. The source file can be run only after compilation. The suffix of the compiled file is wax.
If you only want to use the serial port Script Function, do not install procomm plus and run it directly. After the installation, all modem instances are detected at each startup, which is a waste of time.
2 script example 2.1 send a large number of commands
One thing I want to do is patch a modem and send more than two hundred commands. For example:
AT:PIBAT:Pf800,7b5d,4dc,7b5f,4de,7b59,4d8,7b5b,4daAT:Pf808,7b55,4d4,7b57,4d6,7b51,4d0,7b53,4d2...
The modem responds to these commands as "/R/NOK/R/N ". Through the recorded script, you can see the process of sending commands and waiting for a response. You can use the following statement to complete the process:
transmit "AT:PIB^M" waitfor "K^M^J"
Apparently, transmit is written to the serial port. Waitfor is waiting for a response. ^ M is the carriage return 0d (that is,/R), ^ J is the linefeed 0a (that is,/N ). The waitfor statement waits for the last three characters of the normal response. After reading these two sentences, the script is a simple replacement of the command to be sent. My commonly used text editor is written by myself.Cnbook. Set the beginning of the line in cnbook
^
Replace
transmit "
End the line
$
Replace
^M"/n waitfor "K^M^J"
Select "Regular Expression" for replacement ". Place the replaced text
proc mainendproc
. The complete script looks like this:
proc main transmit "AT:PIB^M" waitfor "K^M^J" transmit "AT:Pf800,7b5d,4dc,7b5f,4de,7b59,4d8,7b5b,4da^M" waitfor "K^M^J" transmit "AT:Pf808,7b55,4d4,7b57,4d6,7b51,4d0,7b53,4d2^M" waitfor "K^M^J"...endproc
In the future, I need to install a patch. When I execute more than two hundred commands, I only need to execute this script.
2.2 Automatic Test
I need to press the serial port to test a device. I recorded a test process, and then used the for loop to automatically test 100 times. The script looks like this:
proc main integer Num ; Integer variable to increment. for Num = 0 upto 100 ; Init variable and define loop. transmit "o" waitfor "wait ..." transmit "1" waitfor "wait ..." transmit "0" waitfor "wait ..." transmit "0" waitfor "wait ..." transmit "0" waitfor "xt_connected_enter^M^J" transmit "p" waitfor "xt_idle_enter^M^J"... endforendproc
Of course, in many cases, manual testing is easier to detect problems than automatic testing. However, using a serial port script for automatic testing can also be used as an auxiliary means.
3 conclusion
Procomm plus has many other features, and its script system aspect has far more functions than that. But currently I only use this.