c# - 如何使用 C# 可靠地读取串行端口的 CTS 和 DSR 状态
问题描述
回到过去(15 年前),我在 Delphi 上做了一个小程序来监控、记录和显示来自 PC 和 I2C 传感器之间的 I2C 通信的信号的时间图。现在我需要同样的东西,我有很大的问题来适应 C#。一般来说,我将 CTS 线从串行端口连接到 I2C 的 SCL 线,并将 DSR 连接到 SDA。然后我启动一个线程来读取 CTS 和 DSR 的状态(带有无限循环)并将它们保存到一个文件中。这是代码:
void InitCommPort()
{
myCOMport = new SerialPort("COM2", 9600);
myCOMport.Open();
}
while (!bExit)
{
CTS_Signal = myCOMport.CtsHolding;
DSR_Signal = myCOMport.DsrHolding;
}
The problem is that i can not get the signals[CTS and DSR] fast enough to reconstruct the communication protocol. Actually mostly i can get only one of the signals, and it is just part of the all transfer. I tried also "SerialPinChangedEventHandler", but I'm receiving only '0' as a result. Obviously I'm missing something or just the SerialPort-Class is made in this way. Is it possible to be done with C#? I do not want to install Windows XP for something simple like that. Any help will be appreciated. Thank You in advance
解决方案
推荐阅读
- android - Retrofit能否支持Android中同一个api的不同版本
- python-3.x - OPENPYXL For 循环遍历指定列中的每个单元格并将其值替换为大写字母
- python - 具有虚拟环境的 WSGI 应用程序中的 ImportError
- django - 如何与父级一起显示多个相关的外键
- angular - 没有使用 Angular Bootstrap 的 NgbDropdown 提供程序
- r - 时间序列数据分析
- javascript - AngularJS ng-messages在有效输入/缩小后没有隐藏 - 捆绑
- java - Spring WebExceptionHandler 顺序
- python - 在 Python 中安全地覆盖和擦除文件
- rust - 在 Rust 的多个向量中拥有一个结构实例