Tutorial¶
Getting Started¶
We will go ahead and mock a complete instrument in this tutorial. we will start by “cloning” our existing device using the cli_util
PreRequisites
you must have already created a null modem and have taken notes of the names of both endpoints. I have chosen COM99 and COM100, as my two endpoints using windows.
Note
in linux your endpoints should look more like /dev/ttyS0
“Cloning” an existing device
- connect your device to a comport and make note of its identifier (something like
COM2
in windows and/dev/ttyUSB0
in unix-like systems. - run the following cli command
python -m serial_mock.cli bridge COM2 COM99 -L output_file_name.data
this will create a bridge between COM2 and COM99, in this case COM2 is our device and COM99 is one end of our null modem - now connect up to the other end of our null modem (I am using COM100) (remember i bound to COM99 in the above command and my null modem pair is COM99 <-> COM100), using a serial terminal program of your choice
- once connected send a series of commands you would like to clone, the input and output will be recorded into our
output_file_name.data
file that we specified before - once you are done simple exit our command line cli instruction with
ctrl+c
, we now have our logfile that will serve as the foundation of our cloned device - to convert it into a serial_mock object we will simply use our cli command to
build
our instance, withpython -m serial_mock.cli bridge output_file_name.data --out=MySer.py
- this will create a new file MySer.py that we can run to mimic our recorded device
- Finally serve up our mocked device with
python MySer.py COM99
which will serve our mocked port on the other half of the null modem (ie. connect to COM100 to interact with it)