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

网站维护产品推介定制化开发

网站维护产品推介,定制化开发,百度容易收录的网站,网页制作工具可以分为一直以来#xff0c;玩8088单板机#xff0c;上位机都是使用的绿色现成的串口软件。 今天#xff0c;感觉8088单板机的各部分测试都基本完成了。 本着玩的精神#xff0c;自己写一个上位机的简单串口程序#xff0c;与自己的8088单板机通讯。 功能#xff1a;一个完整…一直以来玩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://www.pierceye.com/news/265294/

相关文章:

  • 中国网站排名100网站建设属于销售费用
  • 最新seo网站优化教程温州微网站
  • 网站双线选择昆明网站制作代理
  • 网站推广优化招聘织梦网站图片设置多大
  • 四川德充建设集团有限公司网站台州seo免费诊断
  • 农庄网站模板网站 文件夹 上传
  • 做长图文网站企业网站开发服务合同
  • 长椿街网站建设九江网站推广徽hyhyk1
  • 贴吧做网站wordpress不兼容ie
  • 上海万网网站建设网络工程专业是什么
  • 到国外建网站自己做的视频发什么网站吗
  • 高校网站平台建设快速网站排名
  • seo技术 如何优化网站内部结构用ps做网站方法
  • vi设计公司网站python做网站好处
  • 北京专业网站建设服务商枣庄建设工程管理局网站
  • 百度移动网站提交深圳做网站的好公司
  • 十大在线编程网站旅游营销型网站
  • 微转app是用网站做的吗win10运行wordpress
  • 微网站建设哪里便宜网站做的跟别人的一样可以吗
  • 合肥优化网站福州网站设计
  • 企业网站制作前期需要什么资料网站 月15g流量够用吗
  • 网络营销网站建设ppt环艺做网站
  • 手机建设银行官方网站网站开发要点
  • 做简历的网站有随州网站建设学校
  • 深圳建设网站企业青白江做网站的公司
  • dm网站制作软件无忧网站建设
  • 如何在自己的网站上做歌单王建设医生网站
  • 科技+杭州+网站建设做效果图的网站有哪些
  • 引流推广网站平台wordpress页面发布失败
  • 南京哪家网站建设好网站开发需要注意的