如果,翻看我之前的博客,会找到一篇用I/O模拟IIC通信的程序文章。好吧,如果找不到可以点击这里,这里就不在赘述了,系统也已经完全调试通过了。
今天的任务是,把测试得到的数据在上位机的界面上显示出来,于是键盘手花了两天的时间模仿着巨人的肩膀通过了用C#编写的界面程序,界面很简单就像下面显示的一样。
下面就一步一步给大伙展示一下我的程序吧。
C#非常的强大而且友好,串口的通信可以通过编程环境(这里我用的是Visual Studio 2010),如果有需要的话可以给我信息,我有完整版的安装包。如下图,简单的调用和选择就完成了串口的基本配置。
JS9hkJ9uOCRDONbW/zcvlIgfAUzC4VH6vU63Rr41PDJ/6+/xz4fKGtifzytt/nJx8Odr0dEAyoxRNK1vqWt+ciR4cXcdX4wno1mLP8gYsZVKIntiLZx3l7QzzYXanEAaW0aJ0gblf8/Hp5mFnbURADyYeacnQblZ0lrNLl1wk7NIlxwSI85JHLxfgCxhcqihr2phdGI2N4RWWrWxo5avaOq5wenxhcl5dxxWKppVvJ7fquMLX9JRXjwTeumR5ezYPCPN0YQlymdSxqrG6ZD9kbcYT4RTimHO1jcRlVIcZjzhSqUyJM0mc5uzKJVcJu5mX7BIgXppnLxfgCxhc6o2OHomj9RWV8nve8gTDXP5g09OBhpbe2scvqhu7jTVeKYffyCjoOE/3vcYz4XwI7sglxzdvtL1LEjbZMl24H8pOXXKSs42lrg82N+u1Sx68XIAvYHCp8lrpYu/LlQ1tRb1gflkjk6sr6gWSWZVIpqyoF4xIFEPjiop6Qd/gwuu/R4b99czOe3Dmku0tOy/dWrA5d8mxZDKNrR26RBiU4jKqu3nJJkMB03wP45CzsR3CBZqe47lImPAkc7sE7Gq87V8uwBcwuHTtVtPKhla+pmVx+DNyzdSCmsXhi2XKd1NbLA5/UKwYGFOwOPye1xvdwhls8xJy+gzAjUvI7bMHRDjGfY1nLTjJ6Qy30wIhQ5uZxC5nhJBtDWa87XGZsLXC3DYB05FWCbd5uQBfwODSETLVw/j4izivXAKAfQAGlwAAQOASAOACXAIAPIBLAIAHcAkA8A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zHJjHvxCwD7/tW4womaK3TSngDdiA3QvhCyT6kYSObMopiLeE8Te+iPO0Wy7eF8asY1VDhPzkLVtYynq2ZL1QGNM/C7oV6tzP6ktzOk5j+AuKq8LxG/6ZqPh3KUxwgCiU04G6Pa1limTCw8HZvQbi8tx85DUam1st4qOgphTHrb6nMwBoA05ftW+VBFZ64rSdWxS8ILI2Ilxjudh31NpH7ZjPdBemjl38DyGmTHPs8hgbBsYmFszYx6ABwysQUulUggb5H8AHjAwt2bBg/wPwAMG5taMmOc7zyIDeMDA3JoR8wA8YGCNWiqVQtgg/wPwgIG5NQse5H8AHjAwtwYxDxiYR4OYBwzMo0HMAwbm0SDmAQPzaBDzgIF5NIh5wMA8WiqV2vedZ/d959mOnr59AA8YmHuz4OnuHQR4wMAaMBTz7PvO3yADeMDA3BqKeQAeMLCGLZVKIWyQ/wF4wMDcmgUP8j8ADxiYW4OYBwzMo0HMAwbm0SDmAQPzaHTMkwKBQK5FxDzdvYP74n+DDD7DZ/js/rMy+ONfDf74V4N/+/fGh+Z9/ttfHlZ/+uR/Gezo+a/74t9Hu+/o6bMOBT7D52h9VvS90t2799L/MfuPw+/+t5/9ryf+88sdPd/fF47rB3yGz94+K3fu3Ll79y76e/fu3Xv37t3FdOfOHfRVrVa7ffu2teT27dvWJnfu3KnVatZXVoF4ybVa7c6dO/fu3fvmm29m5xd/9PobB//TUQvl8FxL4DN8dv/5/wMAG/hca/4W7QAAAABJRU5ErkJggg==" alt="" />
下面主要就是编程的问题了,在窗体Load的进程中可以完成串口的启动
1 private void Form1_Load(object sender, EventArgs e) 2 { 3 serialPort1.PortName = "COM4"; 4 serialPort1.BaudRate = 9600; 5 serialPort1.Open(); 6 this.textBox1.Clear(); 7 thread = new Thread(CrossThreadFlush); 8 thread.IsBackground = true; 9 thread.Start(); 10 }
而后就是读取数据的操作,这时候用到事件
class="cnblogs_code">1 private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
在这个事件里面编程就可以了,但是在对窗体内文本进行操作的时候会发现出现了线程的冲突和错误。网上给出的一种解决方法是采用代理的方式具体的程序如下
1 public partial class Form1 : Form 2 { 3 private delegate void FlushClient(); //代理 4 Thread thread = null; 5 uint DateTemp; 6 uint Datefalg = 0; 7 uint counter = 0; 8 uint DateTemp1 = 0; 9 uint TMP1; 10 uint RH1; 11 uint PRESS1; 12 double TMP; 13 double RH; 14 double PRESS; 15 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 22 private void Form1_Load(object sender, EventArgs e) 23 { 24 serialPort1.PortName = "COM4"; 25 serialPort1.BaudRate = 9600; 26 serialPort1.Open(); 27 this.textBox1.Clear(); 28 thread = new Thread(CrossThreadFlush); 29 thread.IsBackground = true; 30 thread.Start(); 31 } 32 33 34 private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) 35 { 36 counter=counter+1; 37 DateTemp = (uint)this.serialPort1.ReadByte(); 38 if (DateTemp == 0xF1) 39 { 40 Datefalg = 1; 41 DateTemp1 = 0; 42 DateTemp = 0; 43 counter=0; 44 } 45 if (DateTemp == 0xF2) 46 { 47 Datefalg = 2; 48 DateTemp1 = 0; 49 DateTemp = 0; 50 counter=0; 51 } 52 if (DateTemp == 0xF3) 53 { 54 Datefalg = 3; 55 DateTemp1 = 0; 56 DateTemp = 0; 57 counter=0; 58 } 59 if (Datefalg == 1 && DateTemp != 0xF1) 60 { if(counter==1) 61 DateTemp1 = DateTemp; 62 if (counter == 2) 63 { 64 TMP1 = DateTemp1 * 256 + DateTemp; 65 TMP = (0.01 * TMP1) - 40; 66 } 67 68 } 69 if (Datefalg == 2 && DateTemp != 0xF2) 70 { 71 if (counter == 1) 72 DateTemp1 = DateTemp; 73 if (counter == 2) 74 { 75 RH1 = DateTemp1 * 256 + DateTemp; 76 RH = (0.0405 * RH1) - 4-0.0000028*RH1*RH1; 77 } 78 79 } 80 if (Datefalg == 3 && DateTemp != 0xF3) 81 { 82 if (counter == 1) 83 DateTemp1 = DateTemp; 84 if (counter == 2) 85 { 86 PRESS1 = DateTemp1 * 256 + DateTemp; 87 PRESS = (PRESS1-16384)*90/16384 + 30; 88 } 89 } 90 } 91 92 private void CrossThreadFlush() 93 { 94 while (true) 95 { 96 //将sleep和无限循环放在等待异步的外面 97 Thread.Sleep(500); 98 ThreadFunction(); 99 } 100 } 101 102 private void ThreadFunction() 103 { 104 if (this.textBox1.InvokeRequired)//等待异步 105 { 106 FlushClient fc = new FlushClient(ThreadFunction); 107 this.Invoke(fc); //通过代理调用刷新方法 108 109 } 110 else 111 textBox1.Text = TMP.ToString("0.00"); 112 if (this.textBox2.InvokeRequired)//等待异步 113 { 114 FlushClient fc = new FlushClient(ThreadFunction); 115 this.Invoke(fc); //通过代理调用刷新方法 116 117 } 118 else 119 textBox2.Text = RH.ToString("0.00"); 120 if (this.textBox3.InvokeRequired)//等待异步 121 { 122 FlushClient fc = new FlushClient(ThreadFunction); 123 this.Invoke(fc); //通过代理调用刷新方法 124 125 } 126 else 127 textBox3.Text = PRESS.ToString("0.00"); 128 129 } 130 131 132 }
通过这样的一番调试之后才得以程序正确的运行,由于工科程序员和计算机程序员的编程思想还是有差别的,所以写的不好的地方请轻喷。
【重要通知】
为了丰富给位程序狗&硬件狗们的业余生活,我们做了一个艰难的决定,我们“泡泡鱼工作室”开通了“硬件为王”公共订阅号,微信号:king_hardware。关注智能硬件和互联网创业,以及日常学习资料/搞笑段子推送。请猛扫下面的二维码!
Powered By Bubble_fish ; Email:bubble_fish@yeah.net