The DPhyGenCtlRPCWrapper directory contains library code and projects to
facilitate and demonstrate remote control of the DPhyGenCtl application
for non-.NET languages such as unmanaged C++, Python, Matlab, Labview,
etc.

Directory Contents:

---------------------------------------------------------------------

1) Visual Studio DPhyGenCtlRPCWrapper DLL project.  Defines a
managed/unmanaged C++ wrapper DLL to provide an interface to
DPhyGenCtlRPC.dll, which is the C#/.NET DLL provided to control the
DPhyGenCtl application.  This wrapper DLL is useful because non-.NET
languages cannot easily use DPhyGenCtlRPC DLL directly.

The wrapper library defines methods with the same names as methods in
the DPhyGenCtlRPC library.  Because non-.NET libraries cannot take
advantage of the "generic" argument syntax of C#, DPhyGenCtlRPC.dll
defines a suite of methods with explicit argument types.  These are the
methods duplicated by the wrapper library.  

The wrapper library modifies the function signatures of most routines
from the DPhyGenCtlRPC library in two ways.  First, an additional
argument is required, which is a pointer to client object opened at the
beginning of the session. Second, the errMsg and statusMsg return
arguments are removed from the calls.  Instead, methods to retrieve
these strings (if desired) are provided by the wrapper DLL
(GetLastErrMsg and GetLastStatusMsg).

The naming convention for many of these routines is to append suffixes
that describe the argument and/or return type. 'I' implies an integer
argument, 'S' implies a string argument, and 'F' implies a
floating-point argument.  For example, RPCCmdII has two integer
arguments and RPCCmdIS has an integer and string argument.  

Please see DPhyGenCtlRPCWrapper.cpp for the function names and
signatures of exported method calls.  Then, consult with the DPhy
Generator RPC document DPhyGenCtlRPCCommands.pdf installed with the
DPhyGenCtl application (in Windows Start->DPhyGenCtl) for command names
and argument requirements. From this information, you can choose the
RPCCmd variation needeed to send the command.  For example,
SET_BTA_WAIT_TIME has one floating point argument and so should be
sent using RPCCmdF.  SET_OPTION has two integer arguments and so should
be sent using RPCCmdII.

Note that the wrapper DLL is compiled as an x86 architecture (i.e.
32-bit). This is because non-.NET languages cannot interface to
"Any-CPU" architecture DLLs, which automatically support 32-bit and
64-bit processor architectures.  This means that programs that use this
DLL must be compiled for the 32-bit architecture or, in the case of
python, use the 32-bit version of the interpreter.  Note that 32-bit
versions of programs and DLLs can run on 64-bit machines

The user can, of course, recompile a x64 architecture version of the
wrapper DLL and then use it with 64-bit archietecture programs.

Before calling wrapper DLL methods to control the DPhy Generator, user
programs should perform two initial steps:

1) Intantiate a "client" object using the NewClient DLL method.  The
client object is provided in all subsequent DLL calls as the first
argument.

2) Call the Connect DLL method, giving the hostname and IP port to
use to establish a connection to the DPhyGenCtl software.  DPhyGenCtl
must have enabled the RPC port using the Connect->Enable RPC menu option
prior to this call.

After successful connection, the RPCCmd, RPCQuery, and MIPICmd calls can
be used to configure and control the DPhy Generator instrument.

One issue to highlight is the allocation and deallocation of strings and
arrays when these variable types are returned to the user program.  The
"Free" dll call should be used to deallocate the memory associated with
these variables when the user program is finished with them.  Though,
for convenience, the GetLastErrMsg and GetLastStatusMsg have a "copy"
argument.  If false, memory should NOT be deallocated by the user
program as the library will automatically free the memory during the
next call.  Accordingly, the program should only reference the string
until the next DLL call.

---------------------------------------------------------------------

2) Visual Studio TestWrapper executable project.  Defines an unmanaged
C++ console test program that demonstrates use of the
DPhyGenCtlRPCWrapper DLL.

The DPhyGenCtlRPCWrapper DLL is built in the Debug directory for
use by the TestWrapper and DPhyGenPythonCtl programs.  This directory
also contains the DPhyGenCtlRPC DLL.

The TestWrapper program can be run in Visual Studio or directly by
launching TestWrapper.exe in the Debug directory.  The program assumes
DPhyGenCtl is running and has RPC access enabled through port 2799
(via Connect->Enable RPC menu option).

There are two main CPP files in the TestWrapper project:
DPhyGenCtlRPCIF.cpp and TestWrapper.cpp.  DPhyGenCtlRPCIF.cpp contains
convenient declarations for importing, mapping, calling
DPhyGenCtlRPCWrapper DLL methods.  Its one routine "InitDLL" should be
called to load the wrapper library and initialize global function
pointers for its methods (e.g. RPCCmd, RPCCmdI, RPCCmdS, etc).  It
additionally defines wrapper classes for the RPCErrs, RPCCmds, and
RPCDefs classes contained in the DPhyGenCtlRPC library so they can be
used in user code.

TestWrapper.cpp consists of a simple main routine to demonstrate usage.
First, the client class is instantiated and a connection to the
DPhyGenCtl application is made.  Then, several configuration commands
are sent to set the DSI standard, lane count, and select the 640x480
timing configuration.  Next, an RGB888 video-mode frame is sent and the
program waits 5 seconds before stopping the PG.  After more
configuration commands to enable event timeout (to ensure a BTA timeout
if necessary) and disable looping commands, a generic read request with
BTA is sent.  Finally, any DUT response is retrieved and printed in the
console.

---------------------------------------------------------------------

3) Visual Studio DPhyGenPythonCtl project.  Defines a simple python 3.6
project that also demonstrates use of the DPhyGenCtlRPCWrapper DLL.

Like the TestWrapper program, the DPhyGenPythonCtl program references
the DPhyGenCtlRPCWrapper dll in the Debug directory, which in turn
references the DPhyGenCtlRPC dll.  The python program can be run in the
Visual Studio debugger (make sure your Python 3 x86 environment is
properly selected in the Solution Explorer) or directly by launching
DPhyGenPythonCtl.py (assuming ".ph" extensions are associated with the
Python 3 x86 interpreter).

There are three python files defined in the project.
DPhyGenCtlRPCDefines.py defines the RPCErrs, RPCCmds, and RPCDefs
classes.  DPhyGenCtlRPCWrapper.py imports the wrapper DLL and defines
the method signatures, returning a reference object "dphyDLL" that can
be used by the calling routine to communicate with DPhyGenCtl through
the wrapper DLL.  Finally, the file DPhyGenPythonCtl.py is the main
program that defines a simple GUI using tkinter.

The GUI contains controls for connecting to the DPhyGenCtl application
and defining parameters for sending a minimal-blanking CSI video frame
in RGB888. Controls include: HS bit rate, HActive, VActive, lane count,
and a checkbox to enable Line Start/Line End packets in the frame.  The
image file name to use can be browsed for or entered (test pattern names
are also allowed).

To use:
1) Enter the port number to use and click on the Connect button.
2) Fill in parameter controls.
3) Click the Send button.


















The DphyGenCtlRPCWrapper/Debug directory contains the 





that shows a simple tkinter GUI for the user to 









The program connects to the DPhyGenCtl application assumed to be running
with RPC enabled at port 2799.  





