Wio RP2040 WIFI UART or SPI

I can connect to the WIO RP2040 using SPI now

Using this code I can switch the wifi to Station Mode but as soon as it does it loses connection to the computer (Thony Editor)

[CODE]import usocket
from machine import Pin, I2C, ADC, UART, SPI, PWM
from time import sleep

N1 = network.WLAN_SPI(network.STA_IF)
N1.active(True)

print(“API list:”)
dir(N1)

print(“wifi list:”)
lis = N1.scan()
for q in lis:
print(q)

N1.connect(“access point”,“password”)
if N1.isconnected():
print(" ip gateway netmask MAC ssid")
print(N1.ifconfig())[/CODE]

It returns this error:

Unable to connect to COM18: could not open port ‘COM18’: PermissionError(13, ‘Access is denied.’, None, 5)
If you have serial connection to the device from another program, then disconnect it there first.
Backend terminated or disconnected. Use ‘Stop/Restart’ to restart.

If I try this

[CODE]import usocket
from machine import Pin, I2C, ADC, UART, SPI, PWM
from time import sleep

N1 = network.WLAN_SPI(network.STA_IF)
N1.active(True)[/CODE] it does the same thing

I know it’s working because when I plug the RP2040 in I can see ESP-AP in my list of wifi stations
Is this right? shouldn’t that only happen if I used N1 = network.WLAN_SPI(network.AP_IF)?

Why do I lose my com port connection to the RP2040 after running the program and the only way to get control again is to reset it