Giter VIP home page Giter VIP logo

serialport-lib-dotnet's Introduction

Build status NuGet License

Serial Port library for .Net

Features

  • Easy to use
  • Event driven
  • Hot plug
  • Automatically restabilish connection on error/disconnect
  • Compatible with Mono
  • It overcomes the lack of DataReceived event in Mono

NuGet Package

SerialPortLib is available as a NuGet package.

Run Install-Package SerialPortLib in the Package Manager Console or search for “SerialPortLib” in your IDE’s package management plug-in.

.Net Standard 2.0 notes

When running under Linux you might encouter the following error:

Unable to load shared library 'libnserial.so.1' or one of its dependencies.

in which case serialportstream library is missing.

To fix this error clone and build serialportstream:

git clone https://github.com/jcurl/serialportstream.git
cd serialportstream/
cd dll/serialunix/
./build.sh

Then copy generated files build/libnserial/libnserial.so* to the app folder and lauch the app with LD_LIBRARY_PATH set to the current directory:

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. dotnet exec TestApp.NetCore.dll

Example usage

using SerialPortLib;
...
var serialPort = new SerialPortInput();

// Listen to Serial Port events

serialPort.ConnectionStatusChanged += delegate(object sender, ConnectionStatusChangedEventArgs args) 
{
    Console.WriteLine("Connected = {0}", args.Connected);
};

serialPort.MessageReceived += delegate(object sender, MessageReceivedEventArgs args)
{
    Console.WriteLine("Received message: {0}", BitConverter.ToString(args.Data));
};

// Set port options
serialPort.SetPort("/dev/ttyUSB0", 115200);

// Connect the serial port
serialPort.Connect();

// Send a message
var message = System.Text.Encoding.UTF8.GetBytes("Hello World!");
serialPort.SendMessage(message);

License

SerialPortLib is open source software, licensed under the terms of Apache License 2.0. See the LICENSE file for details.

Who's using this library?

serialport-lib-dotnet's People

Contributors

bounz avatar clancey avatar davidwallis3101 avatar genemars avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.