src/eric7/MicroPython/Devices/MCUScripts/picoWiznetConnect.py

branch
mpy_network
changeset 9890
66a6d3f131cc
parent 9878
a82014a9e57b
child 10153
ffe7432f716b
equal deleted inserted replaced
9889:49728322ffb4 9890:66a6d3f131cc
1 try: 1 try:
2 import wiznet_config 2 import wiznet_config
3 3
4 def connectLan(): 4 def connect_lan():
5 import network 5 import network
6 import time 6 import time
7 from machine import Pin, SPI 7 from machine import Pin, SPI
8
9 try:
10 ifconfig = wiznet_config.ifconfig
11 except AttributeError:
12 print("The network configuration in 'wiznet_config.py' is invalid.")
13 return None
8 14
9 spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18)) 15 spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18))
10 nic = network.WIZNET5K(spi, Pin(17), Pin(20)) 16 nic = network.WIZNET5K(spi, Pin(17), Pin(20))
11 17
12 nic.active(False) 18 nic.active(False)
13 nic.active(True) 19 nic.active(True)
14 nic.ifconfig(wiznet_config.ifconfig) 20 nic.ifconfig(ifconfig)
15 max_wait = 140 21 max_wait = 140
16 while max_wait: 22 while max_wait:
17 if nic.isconnected(): 23 if nic.isconnected():
18 break 24 break
19 max_wait -= 1 25 max_wait -= 1
28 34
29 except ImportError: 35 except ImportError:
30 print( 36 print(
31 "The network configuration is kept in 'wiznet_config.py'. Please add it there." 37 "The network configuration is kept in 'wiznet_config.py'. Please add it there."
32 ) 38 )
33 def connectLan(): 39 def connect_lan():
34 return None 40 return None

eric ide

mercurial