Difference between revisions of "Creation of special Kernel event handling (USB auto connection for serial communication)"

From Lofaro Lab Wiki
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Creation of special Kernel event handling ----
 
USB auto connection for serial communication
 
 
This will enable a user to connect a USB to serial device to their computer and auto  
 
This will enable a user to connect a USB to serial device to their computer and auto  
generate the serial connection.
+
generate the serial connection. Must be performed on the users computer as well as the
 +
serial device if the device is a micro controller or similar device.
  
~$sudo adduser [USERNAME] dialout
+
~$sudo adduser [USERNAME] dialout
~$sudo touch /etc/udev/rules.d/95-serialdaemon.rules
+
~$sudo touch /etc/udev/rules.d/95-serialdaemon.rules
~$sudo chmod +x /etc/udev/rules.d/95-serialdaemon.rules
+
~$sudo chmod +x /etc/udev/rules.d/95-serialdaemon.rules
~$sudo gedit /etc/udev/rules.d/95-serialdaemon.rules
+
~$sudo gedit /etc/udev/rules.d/95-serialdaemon.rules
  
 
Insert:
 
Insert:
  
KERNEL=="ttyUSB0", ENV{SYSTEMD_WANTS}="serialdaemon.service"
+
KERNEL=="ttyUSB0", ENV{SYSTEMD_WANTS}="serialdaemon.service"
  
 
Save and close file
 
Save and close file
  
~$sudo touch /lib/systemd/system/serialdaemon.service
+
~$sudo touch /lib/systemd/system/serialdaemon.service
~$sudo chmod +x /lib/systemd/system/serialdaemon.service
+
~$sudo chmod +x /lib/systemd/system/serialdaemon.service
~$sudo gedit /lib/systemd/system/serialdaemon.service
+
~$sudo gedit /lib/systemd/system/serialdaemon.service
  
 
Insert:
 
Insert:
  
[Unit]
+
[Unit]
Description=USB serial to socket bridge
+
Description=USB serial to socket bridge
After=remote-fs.target
+
After=remote-fs.target
After=syslog.target
+
After=syslog.target
[Service]
+
[Service]
ExecStart=/mnt/serialdaemon.sh
+
ExecStart=/mnt/serialdaemon.sh
  
 
Save and close file
 
Save and close file
  
~$sudo touch /mnt/serialdaemon.sh
+
~$sudo touch /mnt/serialdaemon.sh
~$sudo chmod +x /mnt/serialdaemon.sh
+
~$sudo chmod +x /mnt/serialdaemon.sh
~$sudo gedit /mnt/serialdaemon.sh
+
~$sudo gedit /mnt/serialdaemon.sh
  
 
Insert:
 
Insert:
  
#!/bin/sh
+
#!/bin/sh
date +%F-%T >> /var/log/serialdaemon.log
+
date +%F-%T >> /var/log/serialdaemon.log
/usr/local/serialdaemon/serialdaemon -serial /dev/ttyUSB0 -port 15789 -baud 9600 >> /var/log/serialdaemon.log 2>&1
+
/usr/local/serialdaemon/serialdaemon -serial /dev/ttyUSB0 -port 15789 -baud 9600 >> /var/log/serialdaemon.log 2>&1
date +%F-%T >> /var/log/serialdaemon.log
+
date +%F-%T >> /var/log/serialdaemon.log
  
 
Save and close file
 
Save and close file
  
Restart Computer
+
Restart Computer, upon restart plug in serial device and verify
Upon restart plug in serial device and verify
+
~$stty < /dev/ttyUSB0
~$stty < /dev/ttyUSB0
+

Latest revision as of 00:27, 23 April 2015

This will enable a user to connect a USB to serial device to their computer and auto generate the serial connection. Must be performed on the users computer as well as the serial device if the device is a micro controller or similar device.

~$sudo adduser [USERNAME] dialout
~$sudo touch /etc/udev/rules.d/95-serialdaemon.rules
~$sudo chmod +x /etc/udev/rules.d/95-serialdaemon.rules
~$sudo gedit /etc/udev/rules.d/95-serialdaemon.rules

Insert:

KERNEL=="ttyUSB0", ENV{SYSTEMD_WANTS}="serialdaemon.service"

Save and close file

~$sudo touch /lib/systemd/system/serialdaemon.service
~$sudo chmod +x /lib/systemd/system/serialdaemon.service
~$sudo gedit /lib/systemd/system/serialdaemon.service

Insert:

[Unit]
Description=USB serial to socket bridge
After=remote-fs.target
After=syslog.target
[Service]
ExecStart=/mnt/serialdaemon.sh

Save and close file

~$sudo touch /mnt/serialdaemon.sh
~$sudo chmod +x /mnt/serialdaemon.sh
~$sudo gedit /mnt/serialdaemon.sh

Insert:

#!/bin/sh
date +%F-%T >> /var/log/serialdaemon.log
/usr/local/serialdaemon/serialdaemon -serial /dev/ttyUSB0 -port 15789 -baud 9600 >> /var/log/serialdaemon.log 2>&1
date +%F-%T >> /var/log/serialdaemon.log

Save and close file

Restart Computer, upon restart plug in serial device and verify

~$stty < /dev/ttyUSB0