Comments (2)
FYI - I'm working on this feature the lines
branch. Hopefully I'll get it merged to master and make a release soon. The framing of packets is done via a behaviour, but there's a built-in one for lines. Just add the :framing
parameter to your Nerves.UART.open
or Nerves.UART.configure
calls.
Here's an example for passive mode, but active mode works similarly:
iex> {:ok, uart}= Nerves.UART.start_link
{:ok, #PID<0.186.0>}
iex> Nerves.UART.open(uart, "ttyUSB0", speed: 9600, active: false)
:ok
iex> Nerves.UART.read(uart)
{:ok,
"$PGTOP,11,2*6E\r\n$GPGGA,000209.800,,,,,0,0,,,M,,M,,*4B\r\n$GPGSA,A,1,,,,,,,,,,,,,,,*1E\r\n$GPRMC,000209.800,V,,,,,0.00,0.00,060180,,,N*41\r\n$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32\r\n$PGTOP,11,2*6E\r\n$GPGGA,000210.800,,,,,0,0,,,M,,M,,*43\r\n$GPGSA,A,1,,,,,,,,,,,,,,,*1E\r\n$GPRMC,000210.800,V,,,,,0.00,0.00,060180,,,N*49\r\n"}
iex> Nerves.UART.configure(uart, framing: {Nerves.UART.Framing.Line, separator: "\r\n"})
:ok
iex> Nerves.UART.read(uart)
{:ok, "$GPGGA,000226.800,,,,,0,0,,,M,,M,,*46"}
iex> Nerves.UART.read(uart)
{:ok, "$GPRMC,000226.800,V,,,,,0.00,0.00,060180,,,N*4C"}
Since you're breaking on "\n" characters, you don't need to specify the separator. I.e. adding framing: Nerves.UART.Framing.Line
to your Nerves.UART.open
call is sufficient.
from circuits_uart.
The v0.1.0 release has this feature now. Closing this issue. If there are limitations with what I added, then let's open new issues up so that they can be addressed.
@mattneel, thanks for bring this issue up! I think this will help many people.
from circuits_uart.
Related Issues (20)
- Bad Match in `find_pids/0`
- Possible option to set timeout on Open ? HOT 2
- Circuits.UART.enumerate no work on Ubuntu 20.04 HOT 3
- Connection opens without errors, but I can't neither read or write HOT 2
- Circuits.UART.enumerate returns nothing %{"ttyAMA0" => %{}, "ttyS0" => %{}} HOT 9
- Fix kIOMasterPortDefault deprecation on macOS 12 and later
- Should we monitor/link to the `controlling_process`? HOT 1
- Error compiling with BeagleBone based target HOT 7
- `:enotty` when attempting to open a port with RS485 options on Linux HOT 1
- Compile error in Fedora 38 HOT 6
- HOWTO: connect to 2 or more Serial Ports at the same time HOT 2
- Cannot compile for windows (have the windows driver SDK and mingw installed with chocolatey
- Latency HOT 3
- Can't close connection to unopened device HOT 1
- Cannot set parity to :mark HOT 2
- ENOTTY error setting custom speed on linux HOT 4
- UART.read timeout clarifications HOT 3
- Mingw 10.2 compilation is failing HOT 2
- [Question] Is it possible to read a specific but dynamic amount of bytes? HOT 3
- Issues with Fona 808 on Raspberry Pi Zero W HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from circuits_uart.