张高兴的 Windows 10 IoT 开发笔记:串口红外编解码模块 YS-IRTM
This is a Windows 10 IoT Core project on the Raspberry Pi 2/3, coded by C#.
GitHub: https://github.com/ZhangGaoxing/windows-iot-demo/tree/master/IRTM
Image
Reference
https://github.com/ZhangGaoxing/windows-iot-demo/tree/master/IRTM/Reference
Connect
- RXD - UART0 TX (PIN 8)
- TXD - UART0 RX (PIN 10)
- VCC - 5V
- GND - GND
Note
There is one Serial UART available on the RPi2/3: UART0
- Pin 8 - UART0 TX
- Pin 10 - UART0 RX
You need add the following capability to the Package.appxmanifest file to use Serial UART.
<Capabilities>
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
</Capabilities>
What Contains
In IRTM.cs file
/// <summary>
/// Initialize YS-IRTM
/// </summary>
public async Task InitializeAsync();
/// <summary>
/// Send Order
/// </summary>
/// <param name="code">Order</param>
public async Task SendAsync(byte[] code);
/// <summary>
/// Read Order
/// </summary>
public async Task<byte[]> ReadAsync();
/// <summary>
/// Set YS-IRTM Address
/// </summary>
/// <param name="address">Address from 1 to FF</param>
public async Task SetAddressAsync(byte address);
/// <summary>
/// Set YS-IRTM Baud Rate
/// </summary>
/// <param name="rate">Baud Rate</param>
public async Task SetBaudRateAsync(IrtmBaudRate rate);
/// <summary>
/// Return YS-IRTM
/// </summary>
/// <returns>YS-IRTM</returns>
public SerialDevice GetDevice();
/// <summary>
/// Cleanup
/// </summary>
public void Dispose();
How to Use
- First, you need to create a IRTM object. After that you should call InitializeAsync() to initialize.
IRTM irtm = new IRTM();
await irtm.InitializeAsync();
- Second, SendAsync().
irtm.SendAsync(new byte[] { 0x01, 0x02, 0x03 });
- If you want to close the sensor, call Dispose().
irtm.Dispose();
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?