短信收发类SerialStream.cs的用例--SerialStreamReader.cs
发布日期:2021-06-30 19:06:59
浏览次数:3
分类:技术文章
本文共 1352 字,大约阅读时间需要 4 分钟。
using System;
using System.IO;using System.Threading;using LoMaN.IO;
namespace SerialStreamReader {
class App {
// The main serial stream
static SerialStream ss;[STAThread]
static void Main(string[] args) {// Create a serial port
ss = new SerialStream(); try { ss.Open("COM2"); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); return; }// Set port settings
ss.SetPortSettings(9600);// Set timeout so read ends after 20ms of silence after a response
ss.SetTimeouts(20, 0, 0, 0, 0);// Create the StreamWriter used to send commands
StreamWriter sw = new StreamWriter(ss, System.Text.Encoding.ASCII);// Create the Thread used to read responses
Thread responseReaderThread = new Thread(new ThreadStart(ReadResponseThread)); responseReaderThread.Start();// Read all returned lines
for (;;) { // Read command from console string command = Console.ReadLine();// Check for exit command
if (command.Trim().ToLower() == "exit") { responseReaderThread.Abort(); break; }// Write command to modem
sw.WriteLine(command); sw.Flush(); } }// Main loop for reading responses
static void ReadResponseThread() { StreamReader sr = new StreamReader(ss, System.Text.Encoding.ASCII); try { for (;;) { // Read response from modem string response = sr.ReadLine(); Console.WriteLine("Response: " + response); } } catch (ThreadAbortException) { } } }}转载地址:https://linuxstyle.blog.csdn.net/article/details/1536680 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2024年04月20日 18时00分12秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
YOLO算法(三)—— Yolov3 & Yolo系列网络优缺点
2019-04-30
Python的__future__模块
2019-04-30
计算机视觉中的cost-volume的概念具体指什么(代价体积)
2019-04-30
启发函数heuristic 与 A*
2019-04-30
Image Pyramid(图像金字塔)
2019-04-30
Oracle 作业记录
2019-04-30
putty连接AWS配置(multimedia project)
2019-04-30
Hourglass Network 沙漏网络 (pose estimation姿态估计)
2019-04-30
OpenCV实战(二)——答题卡识别判卷
2019-04-30
目标检测神经网络的发展历程(52 个目标检测模型)
2019-04-30
Boundary loss 损失函数
2019-04-30
tensorflow使用tensorboard进行可视化
2019-04-30
凸优化 convex optimization
2019-04-30
数据库索引 & 为什么要对数据库建立索引 / 数据库建立索引为什么会加快查询速度
2019-04-30
IEEE与APA引用格式
2019-04-30
research gap
2019-04-30