# Using the Saleae Automation API interactively

**URL:** https://discuss.saleae.com/t/using-the-saleae-automation-api-interactively/2978
**Category:** Uncategorized
**Created:** [July 19, 2024, 9:01pm UTC](https://discuss.saleae.com/t/using-the-saleae-automation-api-interactively/2978 "2024-07-19T21:01:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ngblume](https://yyz2.discourse-cdn.com/flex030/user_avatar/discuss.saleae.com/ngblume/32/1654_2.png) [@ngblume](https://discuss.saleae.com/u/ngblume)
#### Post date: [July 19, 2024, 9:01pm UTC](https://discuss.saleae.com/t/using-the-saleae-automation-api-interactively/2978/1 "2024-07-19T21:01:13Z")

</div>

Hej hej,

I’m trying to utilize the Saleae Automation API for test system development.  
During development, we usually are able to test usage of driver (like the Saleae-wrapper we created) interactively in VS Code using Jupyter cells (and ipykernel)…

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/saleae/original/2X/8/8f8b51cdd298ee510756da7f65d502a4df2f483c.png)

When I try this with the script shown in the picture above, which is kind of a wrapper for the Automation API, this does not work properly…  
I get a rather cryptic error message, saying “Attaching job to the process object didn’t work…”…

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/saleae/original/2X/b/b219bb596d725b3b11ff5c264aa079aebc85a6de.png)

Any idea what is happening here and how to get it to work as expected?

Thanks !

Cheers  
Niels Göran

---

<div class="post-metadata">

### Author: ![BitBob](https://avatars.discourse-cdn.com/v4/letter/b/ecb155/32.png) [@BitBob](https://discuss.saleae.com/u/BitBob)
#### Post date: [July 20, 2024, 3:19pm UTC](https://discuss.saleae.com/t/using-the-saleae-automation-api-interactively/2978/2 "2024-07-20T15:19:56Z")

</div>

In the screenshot, it is saying:

```auto
last error: UNAVAILABLE: ipv4:127.0.0.1:10430: ConnectEx: Connection refused (No connection could be made because the target machine actively refused it

```

Is the Logic 2 process getting spawned, and is the port/automation setup? Can you run the same `Manager.launch()` command from a python script outside of the VS Code environment?

Some ideas on Automation launch:

> [@Automatization launch crashing](https://discuss.saleae.com/t/automatization-launch-crashing/1957):
>
> Hi, When using automation.Manager.launch() , Salea Logic2 opens for less than a second, and crashes with “Process finished with exit code -1073740791 (0xC0000409)”. Any idea what could be the issue? Thanks

And another thread about launching the GUI from a script:

> [@Logic 2.0 Python Automation Gui pop-up connect/launch](https://discuss.saleae.com/t/logic-2-0-python-automation-gui-pop-up-connect-launch/2522):
>
> Hello, I am integrating to my setup Saleae basic 8 and Logic 2.4.10. First of all, when I call manager.connect, GUI pop-up and close back. Is there a way to supress the gui pop-up? I thought maybe manager.launch() as in the example code, would connect without GUI, however If I call it when GUI is closed, I get some error below. If I open the GUI first and execute, it works grpc.\_channel.\_InactiveRpcError: \<\_InactiveRpcError of RPC that terminated with: status = StatusCode.UNAVAILABLE detai…

And finally, one talking specifically about launching from within VS Code:

> [@Logic 2.4.7 Error using .launch() from Unittest](https://discuss.saleae.com/t/logic-2-4-7-error-using-launch-from-unittest/2267/6):
>
> Nice Catch! That was the problem! First I was able to reproduce the problem from the command line simply by setting that variable, then attempting to launch Logic.exe. A quick fix in python is to delete the environment variable before launching Logic, like so: del os.environ['ELECTRON\_RUN\_AS\_NODE'] Just do that before calling automation.Manager.launch() and it should work! I tested and confirmed this from vs code.

I noticed some possible fixes:

- Use the Electron/VS Code work around:  
`del os.environ['ELECTRON_RUN_AS_NODE']`
- If using `Manager.launch()` make sure client is not running before launching (i.e., kill off any existing process first)
- Use `with automation.Manager.launch() as manager: ` syntax, so the `Manager` object is not prematurely destroyed  
(client automatically stopped when `Manager` destroyed)
- Use `Manager.connect()` instead of `Manager.launch()` and make sure client is already running before trying to connect  
(e.g., could use a separate automated method to start Logic 2 process, or just start manually)

---

<div class="post-metadata">

### Author: ![ngblume](https://yyz2.discourse-cdn.com/flex030/user_avatar/discuss.saleae.com/ngblume/32/1654_2.png) [@ngblume](https://discuss.saleae.com/u/ngblume)
#### Post date: [July 21, 2024, 8:42pm UTC](https://discuss.saleae.com/t/using-the-saleae-automation-api-interactively/2978/3 "2024-07-21T20:42:56Z")

</div>

Hej hej,

thank again for also answering this one…

> [@BitBob](#):
>
> Is the Logic 2 process getting spawned, and is the port/automation setup? Can you run the same `Manager.launch()` command from a python script outside of the VS Code environment?

The Logic application starts smoothly and the different commands run smoothly…  
as long as I run everything via a terminal in VS Code…  
The issue only arrises, once choosing the option “Run Current File in interfactive Window”…  
That kind of pointed me in the direction, of that… like “what is VS Code actually doing, if you choose that option…”…

Given your ideas as solution:

> [@BitBob](#):
>
> I noticed some possible fixes:
> 
> - Use the Electron/VS Code work around:  
> `del os.environ['ELECTRON_RUN_AS_NODE']`
> - If using `Manager.launch()` make sure client is not running before launching (i.e., kill off any existing process first)
> - Use `with automation.Manager.launch() as manager: ` syntax, so the `Manager` object is not prematurely destroyed  
> (client automatically stopped when `Manager` destroyed)
> - Use `Manager.connect()` instead of `Manager.launch()` and make sure client is already running before trying to connect  
> (e.g., could use a separate automated method to start Logic 2 process, or just start manually)

1. will try this… seem possible, given that that was also the issue with the unit test, as an indirectly calling method…
2. Tried this, Logic was never running before trying the scripts… so no luck…
3. Scripts work normally without interactive Window, so I’m assuming that the references are kept open correctly… But will try your approach as well …
4. not really an option, given that I want to try to check the correct execution, to kind of replay it later in an atuomated fashion… I could automate starting Logic beforehand, but would prefer to go with on-board-options, rather than doing automated workarounds…

Thanks !

Cheers  
Niels Göran
