This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Reseting USB from script
#2
Check system log in system config. Most likely your USB device reconnected and changed the port name from /dev/ttyUSB0 to /dev/ttyUSB1.
You can use this function to find the port name. It will return nil if no port is found.
Code:
function findport()
  local path = '/sys/bus/usb-serial/devices'
  local ports = io.ls(path) or {}

  if type(ports) == 'table' and #ports > 0 then
    return '/dev/' .. ports[ 1 ]
  end
end

You should check for read errors to detect USB disconnect:
Code:
res, err = port:read(...)
if err == 'read error' then
  -- USB disconnected
end
Reply


Messages In This Thread
Reseting USB from script - by Aivaras - 19.04.2023, 06:19
RE: Reseting USB from script - by admin - 19.04.2023, 06:47
RE: Reseting USB from script - by Aivaras - 24.04.2023, 14:10
RE: Reseting USB from script - by admin - 24.04.2023, 15:22
RE: Reseting USB from script - by Aivaras - 06.06.2023, 05:41
RE: Reseting USB from script - by admin - 06.06.2023, 07:37

Forum Jump: