MATLAB: Do I get Error No Permission to Create Lock File when I try to receive Data via USBtoSerial in MATLAB on RHEL 7

instrumentInstrument Control Toolboxlinuxlockpermissionusbtoserial

I have a problem with reading data over an usb-to-uart ftdi interface (C232HD). The interface is connected to a microcontroller which is transmitting the data. 
I can see on minicom how data is received, but no chance to see it in matlab. 
I also have created as symbolic link from /dev/ttyUSB0 to /dev/ttyS100. I tried also the java.opts file to place in userpath. 
See : <https://ch.mathworks.com/matlabcentral/answers/95024-why-is-my-serial-port-not-recognized-with-matlab-on-linux-or-solaris> 
On another Windows Machine it works fine. It seems to be a Linux problem. 
MATLAB can recognize the port.
>> instrhwinfo('serial')
ans =
HardwareInfo with properties:
AvailableSerialPorts: {2×1 cell}
JarFileVersion: 'Version 3.11'
ObjectConstructorName: {2×1 cell}
SerialPorts: {2×1 cell}
Access to your hardware may be provided by a support package. Go to the Support Package Installer to learn more.
>> ans.AvailableSerialPorts
ans =
2×1 cell array
'/dev/ttyS1'
'/dev/ttyS0'
>> instrhwinfo('serial')
ans =
HardwareInfo with properties:
AvailableSerialPorts: {3×1 cell}
JarFileVersion: 'Version 3.11'
ObjectConstructorName: {3×1 cell}
SerialPorts: {3×1 cell}
Access to your hardware may be provided by a support package. Go to the Support Package Installer to learn more.
>> ans.AvailableSerialPorts
ans =
3×1 cell array
'/dev/ttyUSB0'
'/dev/ttyS1'
'/dev/ttyS0'
MATLAB properly recognizes /dev/ttyUSB0.
The port permissions of /dev/ttyUSB0 is 666
>> system('ls -als /dev/ttyUSB0')
0K crw-rw-rw- 1 root root 188, 0 Jan 16 14:27 /dev/ttyUSB0

Best Answer

This error could appear if you do not have read/write access to /lock directory.
$ ls -ald /var/lock
lrwxrwxrwx. 1 root root 1K Jun 22 2017 /var/lock -> ../run/lock
$ ls -ald /run/lock
drwxr-xr-x 8 root root 1K Feb 23 13:10 /run/lock
$ touch /var/lock/test
touch: cannot touch ‘/var/lock/test’: Permission denied
 
To fix this, change the permission on /lock directory
$ sudo chmod o+w /run/lock
$ ls -ald /run/lock
drwxr-xrwx 8 root root 1K Feb 23 13:10 /run/lock
$ touch /var/lock/test
$ ls -al /var/lock/test
-rw-r----- 1 maximilian.sgodda ime 0K Feb 23 13:17 /var/lock/test
 
You may need to reboot as well 
$ reboot
 
$ ls -ald /run/lock
drwxr-xr-x 8 root root 1K Feb 23 13:20 /run/lock