Skip to content

samuelventura/sniff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sniff

Elixir Serial Port NIF

Notice: sniff focuses in the native interface to serial ports. For higher level serial port access see baud.

Installation

Add sniff to your list of dependencies in mix.exs:

def deps do
  [{:sniff, "~> 0.1.7"}]
end

Usage

#this echo sample requires a loopback plug
#supported config combinations {8,7}{N,E,O}{1,2}
iex(1)> {:ok, nid} = Sniff.open("/dev/ttyUSB0", 9600, "8N1")
{:ok, #Reference<0.83505167.3498704899.238160>}
iex(2)> Sniff.write(nid, "hello")
:ok
iex(3)> Sniff.read(nid)
{:ok, "hello"}
iex(4)> Sniff.close(nid)
:ok

Test

# test with socat ttys
./test.sh
# test with custom ttys (null modem)
export TTY0="/dev/ttyUSB0"
export TTY1="/dev/ttyUSB1"
mix test
#in Windows
#requires COM98/COM99 com0com ports
test.bat

Development

Windows

Install Visual C++ 2015 Build Tools by one of the following methods:

From the Windows run command launch cmd /K c:\Users\samuel\Desktop\sniff\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.

MacOS

Give yourself access to serial ports with sudo dseditgroup -o edit -a samuel -t user wheel.

Roadmap

Future

  • Binary distro to avoid devenv setup
  • Cleanup windows compilation warnings

0.1.8

  • Support {8,7}{N,E,O}{1,2} configs

0.1.7

  • Auto close monitor and test
  • Migrated to elixir_make

0.1.6

  • Fixed raw mode to avoid byte 15 swallow in macos
  • Testing with fake socat ttys
  • Requires full posix serial port path
  • Pass test serial port thru environment variables

0.1.5

  • Added O_NONBLOCK for MacOS file open.
  • Tests confirmed to pass on linux.
  • Upgraded ex_doc to compile with latest elixir
  • Test serial port names detection on unixes
  • Fixed binary leak when serial_read fails
  • Separated darwin and linux baudrate files

0.1.4

  • Handle spaces in Windows build path

0.1.3

  • Document Windows dependencies
  • BAT to launch windows dev environment
    • A bat to call env.bat and cd back to code folder is provided
    • must be executed from Windows run command (no double click)
  • Ensure native library can be loaded on first compile
    • First deps.get && compile works fine
    • Second compile works fine
    • clean && compile fails to load NIF library
  • Ensure native library can be loaded from IEX
    • Tested on OSXElCapitan/Ubuntu16.10/Windows10
  • Ensure native library can be loaded when used as dependency from IEX
    • Tested on OSXElCapitan/Ubuntu16.10/Windows10
  • Pass the ERTS_HOME to unix makefiles
    • Tested on OSXElCapitan/Ubuntu16.10/Windows10

0.1.2

  • Empty priv is committed and included in hex package so that native libraries get copied to _build when compiled as dependency

0.1.1

  • Tests pass on a clean Windows 10 VM (see build.bat)
  • Automatic test against Ubuntu 16 & Windows 10

0.1.0

  • Drop mac target until stable serial ports
  • Ubuntu 16.04 64 and Windows 10 Pro 64 support
  • Extract baud nif branch to its own repo

Research

  • Bypass the 0.1s minimum granularity on posix systems
  • Higher baud rates support for posix and win32
  • DTR/RTS control and CTS/DSR monitoring
  • Unit test 8N1 7E1 7O1 and baud rate setup against a confirmed gauge
  • Posix async and Windows overlapped
  • _CRT_SECURE_NO_WARNINGS and strncpy_s suggestion in Windows
  • Buffer discarding

References