![](/img/trans.png)
[英]How can I connect a serial device to a Raspberry Pi without a USB to serial adapter?
[英]How can i get file directory of usb device afer detect it when i placed in raspberry pi in python?
我使用 pyudev 來檢測 usb 設備何時放置在樹莓派中。 但是我需要獲取它的文件目錄,以便在我檢測到它之后將 excel 文件保存在 usb 中
代碼是:
import pyudev
import RPi.GPIO as GPIO
import time
from time import sleep
from os import path
#FUNCION PARA DETECTAR USB Y GUARDAR DATOS
def guardarUSB():
context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by(subsystem='usb')
Led = 32
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(Led,GPIO.OUT)
GPIO.output(Led, GPIO.LOW) #poner la señal de salida en alto (High) o bajo (low)
time.sleep(3)
GPIO.cleanup() #limpiar el pin
for device in iter(monitor.poll, None):
if device.action == 'add':
print('{} connected'. format(device.sys_path))
guardarUSB()
使用類似於 Linux 的 Raspbian 操作系統,將外部硬盤驅動器放置在/media/pi
中。 如果您使用os.listdir
,您將能夠找到您是否有硬盤驅動器。 也許使用此代碼來查找有多少硬盤驅動器:
import os
how_many_hard_drives = len(os.listdir("/media/pi"))
print(how_many_hard_drives)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.