README.md

# sersock

Elixir Serial Port to Socket exporter.

## Installation and Usage

  1. Add `sersock` to your `mix.exs` dependency list:

  ```elixir
  def deps do
    [{:sersock, "~> 0.1.2"}]
  end
  ```

  2. Manually start and stop individual instances.

  ```elixir
  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)
  ```

  3. Connect your serial port to some device and talk to it with `netcat`. Prepend with `rlwrap` for command history.

  ```bash
  #Talking to a KTA-223
  nc localhost 5000
  @00 IS 0
  #00 0
  ```

  4. Run the tests

  ```bash
  #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 test
  ```

## Development

  - 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](http://landinghub.visualstudio.com/visual-cpp-build-tools)
  - Thru [Chocolatey](https://chocolatey.org/) `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

- [x] Updated to sniff 0.1.4

0.1.1

- [x] test runs client sockets in line mode to avoid packet fragmentation in Linux
- [x] eaddrinuse error after reloading `iex -S mix`
`reuseaddr: true` in `:gen_tcp.listen` seems to fix it
- [x] Leave only the raw serial export mode

0.1.0

- [x] Release not supported any more