Best Python code snippet using tempest_python
mintsDefinitions.py
Source:mintsDefinitions.py
1from getmac import get_mac_address2import serial.tools.list_ports3def findPort(find):4 ports = list(serial.tools.list_ports.comports())5 for p in ports:6 currentPort = str(p)7 if(currentPort.endswith(find)):8 return(currentPort.split(" ")[0])9def findDuePort():10 ports = list(serial.tools.list_ports.comports())11 for p in ports:12 currentPort = str(p[2])13 if(currentPort.find("PID=2341")>=0):14 return(p[0])15def findNanoPorts():16 ports = list(serial.tools.list_ports.comports())17 outPorts = []18 for p in ports:19 currentPort = str(p)20 if(currentPort.endswith("FT232R USB UART")):21 outPorts.append(currentPort.split(" ")[0])22 return outPorts23def findSabrentPorts():24 ports = list(serial.tools.list_ports.comports())25 outPorts = []26 for p in ports:27 currentPort = str(p[2])28 if(currentPort.find("PID=067B")>=0):29 outPorts.append(str(p[0]).split(" ")[0])30 return outPorts31def findOzonePort():32 ports = list(serial.tools.list_ports.comports())33 ozonePort = []34 for p in ports:35 currentPort = str(p[2])36 if(currentPort.find("PID=067B")>=0):37 ozonePort.append(str(p[0]).split(" ")[0])38 return ozonePort39def findMacAddress():40 macAddress= get_mac_address(interface="eth0")41 if (macAddress!= None):42 return macAddress.replace(":","")43 macAddress= get_mac_address(interface="docker0")44 if (macAddress!= None):45 return macAddress.replace(":","")46 macAddress= get_mac_address(interface="enp1s0")47 if (macAddress!= None):48 return macAddress.replace(":","")49 return "xxxxxxxx"50dataFolder = "/home/teamlary/mintsData/raw"51duePort = findDuePort()52nanoPorts = findNanoPorts()53ozonePort = findOzonePort()54show2Port = findPort("CP2104 USB to UART Bridge Controller")55macAddress = findMacAddress()56# macAddress = get_mac_address(interface="docker0").replace(":","") #LAB Machine57# macAddress = get_mac_address(interface="enp1s0").replace(":","")58# macAddress = get_mac_address(interface="eth0").replace(":","") # XU459latestDisplayOn = True60gpsPort = findPort("GPS/GNSS Receiver")...
utils.py
Source:utils.py
2from pp.port import Port3def flip(port: Port) -> Port:4 """ Flip a phidl Port """5 return Port(port.name, port.midpoint, port.width, port.orientation + 180)6def direction_ports_from_list_ports(optical_ports: List[Port]) -> Dict[str, List[Port]]:7 direction_ports = {x: [] for x in ["E", "N", "W", "S"]}8 for p in optical_ports:9 p.angle = (p.angle + 360.0) % 36010 if p.angle <= 45.0 or p.angle >= 315:11 direction_ports["E"].append(p)12 elif p.angle <= 135.0 and p.angle >= 45.0:13 direction_ports["N"].append(p)14 elif p.angle <= 225.0 and p.angle >= 135.0:15 direction_ports["W"].append(p)16 else:17 direction_ports["S"].append(p)18 for direction, list_ports in list(direction_ports.items()):19 if direction in ["E", "W"]:20 list_ports.sort(key=lambda p: p.y)...
list_ports.py
Source:list_ports.py
12# import serial.tools.list_ports345# Option 16import serial.tools.list_ports7print(list(serial.tools.list_ports.comports())) # WIN # [<serial.tools.list_ports_common.ListPortInfo object at 0x00000253F73B4C70>]8print(list(serial.tools.list_ports.comports())) # MAC # [<serial.tools.list_ports_common.ListPortInfo object at 0x7ff5a69d68b0>, <serial.tools.list_ports_common.ListPortInfo object at 0x7ff5a69a7460>]91011# option 212import serial.tools.list_ports13ports = serial.tools.list_ports.comports()1415print(ports) # WIN # [<serial.tools.list_ports_common.ListPortInfo object at 0x00000253F73B4C70>]16print(ports) # MAC # [<serial.tools.list_ports_common.ListPortInfo object at 0x7fe93f295340>, <serial.tools.list_ports_common.ListPortInfo object at 0x7fe93f29d4c0>]171819# ************************************************************************************************************************************************20import serial.tools.list_ports21ports = serial.tools.list_ports.comports()2223for port, desc, hwid in sorted(ports):24 print("{}: {} [{}]".format(port, desc, hwid))25# WIN # COM3: Prolific USB-to-Serial Comm Port (COM3) [USB VID:PID=067B:2303 SER= LOCATION=1-2]2627# MAC # /dev/cu.usbmodem14101: u-blox 7 - GPS/GNSS Receiver [USB VID:PID=1546:01A7 LOCATION=20-1]282930# ************************************************************************************************************************************************31import serial.tools.list_ports32ports = serial.tools.list_ports.comports()3334for port in ports:35 # print(port.device) # WIN # COM336 # print(port.device) # MAC # /dev/cu.usbmodem141013738
...
serial_assistance.py
Source:serial_assistance.py
1import serial.tools.list_ports2def list_ports():3 ports = list(serial.tools.list_ports.comports())4 return ports5def list_ports_by_description():6 ports = list_ports()7 for p in ports:8 print(p.description)9def get_port_by_name(name):10 available_ports = list_ports()11 selected_port = None12 for p in available_ports:13 if name in p.description:14 selected_port = str(p.device)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!