Home
-> User's Manual -> Process Contoller -> Decoder Example

Mixing External Programs with Pac-n-Zoom Macros

To test the decoder, open the *.PZH files that are generated after running the encoder code from within the Pac-n-Zoom. Then save them as a CDL. The CDL file goes into the golden directory for this case, the golden directory is "CDL_gld". For a multiple page document, open each page and write a CDL golden files. To test it, you would have to compare each page separately.

dcc.pzm:
This macro output the CDL files from the *.PZH files obtained after running db1.pzm from within the Pac-n-Zoom. The macro can be generated by setting the Pac-n-Zoom macro recording feature on while creating the CDL golden files.To test a multiple page document(mul-AB.pzh & mul-AD.PZH), go to each page and write the CDL files, to do this, click on the view button on the GUI, select the option "Go to Page", from the View drop down menu. This option will help in turning the pages as shown in the following loop.
%Description="CDL files "
Open("C:\Program Files\Colorcom\files\rose-3.pzh")
SaveAs("C:\Users\Administrator\cdl_gld\rose-3.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\ppr-es.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\ppr-es.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\r.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\r.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\timrom41.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\timrom41.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\mul-AB.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\mul-AB-A.CDL")
GoToPage(2)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AB-B.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\mul-AD.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-A.CDL")
GoToPage(2)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-B.CDL")
GoToPage(3)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-C.CDL")
GoToPage(4)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-D.CDL")
Done()
Stop()


After creating the above golden files, stop the macro recording session. Run the macro from within the Pac-n-Zoom to output the CDL test files, then diff ( download if you need it) the CDL test files and CDL golden files using the DOS PROMPT:
diff -b rose-3.CDL CDL_gld\\rose-3.CDL

dcc2.pzm:
This macro opens the *.PZH files generated after running db3.pzm from within the Pac-n-Zoom then it converts them to CDL. For a multiple page document(dh_1-10.pzh), turn each page and save as CDL.This macro is also generated by turning on the Pac-n-Zoom macro recording feature while creating the CDL golden files. The recorded macro is ran from within the Pac-n-Zoom and the test files and golden files are compared using the DOS PROMPT.
%Description="CDL files "
Open("C:\Program Files\Colorcom\files\rose-3.pzh")
SaveAs("C:\Users\Administrator\cdl_gld\rose-3.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\ppr-es.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\ppr-es.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\r.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\r.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\timrom41.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\timrom41.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\mul-AB.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\mul-AB-A.CDL")
GoToPage(2)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AB-B.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\mul-AD.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-A.CDL")
GoToPage(2)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-B.CDL")
GoToPage(3)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-C.CDL")
GoToPage(4)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-D.CDL")
Done()
Stop()
After creating the above golden files, stop the macro recording session. Run the macro from within Pac-n-Zoom to output the CDL test files, then diff ( download diff if you need it) the CDL test files and CDL golden files using the DOS PROMPT:
diff -b rose-3.CDL CDL_gld\rose-3.CDL

dcc2.pzm:
This macro opens the *.PZH files generated after running db3.pzm from within the Pac-n-Zoom then it converts them to CDL. For a multiple page document(dh_1-10.pzh), turn each page and save as CDL.This macro is also generated by turning on the Pac-n-Zoom macro recording feature while creating the CDL golden files. The recorded macro is ran from within the Pac-n-Zoom and the test files and golden files are compared using the DOS PROMPT.
%Description="This macro test the decoder code"
Open("C:\Program Files\Colorcom\files\rose-3g.pzh")
SaveAs("C:\Users\Administrator\cdl_tst\rose-3g.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\e-gld.pzh")
SaveAs("C:\Users\Administrator\cdl_tst\e-gld.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\r-gld.pzh")
SaveAs("C:\Users\Administrator\cdl_tst\r-gld.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\dh_1.pzh")
SaveAs("C:\Users\Administrator\cdl_tst\dh_1.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\dh_1-10.pzh")
SaveAs("C:\Users\Administrator\cdl_tst\dh_1-1.CDL")
GoToPage(2)
SaveAs("C:\Users\Administrator\cdl_tst\dh_1-2.CDL")
GoToPage(3)
SaveAs("C:\Users\Administrator\cdl_tst\dh_1-3.CDL")
GoToPage(4)
SaveAs("C:\Users\Administrator\cdl_tst\dh_1-4.CDL")
GoToPage(5)
SaveAs("C:\Users\Administrator\cdl_tst\dh_1-5.CDL")
GoToPage(6)
SaveAs("C:\Users\Administrator\cdl_tst\dh_1-6.CDL")
GoToPage(7)
SaveAs("C:\Users\Administrator\cdl_tst\dh_1-7.CDL")
GoToPage(8)
SaveAs("C:\Users\Administrator\cdl_tst\dh_1-8.CDL")
GoToPage(9)
SaveAs("C:\Users\Administrator\cdl_tst\dh_1-9.CDL")
GoToPage(10)
SaveAs("C:\Users\Administrator\cdl_tst\dh_1-10.CDL")
Done()
Stop()

The above macros are then implemented with the master script to test the golden and the test files. This is how the master script would look like:

# #############################
# Example Python Control Script
# #############################

# ================
# Import Libraries
# ================

import socket
import sys
import os
from time import strftime, sleep

# ===========
# Define Data
# ===========

# --------------------------
# Message Control Characters
# --------------------------

ExecuteTaskMessage = '#'
TaskCompletedMessage = '@'
OKMessage = '?'

# -------------
# Program Names
# -------------

PROCESS_CONTROLLER = 'ProcessController'
PAC_N_ZOOM = 'Pac-n-Zoom'

# --------------------
# Program Socket Ports
# --------------------

PC_PORT = '5098' # Character Script-ProcCont Port Number
I_PC_PORT = 5098 # Integer Script-ProcCont Port Number
PZ_PORT = '5099' # Character ProcCont-Pac-N-Zoom Port Number

CONTROL_SCRIPT_DOMAIN = socket.gethostname()
# Use this to
# get Domain
# Name where
# Control
# Script is
# executing
CONTROL_SCRIPT_IP = socket.gethostbyname(CONTROL_SCRIPT_DOMAIN) # Use this to
# get Control
# Script IP
# address
pid = os.getpid()

PythonHeader = ': Python Script PID=%(pid)04d: ' % vars()

FileName = 'py__%(pid)04d.log' % vars()
flog = open(FileName, 'w')

# =========
# Functions
# =========

# -----------------------
def ScriptExit(ExitCode):
# -----------------------

# -----------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sPython Shutting Down\n' % vars())
flog.flush()
# -----------------------------------------------------------------

s.close()
flog.close()
sys.exit(ExitCode)

# -----------------------------------------
def PCSend(ProcessName, SendData, DoPrint):
# -----------------------------------------

while 1:
try:
# -------------------------------------------------------------------------------
if DoPrint is 1:
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sSending \"%(SendData)s\" to %(ProcessName)s\n' % vars())
# -------------------------------------------------------------------------------
s.send(SendData)
except socket.error, msg:
# ---------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sProcess Controller Socket send() Error - Shutting Down\n' % vars())
# ---------------------------------------------------------------------------------------
ScriptExit(1)
return

# ---------------------------------------
def PCSendMessage(ProcessName, SendData):
# ---------------------------------------

PCSend(ProcessName, SendData, 1)
RecvOKMessage(ProcessName)

# ---------------------------------------
def PCSendMacro(MacroName):
# ---------------------------------------

fmac = open(MacroName, 'r')

while 1:
string = fmac.readline()
if len(string) is 0:
fmac.close()
return
PCSendMessage(PAC_N_ZOOM, string)

# ---------------------------
def ExecuteTask(ProcessName):
# ---------------------------

# ------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sSending ExecuteTaskMessage to %(ProcessName)s\n' % vars())
# ------------------------------------------------------------------------------

PCSend(ProcessName, ExecuteTaskMessage, 0)

# ----------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sListening for TaskCompletedMessage from %(ProcessName)s\n' % vars())
# ----------------------------------------------------------------------------------------

RecvData = ' '
while 1:
try:
RecvData = s.recv(1024)
if RecvData[0] is not TaskCompletedMessage[0]:
# -------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived \"%(RecvData)s\" from %(ProcessName)s\n' % vars())
flog.write('%(LogHeader)sExpected TaskCompletedMessage - Shutting Down\n' % vars())
# -------------------------------------------------------------------------------
ScriptExit(1)
# -----------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived TaskCompletedMessage from %(ProcessName)s\n' % vars())
# -----------------------------------------------------------------------------------
except socket.error, msg:
# ---------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sProcess Controller Socket recv() Error - Shutting Down\n' % vars())
# ---------------------------------------------------------------------------------------
ScriptExit(1)
return

# -----------------------------
def RecvOKMessage(ProcessName):
# -----------------------------

# -----------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sListening for OKMessage from %(ProcessName)s\n' % vars())
# -----------------------------------------------------------------------------

RecvData = ' '
while 1:
try:
RecvData = s.recv(1024)
if RecvData[0] is not OKMessage[0]:
# -------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived \"%(RecvData)s\" from %(ProcessName)s\n' % vars())
flog.write('%(LogHeader)sExpected OKMessage - Shutting Down\n' % vars())
# -------------------------------------------------------------------------------
ScriptExit(1)
# ------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived OKMessage from %(ProcessName)s\n' % vars())
# ------------------------------------------------------------------------
except socket.error, msg:
# ---------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sProcess Controller Socket recv() Error - Shutting Down\n' % vars())
# ---------------------------------------------------------------------------------------
ScriptExit(1)
return

# ----------------------
def SendRecvOKMessage():
# ----------------------

RecvData = ' '

while 1:
try:
# ------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sSending OKMessage to Process Controller\n' % vars())
# ------------------------------------------------------------------------

s.send(OKMessage)

# --------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sListening for OKMessage from Process Controller\n' % vars())
# --------------------------------------------------------------------------------

RecvData = s.recv(1024)

if RecvData[0] is not OKMessage[0]:
# ----------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived \"%(RecvData)s\" from Process Controller\n' % vars())
flog.write('%(LogHeader)sExpected OKMessage - Shutting Down\n' % vars())
# ----------------------------------------------------------------------------------
ScriptExit(1)
break

except socket.error, msg:

# --------------------------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sSleeping to give the Process Controller time to Open Socket and Respond\n' % vars())
# --------------------------------------------------------------------------------------------------------

sleep(1)

# ---------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived OKMessage from Process Controller\n' % vars())
# ---------------------------------------------------------------------------

# ================
# End of Functions
# ================

# ==================
# Python Main Script
# ==================

# --------------------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sCreating Socket to communicate with the %(PROCESS_CONTROLLER)s\n' % vars())
# --------------------------------------------------------------------------------------------------

s = None
while 1:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
s = None
continue
try:
s.connect((CONTROL_SCRIPT_IP, I_PC_PORT))
except socket.error, msg:
s = None
continue
break

if s is None:
# ----------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sPython Socket Open Error - Shutting Down\n' % vars())
# ----------------------------------------------------------------------------
sys.exit(1)

# ---------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sConnected\n' % vars())
# ---------------------------------------------

#-----------------------------------------------------------
# Send and then Receive OKMessage to/from Process Controller
#-----------------------------------------------------------

SendRecvOKMessage()

# ---------------------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)s%(PROCESS_CONTROLLER)s has opened the socket for communications\n' % vars())
# ---------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sPython can now talk to %(PAC_N_ZOOM)s\n' % vars())
# -------------------------------------------------------------------------

# ====================================================
# All processes are working, all sockets are open, and
# every process is listening on the proper socket.
# ====================================================

# -------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sSending %(PAC_N_ZOOM)s Macro Messages\n' % vars())
# -------------------------------------------------------------------------

# ------------------------------------------------
os.system("dir") # example of a built-in dos call
# ------------------------------------------------

# -------------------------------------------------------------------------
# Test1.pzm
# ---------
# Example of the macro file test1.pzm passed through the Process Controller
# and then the dos executable diff.exe is called to compare the results.
# -------------------------------------------------------------------------

PCSendMacro("c:\progra~1\colorcom\Pac-n-Zoom\dcc1.pzm")

# ------------------------------------
# Tell Pac-n-Zoom to execute the Macro
# ------------------------------------

ExecuteTask(PAC_N_ZOOM)
# --> Pac-N-Zoom ExecuteTaskMessage
# <-- Pac-N-Zoom TaskCompletedMessage

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\rose-3.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\rose-3.CDL")

if z is 0:
flog.write('\nFiles rose-3.CDL and pzh_gld\rose-3.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\ppr-es.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\ppr-es.CDL")

if z is 0:
flog.write('\nFiles ppr-es.CDL to pzh_gld\ppr-es.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\r.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\r.CDL")

if z is 0:
flog.write('\n r.CDL and pzh_gld\r.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\timrom41.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\timrom41.CDL")

if z is 0:
flog.write('\n timrom.CDL and pzh_gld\timrom.CDL are the same.\n\n')

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\mul-AB-A.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\mul-AB-A.CDL")

if z is 0:
flog.write('\n mul-AB-A.CDL and pzh_gld\mul-AB-A.CDL are the same.\n\n')
else:
ScriptExit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\mul-AB-B.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\mul-AB-B.CDL")

if z is 0:
flog.write('\n mul-AB-B.CDL and pzh_gld\mul-AB-B.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\mul-AD-A.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\mul-AD-A.CDL")

if z is 0:
flog.write('\n mul-AD-A.CDL and pzh_gld\mul-AD-A.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\mul-AD-B.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\mul-AD-B.CDL")

if z is 0:
flog.write('\n mul-AD-B.CDL and pzh_gld\mul-AD-B.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\mul-AD-C.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\mul-AD-C.CDL")

if z is 0:
flog.write('\n mul-AD-C.CDL and pzh_gld\mul-AD-C.CDLare the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\mul-AD-D.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\mul-AD-D.CDL")

if z is 0:
flog.write('\n mul-AD-D.CDL and pzh_gld\mul-AD-D.CDL are the same.\n\n')
else:
ScriptExit(z)

PCSendMacro("c:\progra~1\colorcom\Pac-n-Zoom\dcc2.pzm")

# ------------------------------------
# Tell Pac-n-Zoom to execute the Macro
# ------------------------------------

ExecuteTask(PAC_N_ZOOM)
# --> Pac-N-Zoom ExecuteTaskMessage
# <-- Pac-N-Zoom TaskCompletedMessage

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\rose-3g.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\rose-3g.CDL")

if z is 0:
flog.write('\nFiles rose-3g.CDL and cdl_gld\rose-3g.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\e-gld.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\e-gld.CDL")

if z is 0:
flog.write('\nFiles e-gld.CDL to cdl_gld\e-gld.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\r-gld.CDL", \
"c:\\Users\\Administrator\\r-gld.CDL")

if z is 0:
flog.write('\n r-gld.CDL and cdl_gld\r-gld.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\dh_1.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\dh_1.CDL")

if z is 0:
flog.write('\n dh_1.CDL and cdl_gld\dh_1.CDL are the same.\n\n')

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\dh_1-1.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\dh_1-1.CDL")

if z is 0:
flog.write('\n dh_1-1.CDL and cdl_gld\dh_1-1.CDL are the same.\n\n')
else:
ScriptExit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\dh_1-2.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\dh_1-2.CDL")

if z is 0:
flog.write('\n dh_1-2.CDL and cdl_gld\dh_1-2.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\dh_1-3.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\dh_1-3.CDL")

if z is 0:
flog.write('\n dh_1-3.CDL and cdl_gld\dh_1-3.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\dh_1-4.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\dh_1-4.CDL")

if z is 0:
flog.write('\n dh_1-4.CDL and cdl_gld\dh_1-4.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\dh_1-5.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\dh_1-5.CDL")

if z is 0:
flog.write('\n dh_1-5.CDL and cdl_gld\dh_1-5.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\dh_1-6.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\dh_1-6.CDL")

if z is 0:
flog.write('\n mul-AD-D.CDL and cdl_gld\mul-AD-D.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\dh_1-7.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\dh_1-7.CDL")

if z is 0:
flog.write('\n dh_1-7.CDL and cdl_gld\dh_1-7.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\dh_1-8.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\dh_1-8.CDL")

if z is 0:
flog.write('\n dh_1-8.CDL and cdl_gld\dh_1-8.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\cdl_tst\\dh_1-9.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\dh_1-9.CDL")

if z is 0:
flog.write('\n dh_1-9.CDL and cdl_gld\dh_1-9.CDL are the same.\n\n')
else:
exit(z)

z = os.spawnl(os.P_WAIT, "c:\\Users\\Administrator\\diff.exe", "diff", "-b", \
"c:\\Users\\Administrator\\dh_1-10.CDL", \
"c:\\Users\\Administrator\\cdl_gld\\dh_1-10.CDL")

if z is 0:
flog.write('\n dh_1-10.CDL and cdl_gld\dh_1-10.CDL are the same.\n\n')
else:
exit(z)

ScriptExit(z)

ScriptExit(0)


When the script is launched, it will compare the CDL golden and test files and write the result on the log file.

Single Stepping the Macros

Single stepping executes the current line, stop at the first possible occasion (either in a function that is called or in the current function). It then Continue execution until the next line in the current function is reached or it returns. To single step the macros, embed the macros on the python script as shown below:

# #############################
# Example Python Control Script
# #############################

# ================
# Import Libraries
# ================

import socket
import sys
import os
from time import strftime, sleep

# ===========
# Define Data
# ===========

# --------------------------
# Message Control Characters
# --------------------------

ExecuteTaskMessage = '#'
TaskCompletedMessage = '@'
OKMessage = '?'

# -------------
# Program Names
# -------------

PROCESS_CONTROLLER = 'ProcessController'
PAC_N_ZOOM = 'Pac-n-Zoom'

# --------------------
# Program Socket Ports
# --------------------

PC_PORT = '5098' # Character Script-ProcCont Port Number
I_PC_PORT = 5098 # Integer Script-ProcCont Port Number
PZ_PORT = '5099' # Character ProcCont-Pac-N-Zoom Port Number

CONTROL_SCRIPT_DOMAIN = socket.gethostname()
# Use this to
# get Domain
# Name where
# Control
# Script is
# executing
CONTROL_SCRIPT_IP = socket.gethostbyname(CONTROL_SCRIPT_DOMAIN) # Use this to
# get Control
# Script IP
# address
pid = os.getpid()

PythonHeader = ': Python Script PID=%(pid)04d: ' % vars()

FileName = 'py__%(pid)04d.log' % vars()
flog = open(FileName, 'w')

# =========
# Functions
# =========

# -----------------------
def ScriptExit(ExitCode):
# -----------------------

# -----------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sPython Shutting Down\n' % vars())
flog.flush()
# -----------------------------------------------------------------

s.close()
flog.close()
sys.exit(ExitCode)

# -----------------------------------------
def PCSend(ProcessName, SendData, DoPrint):
# -----------------------------------------

while 1:
try:
# -------------------------------------------------------------------------------
if DoPrint is 1:
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sSending \"%(SendData)s\" to %(ProcessName)s\n' % vars())
# -------------------------------------------------------------------------------
s.send(SendData)
except socket.error, msg:
# ---------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sProcess Controller Socket send() Error - Shutting Down\n' % vars())
# ---------------------------------------------------------------------------------------
ScriptExit(1)
return

# ---------------------------------------
def PCSendMessage(ProcessName, SendData):
# ---------------------------------------

PCSend(ProcessName, SendData, 1)
RecvOKMessage(ProcessName)

# ---------------------------------------
def PCSendMacro(MacroName):
# ---------------------------------------

fmac = open(MacroName, 'r')

while 1:
string = fmac.readline()
if len(string) is 0:
fmac.close()
return
PCSendMessage(PAC_N_ZOOM, string)

# ---------------------------
def ExecuteTask(ProcessName):
# ---------------------------

# ------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sSending ExecuteTaskMessage to %(ProcessName)s\n' % vars())
# ------------------------------------------------------------------------------

PCSend(ProcessName, ExecuteTaskMessage, 0)

# ----------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sListening for TaskCompletedMessage from %(ProcessName)s\n' % vars())
# ----------------------------------------------------------------------------------------

RecvData = ' '
while 1:
try:
RecvData = s.recv(1024)
if RecvData[0] is not TaskCompletedMessage[0]:
# -------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived \"%(RecvData)s\" from %(ProcessName)s\n' % vars())
flog.write('%(LogHeader)sExpected TaskCompletedMessage - Shutting Down\n' % vars())
# -------------------------------------------------------------------------------
ScriptExit(1)
# -----------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived TaskCompletedMessage from %(ProcessName)s\n' % vars())
# -----------------------------------------------------------------------------------
except socket.error, msg:
# ---------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sProcess Controller Socket recv() Error - Shutting Down\n' % vars())
# ---------------------------------------------------------------------------------------
ScriptExit(1)
return

# -----------------------------
def RecvOKMessage(ProcessName):
# -----------------------------

# -----------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sListening for OKMessage from %(ProcessName)s\n' % vars())
# -----------------------------------------------------------------------------

RecvData = ' '
while 1:
try:
RecvData = s.recv(1024)
if RecvData[0] is not OKMessage[0]:
# -------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived \"%(RecvData)s\" from %(ProcessName)s\n' % vars())
flog.write('%(LogHeader)sExpected OKMessage - Shutting Down\n' % vars())
# -------------------------------------------------------------------------------
ScriptExit(1)
# ------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived OKMessage from %(ProcessName)s\n' % vars())
# ------------------------------------------------------------------------
except socket.error, msg:
# ---------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sProcess Controller Socket recv() Error - Shutting Down\n' % vars())
# ---------------------------------------------------------------------------------------
ScriptExit(1)
return

# ----------------------
def SendRecvOKMessage():
# ----------------------

RecvData = ' '

while 1:
try:
# ------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sSending OKMessage to Process Controller\n' % vars())
# ------------------------------------------------------------------------

s.send(OKMessage)

# --------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sListening for OKMessage from Process Controller\n' % vars())
# --------------------------------------------------------------------------------

RecvData = s.recv(1024)

if RecvData[0] is not OKMessage[0]:
# ----------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived \"%(RecvData)s\" from Process Controller\n' % vars())
flog.write('%(LogHeader)sExpected OKMessage - Shutting Down\n' % vars())
# ----------------------------------------------------------------------------------
ScriptExit(1)
break

except socket.error, msg:

# --------------------------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sSleeping to give the Process Controller time to Open Socket and Respond\n' % vars())
# --------------------------------------------------------------------------------------------------------

sleep(1)

# ---------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sReceived OKMessage from Process Controller\n' % vars())
# ---------------------------------------------------------------------------

# ================
# End of Functions
# ================

# ==================
# Python Main Script
# ==================

# --------------------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sCreating Socket to communicate with the %(PROCESS_CONTROLLER)s\n' % vars())
# --------------------------------------------------------------------------------------------------

s = None
while 1:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
s = None
continue
try:
s.connect((CONTROL_SCRIPT_IP, I_PC_PORT))
except socket.error, msg:
s = None
continue
break

if s is None:
# ----------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sPython Socket Open Error - Shutting Down\n' % vars())
# ----------------------------------------------------------------------------
sys.exit(1)

# ---------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sConnected\n' % vars())
# ---------------------------------------------

#-----------------------------------------------------------
# Send and then Receive OKMessage to/from Process Controller
#-----------------------------------------------------------

SendRecvOKMessage()

# ---------------------------------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)s%(PROCESS_CONTROLLER)s has opened the socket for communications\n' % vars())
# ---------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sPython can now talk to %(PAC_N_ZOOM)s\n' % vars())
# -------------------------------------------------------------------------

# ====================================================
# All processes are working, all sockets are open, and
# every process is listening on the proper socket.
# ====================================================

# -------------------------------------------------------------------------
LogHeader = strftime('%X') + PythonHeader
flog.write('%(LogHeader)sSending %(PAC_N_ZOOM)s Macro Messages\n' % vars())
# -------------------------------------------------------------------------

# ------------------------------------------------
os.system("dir") # example of a built-in dos call
# ------------------------------------------------

# -------------------------------------------------------------------------
# Test1.pzm

PCSendMacro("c:\progra~1\colorcom\Pac-n-Zoom\dcc1.pzm")

# ------------------------------------
# Tell Pac-n-Zoom to execute the Macro
# ------------------------------------

ExecuteTask(PAC_N_ZOOM)
# --> Pac-N-Zoom ExecuteTaskMessage
# <-- Pac-N-Zoom TaskCompletedMessage

Open("C:\Program Files\Colorcom\files\rose-3.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\rose-3.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\ppr-es.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\ppr-es.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\r.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\r.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\timrom41.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\timrom41.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\mul-AB.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\mul-AB-A.CDL")
GoToPage(2)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AB-B.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\mul-AD.pzh")
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-A.CDL")
GoToPage(2)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-B.CDL")
GoToPage(3)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-C.CDL")
GoToPage(4)
SaveAs("C:\Users\Administrator\CDL_gld\mul-AD-D.CDL")
Done()
Stop()

ScriptExit(z)

ScriptExit(0)

# ------------------------------------
# Test2.pzm
# ------------------------------------

PCSendMacro("c:\progra~1\colorcom\Pac-n-Zoom\dcc2.pzm")

# ------------------------------------
# Tell Pac-n-Zoom to execute the Macro
# ------------------------------------

ExecuteTask(PAC_N_ZOOM)
# --> Pac-N-Zoom ExecuteTaskMessage
# <-- Pac-N-Zoom TaskCompletedMessage

Open("C:\Program Files\Colorcom\files\rose-3g.pzh")
SaveAs("C:\Users\Administrator\cdl_gld\rose-3g.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\e-gld.pzh")
SaveAs("C:\Users\Administrator\cdl_gld\e-gld.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\r-gld.pzh")
SaveAs("C:\Users\Administrator\cdl_gld\r-gld.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\dh_1.pzh")
SaveAs("C:\Users\Administrator\cdl_gld\dh_1.CDL")
Clear()
Open("C:\Program Files\Colorcom\files\dh_1-10.pzh")
SaveAs("C:\Users\Administrator\cdl_gld\dh_1-1.CDL")
GoToPage(2)
SaveAs("C:\Users\Administrator\cdl_gld\dh_1-2.CDL")
GoToPage(3)
SaveAs("C:\Users\Administrator\cdl_gld\dh_1-3.CDL")
GoToPage(4)
SaveAs("C:\Users\Administrator\cdl_gld\dh_1-4.CDL")
GoToPage(5)
SaveAs("C:\Users\Administrator\cdl_gld\dh_1-5.CDL")
GoToPage(6)
SaveAs("C:\Users\Administrator\cdl_gld\dh_1-6.CDL")
GoToPage(7)
SaveAs("C:\Users\Administrator\cdl_gld\dh_1-7.CDL")
GoToPage(8)
SaveAs("C:\Users\Administrator\cdl_gld\dh_1-8.CDL")
GoToPage(9)
SaveAs("C:\Users\Administrator\cdl_gld\dh_1-9.CDL")
GoToPage(10)
SaveAs("C:\Users\Administrator\cdl_gld\dh_1-10.CDL")
Done()
Stop()


The Process of Single Stepping the Macro


After launching Pac-n-Zoom and the Process Controller, right click on python script icon containing the macro, and choose "Edit with IDLE". Two Python windows will come up. From the Python Shell window, choose the Debug dropdown Debugger which will bring up a debug window. Check source and Globals to see what you are stepping through.

From the source window choose the Edit dropdown then click on Run. The debug window will stop on the first line of the script. The script has functions at the top which are best to jump over until you get below the macro,this will execute the macro.
© 2004 - 2011 Accelerated I/O, Inc, All rights reserved.