# In a Terminal This page runs the device, the experiment and the analyzer from the previous pages together, on one computer, each in its own terminal window. Nothing is needed beyond plesty-lib and the scripts you already wrote. PLESTY also has a desktop application, plesty-bench, which starts devices and experiments for you with buttons. It runs the same kind of programs as this page, so what you do here is also what happens underneath it. ```text terminal 1 serve_pm.py offers the power meter over the network, on port 5555 terminal 2 power_scan.py runs the scan, using the power meter from terminal 1 terminal 3 power_viz.py shows the scan's data in a window while it runs afterwards analyze.py finds the peak in the recorded scan ``` As on the earlier pages, the power meter is `DemoDevice`, so no instrument is needed (see [Try it without the instrument](device.md#try-it-without-the-instrument)). ## 1. Offer the power meter over the network A server makes a device usable from other programs (see [Use it from another computer](device.md#use-it-from-another-computer)). Here the other program runs on the same computer, but it reaches the device the same way. ```python # serve_pm.py from plesty.lib.service import build_server, run_server from plesty.lib.sim.demo_device import MOCK_ADDRESS, DemoDevice server = build_server(DemoDevice(MOCK_ADDRESS), address="tcp://*:5555") run_server(server.run()) ``` In terminal 1: ```bash python serve_pm.py # keeps running until you press Ctrl-C ``` To check it, open a client from a Python prompt in another terminal. `localhost` means "this computer": ```python from plesty.lib.service import build_client client = build_client(address="tcp://localhost:5555") print(client.identity()) # PLESTY,DemoDevice,DEMO-0001,1.0.0 client.write("wavelength", 633.0) print(client.query("wavelength")) # 633.0 ``` With a real instrument, serve your own device class in the same way. ## 2. Run the scan Use the command-line version of `power_scan.py`, from [Give it a command line](experiment.md#give-it-a-command-line). It looks for the power meter's address in the environment variable `PM_ADDRESS`. In terminal 2, set the variable and start the scan: ```bash export PM_ADDRESS=tcp://localhost:5555 # Windows PowerShell: $env:PM_ADDRESS = "tcp://localhost:5555" python power_scan.py --dry-run # show the plan, connect nothing python power_scan.py # Run completed: powerscan_-