Are you planning to do anything with the USB drive (i.e. read/write to it)? Just to list usb devices, you just need to run command lsusb. To read/write from it, I would recommend that you set up partition automount so that it will appear automatically after reboot/startup. I am not sure of your experience with Linux, so more information is needed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I dont know nothing about Linux. Thats the problem. They changed from Windows CE to Linux. Most of it is working. But if i read a directory its not up to date. Pull out the stick. Then read the stick. it still shows a directory !!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Isusb ?? is that a codesys command ? I programm Codesys. Than i want to detect if there's a stick inserted. Ive there it should show the directory. But somehowe linux is not up to date. If i read a directory. then pul out the stick. Then read the diretory. It still shows the directory even if the stick is pulled out.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would recommend just process everything via SysProcessExecuteCommand2, so you don't need to do post processing in CoDeSys. Example command could be something like this to exclude "Linux Foundation" and include "Flash Drive":
What do you mean with long string? If you use the "grep" parameter it should't be so long.
If string is longer than may try to delete the first part of the string which you do not need...
Or you try to program your own String functions ;-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
sStdOut is 1000. So to long for LEFT or RIGHT. Limits from codesys.
I try Everythink. Also Lookt for an Linux Cource. But a Cource would help me at the moment.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can you try the command inside a terminal like putty?
What result is there?
And If you try only lsblk? Is there nothing... or what is the return from linux?
Last edit: Chris.O 2020-09-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK, then may install putty to your desktop-pc and connect your sps to your desktop pc... with putty you will get connection to your sps (with the ip-adress) then you can log in with user and password (e.g. user = root and PW = root or something like this). THen please try your command lsblk
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
df -h is working. But cant find sda1.
ill think find also is limited to 255
i can see it in the string. Also tried an union. But that also not working properly.
Thats working. Now the end question. Witch on is better. DF or lsusb . Df reads the directory. and lsusb an status. so i would think that its better to check a status every second then to read every second a directory.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok great...
I don't know what is the better way... I would use what works better... you can check if the cycle time of your task changes or your cpu load changes with this commands...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Alternative way would be to detect the mounted folder of the usb-Stick.
In my case the linux system mount the usb-stick with "sda" inside the folder /media.
Means my path would be "/media/sda".
Then may be something like this: (In the programming part I think best would be a state machine)
Thats the way i did it. open the director. If its shows an Error, then there is no stick. But the problem is . if i read a directory its not up to date. Pull out the stick. Then read the stick. it still shows a directory !!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
How can i detect that there is an USB Stick ? With windows is read the directory. But now they changed to LINUX. That doesn't work that way.
more posts ...
Are you planning to do anything with the USB drive (i.e. read/write to it)? Just to list usb devices, you just need to run command lsusb. To read/write from it, I would recommend that you set up partition automount so that it will appear automatically after reboot/startup. I am not sure of your experience with Linux, so more information is needed.
I dont know nothing about Linux. Thats the problem. They changed from Windows CE to Linux. Most of it is working. But if i read a directory its not up to date. Pull out the stick. Then read the stick. it still shows a directory !!
Isusb ?? is that a codesys command ? I programm Codesys. Than i want to detect if there's a stick inserted. Ive there it should show the directory. But somehowe linux is not up to date. If i read a directory. then pul out the stick. Then read the diretory. It still shows the directory even if the stick is pulled out.
Hi,... quick and dirty... maybe something like this
Last edit: Chris.O 2020-09-23
I would recommend just process everything via SysProcessExecuteCommand2, so you don't need to do post processing in CoDeSys. Example command could be something like this to exclude "Linux Foundation" and include "Flash Drive":
scmd:STRING:='lsusb | grep -v "Linux Foundation" | grep "Flash Drive"';
Thanks. i will try it.
Thats working. But not every stick responce with :"Flash Drive"
Im testing it. but its one long string. So i tried to set it to an array. But commands like LEFT en RIGHT are limmited to 255. is there an other way ?
What do you mean with long string? If you use the "grep" parameter it should't be so long.
If string is longer than may try to delete the first part of the string which you do not need...
Or you try to program your own String functions ;-)
sStdOut is 1000. So to long for LEFT or RIGHT. Limits from codesys.
I try Everythink. Also Lookt for an Linux Cource. But a Cource would help me at the moment.
You can also limit sStdOut to 255.
If you use
'lsblk | grep "/media/sda" ; echo OK';
you should get a string with something like that:
ββsda1 8:1 1 14.7G 0 part /media/sda1
OK
This would be a string with 51 Characters... so no problem
If you use LEFT / RIGHT / MID with a String (1000) I think it will only use the fist 255 characters... so should also work.
LSblk gives only OK$N with or without an stick.
Can you try the command inside a terminal like putty?
What result is there?
And If you try only lsblk? Is there nothing... or what is the return from linux?
Last edit: Chris.O 2020-09-30
Never used putty. i look into it. I tried to shut down codesys to get to linux. But that doesn't work the way like in Windows.
OK, then may install putty to your desktop-pc and connect your sps to your desktop pc... with putty you will get connection to your sps (with the ip-adress) then you can log in with user and password (e.g. user = root and PW = root or something like this). THen please try your command lsblk
putty gives : -sh: lsblk: command not found
Ok.... may command df -h is working?
Should give you something like this:
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 383M 5.9M 377M 2% /run
/dev/mmcblk0p2 27G 5.5G 20G 23% /
tmpfs 1.9G 1.5M 1.9G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 70M 360K 70M 1% /var/log
/dev/mmcblk0p1 511M 5.1M 506M 1% /boot/efi
/dev/mmcblk1 30G 43M 29G 1% /media/sd
tmpfs 383M 0 383M 0% /run/user/0
none 120M 40K 120M 1% /mnt/ramdisk
/dev/sda 16G 4.8G 11G 32% /media/sda
In my case here /dev/mmcblk1 is my sd-card (mounted at /media/sd
and /dev/sda is my usb-stick (mounted at /medai/sda)
with command df -h grep /media/sda
you should get
Filesystem Size Used Avail Use% Mounted on
/dev/sda 16G 4.8G 11G 32% /media/sda
THis are 96 characters and you can search for /media/sda...or your usb-directory
df -h is working. But cant find sda1.
ill think find also is limited to 255
i can see it in the string. Also tried an union. But that also not working properly.
Last edit: Reinier Geers 2020-09-30
Ok, sounds good.
Try command: df -h grep "your path name"
e.g. df -h grep /media/sda1
Then string should be shorter and you can see more.
please try inside putty df -h and have a look what is displayed.
Thats working. Now the end question. Witch on is better. DF or lsusb . Df reads the directory. and lsusb an status. so i would think that its better to check a status every second then to read every second a directory.
Ok great...
I don't know what is the better way... I would use what works better... you can check if the cycle time of your task changes or your cpu load changes with this commands...
Alternative way would be to detect the mounted folder of the usb-Stick.
In my case the linux system mount the usb-stick with "sda" inside the folder /media.
Means my path would be "/media/sda".
Then may be something like this: (In the programming part I think best would be a state machine)
Only an idea :-)
Thats the way i did it. open the director. If its shows an Error, then there is no stick. But the problem is . if i read a directory its not up to date. Pull out the stick. Then read the stick. it still shows a directory !!
Can you post your code?