⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 howtouse.txt

📁 这是一个多线程实现的串口通信类
💻 TXT
字号:
                    How to use LsComm
  LsComm is a multiThread Com class that is written by me(Liu_sir).
  Main idea of me is to write a  Easy to Use Com class.
  You can write a little Code and finish the Communication with high
  Efficency,It is what I want to do.   
  there are three Receiving modes of LsComm:
    1.ManualReceiveByQuery
    2.ManualReceiveByConst
    3.AutoReceiveBySignal
    4.AutoReceiveByBreak
 I have writen a Demo Program for the usage of the 4 types of mode;

 there are some Examples:
   1.ManualReceiveByQuery
        #include "ComPort.h"   
       	LsComm::CComPort m_ComPort;//LsComm is namespace in c++
       	m_ComPort.Open(2,LsComm::CComPort::AutoReceiveByquery);
 
        //ReCeive Com Data: 
           DWORD InBufferCount;
           byte pbuffer[2048];
           InBufferCount = m_ComPort.GetInBufferCount();
       if(InBufferCount>0)
       {
          m_ComPort.GetInput(pbuffer,InBufferCount);
       }
       //Write Com Data: 
       	char a[10];
	CString c;
	for(int i=0;i<10;i++)
	{
		a[i]='b';
		c+=a[i];
		c+=" ";
	}
	this->m_ComPort.Output(a,sizeof(a)); 
 
    2.ManualReceiveByConst(it is a ASsync mode)
       #include "ComPort.h"   
       	LsComm::CComPort m_ComPort;//LsComm is namespace in c++
       	m_ComPort.Open(2,LsComm::CComPort::AutoReceiveByConst);
 
        //ReCeive Com Data: 
      DWORD InBufferCount=0;
      byte pbuffer[2048];
      InBufferCount=this->m_ComPort.GetInput(pbuffer,10,1000);
      //above ,I want to Get 10 Bytes in 1 Second
      //Certainly You Can modify these Params;for example
      //InBufferCount=this->m_ComPort.GetInput(pbuffer,100,2000);
      //InBufferCount return the real bytes in Com Receiving Buffer you have Got;
      if(InBufferCount==0)
	   return;
      CString c;
      char a[4];
   
      for(int i=0;i<(int)InBufferCount;i++)
      {
	  ::sprintf(a,"%2.2X",pbuffer[i]);
          c+=a;
	  c+=" ";
      }
      c="接收(Receive):"+c;
      //Write Com Data: 
       	char a[10];
	CString c;
	for(int i=0;i<10;i++)
	{
		a[i]='b';
		c+=a[i];
		c+=" ";
	}
	this->m_ComPort.Output(a,sizeof(a)); 

    /*before use the 3,4 mode,You must write a receive a Funcion witch will be called back 
       in Lscomm. 
    */
    void OnReceiveData(LPVOID pSender,void* pBuf,DWORD InBufferCount)
    {
	CString c;
	byte a[100];
	char b[4]="";
	memcpy(a,pBuf,InBufferCount);
	CLsCommDemoDlg* pDlg = (CLsCommDemoDlg*) pSender;
	CListBox*pList =(CListBox*)pDlg->GetDlgItem(IDC_LIST1);
	for(int i=0;i<(int)InBufferCount;i++)
	{
	  ::sprintf(b,"%2.2X",a[i]);
	   c+=" ";
	   c+=b;
	}
	c="接收(Receive):"+c;
	pList->AddString(c);
     }
    3.AutoReceiveBySignal
        #include "ComPort.h"   
       	LsComm::CComPort m_ComPort;//LsComm is namespace in c++
       	m_ComPort.Open(2,LsComm::CComPort::AutoReceiveBySignal ); 
	m_ComPort.SetReceiveFunc((FOnReceiveData)OnReceiveData,this); 
        m_ComPort.SetBreakHandleFunc(OnComBreak); 
        //ReCeive Com Data:
        in OnReceiveData(LPVOID pSender,void* pBuf,DWORD InBufferCount) //above
        //write data 
        the same as the first mode; 
    4.AutoReceiveByBreak 
        #include "ComPort.h"   
       	LsComm::CComPort m_ComPort;//LsComm is namespace in c++
       	m_ComPort.Open(2,LsComm::CComPort::AutoReceiveByBreak ); 
	m_ComPort.SetReceiveFunc((FOnReceiveData)OnReceiveData,this); 
        m_ComPort.SetBreakHandleFunc(OnComBreak); 
        //ReCeive Com Data:
        in OnReceiveData(LPVOID pSender,void* pBuf,DWORD InBufferCount) //above
        //write data 
        the same as the first mode; 
  You can add Break deal function in each mode but you can remove it if it is no use:
       void OnComBreak(LPVOID pSender,DWORD dwMask,COMSTAT stat)
    {
     //deal with the break of com here
   }
Extra: 
I am a chinese,and My English  is Poor.I am very sorry 
I can,t write fluent illumination for you.
Special Thanks: for PJ Naughter ,He write a Excellent Com CLass:CSerialPort 
witch I have used in my Program. 
                
                                         liu_sir 2003.5

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -