src/eric7/MicroPython/Devices/RP2040Devices.py

branch
mpy_network
changeset 9989
286c2a21f36f
parent 9908
761301a784f3
child 10022
a95800b414b7
equal deleted inserted replaced
9988:1ba9d07ba9da 9989:286c2a21f36f
237 def __activateBootloader(self): 237 def __activateBootloader(self):
238 """ 238 """
239 Private slot to switch the board into 'bootloader' mode. 239 Private slot to switch the board into 'bootloader' mode.
240 """ 240 """
241 if self.microPython.isConnected(): 241 if self.microPython.isConnected():
242 self.microPython.deviceInterface().execute( 242 self.executeCommands(
243 [ 243 [
244 "import machine", 244 "import machine",
245 "machine.bootloader()", 245 "machine.bootloader()",
246 ], 246 ],
247 mode=self._submitMode, 247 mode=self._submitMode,
336 @pyqtSlot() 336 @pyqtSlot()
337 def __resetDevice(self): 337 def __resetDevice(self):
338 """ 338 """
339 Private slot to reset the connected device. 339 Private slot to reset the connected device.
340 """ 340 """
341 self.microPython.deviceInterface().execute( 341 if self.microPython.isConnected():
342 "import machine\nmachine.reset()\n", mode=self._submitMode 342 self.executeCommands(
343 ) 343 "import machine\nmachine.reset()\n", mode=self._submitMode
344 )
344 345
345 def getDocumentationUrl(self): 346 def getDocumentationUrl(self):
346 """ 347 """
347 Public method to get the device documentation URL. 348 Public method to get the device documentation URL.
348 349
461 return False, '' 462 return False, ''
462 463
463 print(has_wifi()) 464 print(has_wifi())
464 del has_wifi 465 del has_wifi
465 """ 466 """
466 out, err = self._interface.execute( 467 out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000)
467 command, mode=self._submitMode, timeout=10000
468 )
469 if err: 468 if err:
470 if not err.startswith(b"Timeout "): 469 if not err.startswith(b"Timeout "):
471 raise OSError(self._shortError(err)) 470 raise OSError(self._shortError(err))
472 else: 471 else:
473 # pimoroni firmware loaded but no pico wireless present 472 # pimoroni firmware loaded but no pico wireless present
582 del wifi_status 581 del wifi_status
583 """ 582 """
584 else: 583 else:
585 return super().getWifiData() 584 return super().getWifiData()
586 585
587 out, err = self._interface.execute(command, mode=self._submitMode) 586 out, err = self.executeCommands(command, mode=self._submitMode)
588 if err: 587 if err:
589 raise OSError(self._shortError(err)) 588 raise OSError(self._shortError(err))
590 589
591 stationStr, apStr, overallStr = out.decode("utf-8").splitlines() 590 stationStr, apStr, overallStr = out.decode("utf-8").splitlines()
592 station = json.loads(stationStr) 591 station = json.loads(stationStr)
696 ) 695 )
697 else: 696 else:
698 return super().connectWifi(ssid, password) 697 return super().connectWifi(ssid, password)
699 698
700 with EricOverrideCursor(): 699 with EricOverrideCursor():
701 out, err = self._interface.execute( 700 out, err = self.executeCommands(
702 command, mode=self._submitMode, timeout=15000 701 command, mode=self._submitMode, timeout=15000
703 ) 702 )
704 if err: 703 if err:
705 return False, err 704 return False, err
706 705
754 del disconnect_wifi 753 del disconnect_wifi
755 """ 754 """
756 else: 755 else:
757 return super().disconnectWifi() 756 return super().disconnectWifi()
758 757
759 out, err = self._interface.execute(command, mode=self._submitMode) 758 out, err = self.executeCommands(command, mode=self._submitMode)
760 if err: 759 if err:
761 return False, err 760 return False, err
762 761
763 return out.decode("utf-8").strip() == "True", "" 762 return out.decode("utf-8").strip() == "True", ""
764 763
821 ) 820 )
822 except OSError as err: 821 except OSError as err:
823 return False, str(err) 822 return False, str(err)
824 823
825 # modify boot.py 824 # modify boot.py
826 out, err = self._interface.execute(command, mode=self._submitMode) 825 out, err = self.executeCommands(command, mode=self._submitMode)
827 if err: 826 if err:
828 return False, err 827 return False, err
829 828
830 return out.decode("utf-8").strip() == "True", "" 829 return out.decode("utf-8").strip() == "True", ""
831 830
886 del check_internet 885 del check_internet
887 """ 886 """
888 else: 887 else:
889 return super().checkInternet() 888 return super().checkInternet()
890 889
891 out, err = self._interface.execute( 890 out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000)
892 command, mode=self._submitMode, timeout=10000
893 )
894 if err: 891 if err:
895 return False, err 892 return False, err
896 893
897 return out.decode("utf-8").strip() == "True", "" 894 return out.decode("utf-8").strip() == "True", ""
898 895
951 del scan_networks 948 del scan_networks
952 """ 949 """
953 else: 950 else:
954 return super().scanNetworks() 951 return super().scanNetworks()
955 952
956 out, err = self._interface.execute( 953 out, err = self.executeCommands(command, mode=self._submitMode, timeout=15000)
957 command, mode=self._submitMode, timeout=15000
958 )
959 if err: 954 if err:
960 return [], err 955 return [], err
961 956
962 networksList = ast.literal_eval(out.decode("utf-8")) 957 networksList = ast.literal_eval(out.decode("utf-8"))
963 networks = [] 958 networks = []
1029 del deactivate 1024 del deactivate
1030 """ 1025 """
1031 else: 1026 else:
1032 return super().deactivateInterface(interface) 1027 return super().deactivateInterface(interface)
1033 1028
1034 out, err = self._interface.execute(command, mode=self._submitMode) 1029 out, err = self.executeCommands(command, mode=self._submitMode)
1035 if err: 1030 if err:
1036 return False, err 1031 return False, err
1037 else: 1032 else:
1038 return out.decode("utf-8").strip() == "True", "" 1033 return out.decode("utf-8").strip() == "True", ""
1039 1034
1120 repr(password if password else ""), 1115 repr(password if password else ""),
1121 ) 1116 )
1122 else: 1117 else:
1123 return super().startAccessPoint(ssid, security=security, password=password) 1118 return super().startAccessPoint(ssid, security=security, password=password)
1124 1119
1125 out, err = self._interface.execute( 1120 out, err = self.executeCommands(command, mode=self._submitMode, timeout=15000)
1126 command, mode=self._submitMode, timeout=15000
1127 )
1128 if err: 1121 if err:
1129 return False, err 1122 return False, err
1130 else: 1123 else:
1131 return out.decode("utf-8").strip() == "True", "" 1124 return out.decode("utf-8").strip() == "True", ""
1132 1125
1170 ), 1163 ),
1171 ) 1164 )
1172 else: 1165 else:
1173 return super().checkInternet() 1166 return super().checkInternet()
1174 1167
1175 out, err = self._interface.execute( 1168 out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000)
1176 command, mode=self._submitMode, timeout=10000
1177 )
1178 if err: 1169 if err:
1179 return [], err 1170 return [], err
1180 1171
1181 clientsList = ast.literal_eval(out.decode("utf-8")) 1172 clientsList = ast.literal_eval(out.decode("utf-8"))
1182 return clientsList, "" 1173 return clientsList, ""
1207 1198
1208 print(has_eth()) 1199 print(has_eth())
1209 del has_eth 1200 del has_eth
1210 """ 1201 """
1211 1202
1212 out, err = self._interface.execute( 1203 out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000)
1213 command, mode=self._submitMode, timeout=10000
1214 )
1215 if err: 1204 if err:
1216 raise OSError(self._shortError(err)) 1205 raise OSError(self._shortError(err))
1217 1206
1218 return ast.literal_eval(out.decode("utf-8")) 1207 return ast.literal_eval(out.decode("utf-8"))
1219 1208
1248 del ethernet_status, w5x00_init 1237 del ethernet_status, w5x00_init
1249 """.format( 1238 """.format(
1250 WiznetUtilities.mpyWiznetInit() 1239 WiznetUtilities.mpyWiznetInit()
1251 ) 1240 )
1252 1241
1253 out, err = self._interface.execute(command, mode=self._submitMode) 1242 out, err = self.executeCommands(command, mode=self._submitMode)
1254 if err: 1243 if err:
1255 raise OSError(self._shortError(err)) 1244 raise OSError(self._shortError(err))
1256 1245
1257 status = [] 1246 status = []
1258 ethStatus = json.loads(out.decode("utf-8")) 1247 ethStatus = json.loads(out.decode("utf-8"))
1305 """.format( 1294 """.format(
1306 WiznetUtilities.mpyWiznetInit(), "'dhcp'" if config == "dhcp" else config 1295 WiznetUtilities.mpyWiznetInit(), "'dhcp'" if config == "dhcp" else config
1307 ) 1296 )
1308 1297
1309 with EricOverrideCursor(): 1298 with EricOverrideCursor():
1310 out, err = self._interface.execute( 1299 out, err = self.executeCommands(
1311 command, mode=self._submitMode, timeout=15000 1300 command, mode=self._submitMode, timeout=15000
1312 ) 1301 )
1313 if err: 1302 if err:
1314 return False, err 1303 return False, err
1315 1304
1337 """.format( 1326 """.format(
1338 WiznetUtilities.mpyWiznetInit(), 1327 WiznetUtilities.mpyWiznetInit(),
1339 ) 1328 )
1340 1329
1341 with EricOverrideCursor(): 1330 with EricOverrideCursor():
1342 out, err = self._interface.execute( 1331 out, err = self.executeCommands(
1343 command, mode=self._submitMode, timeout=15000 1332 command, mode=self._submitMode, timeout=15000
1344 ) 1333 )
1345 if err: 1334 if err:
1346 return False, err 1335 return False, err
1347 1336
1376 del check_internet, w5x00_init 1365 del check_internet, w5x00_init
1377 """.format( 1366 """.format(
1378 WiznetUtilities.mpyWiznetInit(), 1367 WiznetUtilities.mpyWiznetInit(),
1379 ) 1368 )
1380 1369
1381 out, err = self._interface.execute( 1370 out, err = self.executeCommands(command, mode=self._submitMode, timeout=10000)
1382 command, mode=self._submitMode, timeout=10000
1383 )
1384 if err: 1371 if err:
1385 return False, err 1372 return False, err
1386 1373
1387 return out.strip() == b"True", "" 1374 return out.strip() == b"True", ""
1388 1375
1443 ) 1430 )
1444 except OSError as err: 1431 except OSError as err:
1445 return False, str(err) 1432 return False, str(err)
1446 1433
1447 # modify boot.py 1434 # modify boot.py
1448 out, err = self._interface.execute(command, mode=self._submitMode) 1435 out, err = self.executeCommands(command, mode=self._submitMode)
1449 if err: 1436 if err:
1450 return False, err 1437 return False, err
1451 1438
1452 return out.decode("utf-8").strip() == "True", "" 1439 return out.decode("utf-8").strip() == "True", ""
1453 1440
1488 return False 1475 return False
1489 1476
1490 print(has_ntp()) 1477 print(has_ntp())
1491 del has_ntp 1478 del has_ntp
1492 """ 1479 """
1493 out, err = self._interface.execute(command, mode=self._submitMode) 1480 out, err = self.executeCommands(command, mode=self._submitMode)
1494 if err: 1481 if err:
1495 raise OSError(self._shortError(err)) 1482 raise OSError(self._shortError(err))
1496 return out.strip() == b"True" 1483 return out.strip() == b"True"
1497 1484
1498 def setNetworkTime(self, server="pool.ntp.org", tzOffset=0, timeout=10): 1485 def setNetworkTime(self, server="pool.ntp.org", tzOffset=0, timeout=10):
1549 }}) 1536 }})
1550 del set_ntp_time 1537 del set_ntp_time
1551 """.format( 1538 """.format(
1552 repr(server), tzOffset, timeout 1539 repr(server), tzOffset, timeout
1553 ) 1540 )
1554 out, err = self._interface.execute( 1541 out, err = self.executeCommands(
1555 command, mode=self._submitMode, timeout=(timeout + 2) * 1000 1542 command, mode=self._submitMode, timeout=(timeout + 2) * 1000
1556 ) 1543 )
1557 if err: 1544 if err:
1558 return False, err 1545 return False, err
1559 else: 1546 else:
1584 rp2.country({0}) 1571 rp2.country({0})
1585 """.format( 1572 """.format(
1586 repr(country) 1573 repr(country)
1587 ) 1574 )
1588 1575
1589 out, err = self._interface.execute(command, mode=self._submitMode) 1576 out, err = self.executeCommands(command, mode=self._submitMode)
1590 if err: 1577 if err:
1591 self.microPython.showError("rp2.country()", err) 1578 self.microPython.showError("rp2.country()", err)
1592 1579
1593 1580
1594 def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber): 1581 def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber):

eric ide

mercurial