Code Monkey home page Code Monkey logo

koboldcom's Introduction

KoboldCom

KoboldCom是一个串口通信类库,提供自定义多协议异步解析、数据模型转换等功能。

封装最复杂的数据流异步收发,以及根据协议把接收的数据进行模型映射转换等功能。

类库提供了常见的16进制字节流协议(HexProtocolAnalyzer)和文本字节串协议(TextProtocolAnalyzer)的解析,所以可以使用KoboldCom,快速实现指定协议的数据收发

Wiki How

常见的通讯协议一般是这样的:头+数据长度+数据正文+校验

AA 44 05 01 02 03 04 05 EA

还有一种长这个样子:

$GPGGA,121252.000,3937.3032,N,11611.6046,E,1,05,2.0,45.9,M,-5.7,M,,0000*77

其中$表示开始;GPGGA:命令字;*表示结尾;77校验

这两种协议很常见,所以KoboldCom默认提供了这两种常用的协议解析类(HexProtocolAnalyzer类和TextProtocolAnalyzer类)。

Demo

运行截图

Code Demo

可直接参考/Demo中的例子,包含完整的多协议处理

Usage

// 创建通讯协议和模型转换方法
// Protocol1.cs
...Analyze(){
    // 处理数据模型转换
}


// 创建通讯器
var communicator = new KoboldCom.Communicator(new KoboldCom.SerialPort(), new MyProtocols());
// 通讯器处理接收原始数据
communicator.OnRawDataReceived += Communicator_OnRawDataReceived;
// 自定义模型转换后续操作
Protocol1.OnDataAnalyzed += ProtocolText_OnDataAnalyzed;

Events

KoboldCom.Communicator对上层开放了两个事件

  1. OnDataAnalyzed 从串口接收的数据中解析到符合协议要求的数据包,会触发的事件

  2. OnDataReceived 串口收到新数据,会触发该事件

可以给这两个事件分别绑定处理方法就可以进行对应操作。

More

如果这两种协议的解析方式不适合你的项目要求,可以继承抽象ProtocolAnalyzer类编写子类,一般只需要复写SearchBuffer方法,,也就是数据到协议的处理逻辑就可以了,其他的不需要改动。

TODO:

  • i18n
  • TextProtocolAnalyzer CheckData 数据校验支持

串口模拟与调试

Windows

Thanks

触发要做这个东西的灵感来自文章

License

MIT

koboldcom's People

Contributors

peterrock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

koboldcom's Issues

校验位2个字节

当前框架内固定校验位是1个字节,请问如果校验位是2个字节的时候,该怎么处理?
时候可以增加兼容情况。

大佬您好,目前我正在使用这个库,已经写好了一个工程。有些疑问,阅读完了源码,请问是怎么实现异步解析串口数据,没有找到异步的代码。

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

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.