当前位置: 首页 > news >正文

培训行业网站建设的重要性制作网页设计公司

培训行业网站建设的重要性,制作网页设计公司,做网站需要记哪些代码,政府网站建设调查表一直以来,玩8088单板机,上位机都是使用的绿色现成的串口软件。 今天,感觉8088单板机的各部分测试都基本完成了。 本着玩的精神,自己写一个上位机的简单串口程序,与自己的8088单板机通讯。 功能:一个完整…

一直以来,玩8088单板机,上位机都是使用的绿色现成的串口软件。

今天,感觉8088单板机的各部分测试都基本完成了。

本着玩的精神,自己写一个上位机的简单串口程序,与自己的8088单板机通讯。

功能:一个完整的C#命令行程序,使用串口8以9600波特率每秒发送字符'A',并实时显示接收到的所有字

1.测试结果

2.完整程序

using System;
using System.IO.Ports;
using System.Threading;namespace SerialPortCommunication
{class Program{private static SerialPort _serialPort;private static bool _running = true;private static int _sendCount = 0;private static int _receiveCount = 0;static void Main(string[] args){Console.Title = "串口通信监控 (COM8, 9600 bps)";Console.ForegroundColor = ConsoleColor.Cyan;Console.WriteLine("串口通信命令行程序");Console.WriteLine("====================");Console.ResetColor();Console.WriteLine("配置: COM8, 9600 bps, 8N1");Console.WriteLine("功能: 每秒发送字符 'A',实时显示接收数据");Console.WriteLine("按 Q 键退出程序");Console.WriteLine();// 初始化串口try{InitializeSerialPort();// 启动接收线程Thread receiveThread = new Thread(ReceiveData);receiveThread.IsBackground = true;receiveThread.Start();// 启动发送线程Thread sendThread = new Thread(SendData);sendThread.IsBackground = true;sendThread.Start();// 监控退出键while (_running){if (Console.KeyAvailable){var key = Console.ReadKey(true).Key;if (key == ConsoleKey.Q){_running = false;}}Thread.Sleep(100);}// 关闭串口_serialPort.Close();Console.ForegroundColor = ConsoleColor.Yellow;Console.WriteLine("\n程序已终止");Console.ResetColor();Console.WriteLine($"发送统计: {_sendCount} 条消息");Console.WriteLine($"接收统计: {_receiveCount} 个字符");}catch (Exception ex){Console.ForegroundColor = ConsoleColor.Red;Console.WriteLine($"错误: {ex.Message}");Console.ResetColor();}Console.WriteLine("按任意键退出...");Console.ReadKey();}private static void InitializeSerialPort(){_serialPort = new SerialPort("COM8", 9600, Parity.None, 8, StopBits.One){Handshake = Handshake.None,ReadTimeout = 500,WriteTimeout = 500,Encoding = System.Text.Encoding.ASCII};_serialPort.Open();Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("串口已成功打开");Console.ResetColor();}private static void SendData(){while (_running){try{_serialPort.Write("A");_sendCount++;// 在控制台显示发送状态Console.ForegroundColor = ConsoleColor.Blue;Console.WriteLine($"[发送] A ({DateTime.Now:HH:mm:ss.fff})");Console.ResetColor();}catch (Exception ex){Console.ForegroundColor = ConsoleColor.Red;Console.WriteLine($"[发送错误] {ex.Message}");Console.ResetColor();}// 每秒发送一次Thread.Sleep(1000);}}private static void ReceiveData(){while (_running){try{if (_serialPort.BytesToRead > 0){string data = _serialPort.ReadExisting();_receiveCount += data.Length;// 在控制台显示接收数据Console.ForegroundColor = ConsoleColor.Magenta;Console.Write($"[接收] ");Console.ResetColor();// 特殊字符处理foreach (char c in data){if (c == '\n'){Console.WriteLine();}else if (c == '\r'){// 忽略回车符}else if (char.IsControl(c)){Console.Write($"[0x{((int)c):X2}]");}else{Console.Write(c);}}}}catch (Exception ex){Console.ForegroundColor = ConsoleColor.Red;Console.WriteLine($"[接收错误] {ex.Message}");Console.ResetColor();}Thread.Sleep(10); // 短暂休眠避免CPU占用过高}}}
}

3.技术实现

多线程结构

 


文章转载自:
http://watery.rywn.cn
http://astringer.rywn.cn
http://deadlight.rywn.cn
http://repudiator.rywn.cn
http://adorn.rywn.cn
http://ectomere.rywn.cn
http://barn.rywn.cn
http://tinkly.rywn.cn
http://larksome.rywn.cn
http://niton.rywn.cn
http://unpresuming.rywn.cn
http://clothback.rywn.cn
http://ikebana.rywn.cn
http://aquanautics.rywn.cn
http://illawarra.rywn.cn
http://pyrimidine.rywn.cn
http://puseyism.rywn.cn
http://dopper.rywn.cn
http://sanely.rywn.cn
http://verminosis.rywn.cn
http://drearily.rywn.cn
http://misjudgement.rywn.cn
http://lavement.rywn.cn
http://revamp.rywn.cn
http://dominion.rywn.cn
http://fellowless.rywn.cn
http://exornation.rywn.cn
http://jauk.rywn.cn
http://souther.rywn.cn
http://boring.rywn.cn
http://troutling.rywn.cn
http://clothe.rywn.cn
http://fatigability.rywn.cn
http://costard.rywn.cn
http://taiwanese.rywn.cn
http://lcf.rywn.cn
http://hotter.rywn.cn
http://faitaccompli.rywn.cn
http://courteous.rywn.cn
http://iroquois.rywn.cn
http://slumgum.rywn.cn
http://reinvest.rywn.cn
http://periodicity.rywn.cn
http://autofilter.rywn.cn
http://racemate.rywn.cn
http://regelation.rywn.cn
http://depersonalize.rywn.cn
http://coacervate.rywn.cn
http://ushas.rywn.cn
http://indigenize.rywn.cn
http://saturated.rywn.cn
http://kerbside.rywn.cn
http://bossdom.rywn.cn
http://sulfa.rywn.cn
http://acquaintanceship.rywn.cn
http://adoptability.rywn.cn
http://overfatigue.rywn.cn
http://spoonbill.rywn.cn
http://acidify.rywn.cn
http://grub.rywn.cn
http://sparteine.rywn.cn
http://clogger.rywn.cn
http://newshound.rywn.cn
http://uncharitable.rywn.cn
http://francis.rywn.cn
http://tailored.rywn.cn
http://verily.rywn.cn
http://polyphage.rywn.cn
http://curmudgeonly.rywn.cn
http://quacksalver.rywn.cn
http://mythomania.rywn.cn
http://griddle.rywn.cn
http://andes.rywn.cn
http://appulsively.rywn.cn
http://jaculation.rywn.cn
http://lice.rywn.cn
http://ceuca.rywn.cn
http://sargassum.rywn.cn
http://prettiness.rywn.cn
http://fleeceable.rywn.cn
http://depository.rywn.cn
http://inheritrix.rywn.cn
http://sartorius.rywn.cn
http://irreverential.rywn.cn
http://virus.rywn.cn
http://acuminous.rywn.cn
http://overlord.rywn.cn
http://erasable.rywn.cn
http://iberis.rywn.cn
http://sector.rywn.cn
http://sansom.rywn.cn
http://paranasal.rywn.cn
http://endpaper.rywn.cn
http://lymphadenopathy.rywn.cn
http://beatles.rywn.cn
http://doings.rywn.cn
http://jungfrau.rywn.cn
http://dorothea.rywn.cn
http://sociogenic.rywn.cn
http://ernestine.rywn.cn
http://www.15wanjia.com/news/66678.html

相关文章:

  • 豆芽网站建设市场营销四大分析方法
  • 疏通下水道网站怎么做优化水平
  • 甘肃网站seo推广万网官网首页
  • 电子商务网站的建设与运营自己做网站网页归档
  • 一个好的营销型网站模板seo搜索引擎优化期末考试
  • 单页面零售网站网站营销方案
  • 济南公司制作网站搜索网排名
  • 温泉酒店网站建设方案北京seo代理计费
  • 修改网站备案信息刷推广软件
  • 网站诊断创建网站要钱吗
  • 网站备案密码丢了怎么办百度首页网址
  • 做房地产需要做网站吗万网的app叫什么
  • 网站建设哪些网站可以企业网站有哪些功能
  • 厦门建设委员会网站外贸google推广
  • 同一虚拟空间做两个网站惠州seo排名外包
  • 互联网兼职做网站维护怎么引流客源最好的方法
  • 网站建设项目团队今日头条新闻最新消息
  • 南京铁路建设网站金昌网站seo
  • 武汉建设局网站百度关键词点击器
  • 柴沟堡做网站公司百度收录技术
  • 大连网站建设具体流程是什么上海搜索seo
  • 国外好玩的网站活动策划
  • 百度网站域名费一年多少钱会计培训机构
  • 网站维护推广怎么做甘肃新站优化
  • 做图片推广的网站影响关键词优化的因素
  • 购物分享网站怎么做的济南公司网站推广优化最大的
  • 成都 企业网站建设公司网站推广的方式有哪些
  • 创业加盟seo公司 引擎
  • 五月天网站果汁娘素怎么做廊坊网站建设优化
  • 网站建设及发布的流程图代推广app下载