sersock
Elixir Serial Port to Socket exporter.
Installation and Usage
-
Add
sersockto yourmix.exsdependency list:
def deps do
[{:sersock, "~> 0.1.2"}]
end- Manually start and stop individual instances.
tty = case :os.type() do
{:unix, :darwin} -> "cu.usbserial-FTYHQD9MA"
{:unix, :linux} -> "ttyUSB0"
{:win32, :nt} -> "COM12"
end
{:ok, pid} = Sersock.start_link([device: tty, port: 5000])
{:ok, %{ip: {0,0,0,0}, port: 5000}} = Sersock.endpoint(pid)
:ok = Sersock.stop(pid)-
Connect your serial port to some device and talk to it with
netcat. Prepend withrlwrapfor command history.
#Talking to a KTA-223
nc localhost 5000
@00 IS 0
#00 0- Run the tests
#Serial port names are hard coded in test_helper.exs
#TCP ports are hard coded in sersock_test.exs
#A couple of serial ports are required
mix testDevelopment
-
Testing requires two null modem serial ports configured in
test/test_helper.exs
Windows
Install Visual C++ 2015 Build Tools by one of the following methods:
- Download and install visualcppbuildtools_full.exe
-
Thru Chocolatey
choco install VisualCppBuildTools.
From the Windows run command launch cmd /K c:\Users\samuel\Documents\github\sersock\setenv.bat adjusting your code location accordingly.
Ubuntu
Give yourself access to serial ports with sudo gpasswd -s samuel dialout. Follow the official Elixir installation instructions and install build-essential erlang-dev as well.
Roadmap
Future
- Pass test serial port thru environment variables
0.5.4
- Updated to sniff 0.1.4
0.1.1
- test runs client sockets in line mode to avoid packet fragmentation in Linux
-
eaddrinuse error after reloading
iex -S mixreuseaddr: truein:gen_tcp.listenseems to fix it - Leave only the raw serial export mode
0.1.0
- Release not supported any more