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
#1
Hello, 
I was wondering if there is a command that would allow me to reset USB port? 
I am using LM5 Lite and I'm using USB for rs232 communication, but the problem I have is it sometimes hangs and does not send nor receive any commands and the only way I can make it come back alive is rebooting LM, so maybe only rebooting USB port would be a possibility?
Reply
#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
#3
(19.04.2023, 06:47)admin Wrote: 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

Hello admin,

Unfortunately the problem is still here.

USB does not change the port name. err displays: timeout

system log puts out:

Apr 24 13:57:01 LogicMachine kern.err kernel: [14656.417881] pl2303 1-1:1.0: pl2303_vendor_write - failed to write [0000]: -110
Apr 24 13:57:01 LogicMachine kern.err kernel: [14656.297931] pl2303 ttyUSB0: pl2303_get_line_request - failed: -110
Apr 24 13:57:01 LogicMachine kern.err kernel: [14656.177891] pl2303 ttyUSB0: pl2303_set_control_lines - failed: -110
Apr 24 13:57:01 LogicMachine kern.err kernel: [14656.057986] pl2303 1-1:1.0: pl2303_vendor_write - failed to write [0000]: -110
Apr 24 13:57:01 LogicMachine kern.err kernel: [14655.937909] pl2303 ttyUSB0: pl2303_set_line_request - failed: -110
Apr 24 13:57:01 LogicMachine kern.err kernel: [14655.818029] pl2303 ttyUSB0: pl2303_get_line_request - failed: -110
Apr 24 13:57:00 LogicMachine kern.err kernel: [14655.697920] pl2303 1-1:1.0: pl2303_vendor_write - failed to write [0009]: -110
Apr 24 13:57:00 LogicMachine kern.err kernel: [14655.578120] pl2303 1-1:1.0: pl2303_vendor_write - failed to write [0008]: -110
Apr 24 13:57:00 LogicMachine kern.err kernel: [14655.457913] pl2303 ttyUSB0: error sending break = -110


Any solutions? Or maybe I can restart USB port?
Reply
#4
Try a different USB adapter. PL2303 is not very stable from my experience. Use CP2102 or genuine FTDI chips.
Reply
#5
(24.04.2023, 15:22)admin Wrote: Try a different USB adapter. PL2303 is not very stable from my experience. Use CP2102 or genuine FTDI chips.

Hello admin,

I have replaced USB adapter with genuine FTDI chip (FT232RL). The problem is still here. Any other ideas?
Reply
#6
Are you using an extension cable? Most likely there's a noise source nearby that's causing USB interference.
Reply


Forum Jump: