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
#1
Sad 
Good morning, I have a problem, use this code, but even without the usb it appears that it is connected. My question is how do I place the USB location?
I'm working it this way...


path = 'mnt/PalominoSyT'
if io.exists(path) then
os.execute('mount' .. path .. ' /mnt')
alert('USB mont')
else
alert('USB not found')
end

path = '/mnt'
status = io.exists(path)
io.writefile(path .. 'new.txt', 'This is a test')
result = io.readfile(path .. 'new.txt')
lea = io.readfile('TestLMUsb.txt')

log(status, result, lea)
Reply
#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
#3
I get the following error, should I create any directory?
Thank you.

Attached Files Thumbnail(s)
   
Reply
#4
The script was incorrect, I've updated it.
Reply
#5
Sad 
Thanks, but I still get the same error. Sad
Reply
#6
Go to system config -> status -> system log. When you connect your USB drive it will show the list of partitions. Some incorrectly formatted drives might use the whole drive without partitions, then you should try mountusb('/dev/sda')
Reply
#7
I already changed it, but I still get the error, when I put mountusb ('/ mnt') the status is USB ok but it is not taking the USB.
With this code I also get error, I do not know what else to try.
<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('/dev/sda')
if res then
alert('USB OK')
else
alert('USB error: ' .. tostring(err))
end
</code>
Reply
#8
Hi,

Can you make a screenshot of your syslog direct after placing usb?
Also from ports and from partitions screen?

Have you tried another stick?

BR,

Erwin
Reply
#9
(24.03.2017, 17:12)Erwin van der Zwart Wrote: Hi,

Can you make a screenshot of your syslog direct after placing usb?
Also from ports and from partitions screen?

Have you tried another stick?

BR,

Erwin

Attached Files Thumbnail(s)
           
Reply
#10
Hi,

I don't see any USB stick showed in your sys log ..

Have you tried another stick? Are you using a USB hub?

This is what i see when inserting a USB drive (notice the new usb found @ 22:32:54 as SDA)

   

BR,

Erwin
Reply
#11
Hi, I was able to get the USB connection, thanks for your help. Smile
Reply


Forum Jump: