Creation of special Kernel event handling (USB auto connection for serial communication)

From Lofaro Lab Wiki
Jump to: navigation, search

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