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.

Communication with Usb
#2
Use this function to mount USB properly, in alerts you will get either ok or an error message. By default it mounts the first partition from USB drive to /mnt so you don't have to change anything unless you don't want it to work Smile
Code:
function mountusb(part, mnt)
  part = part or '/dev/sda1'
  mnt = mnt or '/mnt'
  local cmd = string.format('mount %q %q 2>&1', part, mnt)
  local res, stat = io.readproc(cmd)
  return stat == 0 and true or nil, res
end

res, err = mountusb()
if res then
  alert('USB OK')
else
  alert('USB error: ' .. tostring(err))
end

Then, to read/write files you need to supply full path like /mnt/myfile.txt. Because in your case path .. 'new.txt' becomes /mntnew.txt which will be written to the main file system instead of USB drive.
Reply


Messages In This Thread
Communication with Usb - by Shalltear - 21.03.2017, 14:59
RE: Communication with Usb - by admin - 22.03.2017, 06:55
RE: Communication with Usb - by Shalltear - 22.03.2017, 14:31
RE: Communication with Usb - by admin - 23.03.2017, 07:00
RE: Communication with Usb - by Shalltear - 23.03.2017, 17:06
RE: Communication with Usb - by admin - 24.03.2017, 09:01
RE: Communication with Usb - by Shalltear - 24.03.2017, 16:19
RE: Communication with Usb - by Shalltear - 24.03.2017, 17:57
RE: Communication with Usb - by Shalltear - 28.03.2017, 15:07

Forum Jump: