我理解的IOCP,也就是完成端口

我理解的IOCP,也就是完成端口,不一定是对的,很大可能是理解IOCP的冰山一角,大家见谅 ,使用Windows消息队列有点困难,因此我自己构建了一个模式,效率肯定没有消息队列高了,但是容易。

我理解IOCP就是有线程就负责端口通讯,有线程负责队列,有线程负责消息处理等工作的分工

现在我对串口通讯按照这个模式进行,建立了一个接收数据的Class,一个发送数据的Class,一个处理的Class,一个测试程序,

在我的测试环境中,我把串口的2、3两根引线短接,同时发送同时接收,串口速率9600bps,响应速度大约每秒3组数据,每组数据66字节。

 

方法如下:

PortDataSend.cs  发送Class

using  System;
using  System.Collections.Generic;
using  System.Text;

namespace  IOCPTest.BaseC
{
    
public class PortDataSend
    
{
        
Declare Declare

        
PortDataSend PortDataSend

        
DataSend DataSend

        
mCount mCount


        
DataSendTest3 DataSendTest3


    }

}




PortDataReceived.cs  接收Class

 

using  System;
using  System.Collections.Generic;
using  System.Text;

namespace  IOCPTest.BaseC
{
    
class PortDataReceived
    
{
        
Declare Declare

        
PortDataReceived PortDataReceived

        
Listen Listen

        
ReceiveData ReceiveData

        
ReceiveDataNonReturn ReceiveData

        
ReceiveDataThread ReceiveData

        
mCount mCount


    }


}






DataProcessingIOCP.cs  处理Class

 

using  System;
using  System.Collections.Generic;
using  System.Text;

namespace  IOCPTest.BaseC
{
    
public class DataProcessingIOCP
    
{
        
Declare Declare

        
DataProcessingIOCP DataProcessingIOCP

        
DataProcessing DataProcessing

        
mCount mCount

        
ReadData_0X01 ReadData_0X01

        
ReadData_0X02 ReadData_0X02

        
ReadData_0X02_Request ReadData_0X02_Request

    }

}

frmMain.cs  测试程序

 

using  System;
using  System.Collections.Generic;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Text;
using  System.Windows.Forms;

namespace  IOCPTest
{
    
public partial class frmMain : Form
    
{
        
Declare Declare

        
frmMain frmMain

        
frmMain_Load frmMain_Load

        
Test Test

        
SetText SetText


    }

}



 

frmMain.Designed.cs  测试cheng

 

namespace  IOCPTest
{
    
partial class frmMain
    
{
        
/// <summary>
        
/// 必需的设计器变量。
        
/// </summary>

        private System.ComponentModel.IContainer components = null;

        
/// <summary>
        
/// 清理所有正在使用的资源。
        
/// </summary>
        
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>

        protected override void Dispose(bool disposing)
        
{
            
if (disposing && (components != null))
            
{
                components.Dispose();
            }

            
base.Dispose(disposing);
        }


        
Windows 窗体设计器生成的代码

        
private System.Windows.Forms.TextBox txtSend;
        
private System.Windows.Forms.Label labSend;
        
private System.Windows.Forms.Label labReceive;
        
private System.Windows.Forms.TextBox txtReceive;
        
private System.Windows.Forms.Label labProcessing;
        
private System.Windows.Forms.TextBox txtProcessing;
        
private System.Windows.Forms.Button btnPause;
        
private System.Windows.Forms.Button btnStart;
        
private System.Windows.Forms.Button btnResume;
    }

}


 

 

 

 

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值