DFS_Shuo_Chen 1 жил өмнө
parent
commit
823f6cff57
56 өөрчлөгдсөн 2221 нэмэгдсэн , 0 устгасан
  1. BIN
      Bin/ReadSensor.exe
  2. 22 0
      ReadSensor.sln
  3. BIN
      ReadSensor.v12.suo
  4. 279 0
      ReadSensor/ComHandle.cpp
  5. 49 0
      ReadSensor/ComHandle.h
  6. 2 0
      ReadSensor/Debug/ReadSensor.log
  7. BIN
      ReadSensor/Debug/ReadSensor.tlog/CL.read.1.tlog
  8. BIN
      ReadSensor/Debug/ReadSensor.tlog/CL.write.1.tlog
  9. 2 0
      ReadSensor/Debug/ReadSensor.tlog/ReadSensor.lastbuildstate
  10. BIN
      ReadSensor/Debug/ReadSensor.tlog/cl.command.1.tlog
  11. BIN
      ReadSensor/Debug/ReadSensor.tlog/link.command.1.tlog
  12. BIN
      ReadSensor/Debug/ReadSensor.tlog/link.read.1.tlog
  13. BIN
      ReadSensor/Debug/ReadSensor.tlog/link.write.1.tlog
  14. BIN
      ReadSensor/Debug/ReadSensor.tlog/rc.command.1.tlog
  15. BIN
      ReadSensor/Debug/ReadSensor.tlog/rc.read.1.tlog
  16. BIN
      ReadSensor/Debug/ReadSensor.tlog/rc.write.1.tlog
  17. 588 0
      ReadSensor/MySeries.cpp
  18. 80 0
      ReadSensor/MySeries.h
  19. 99 0
      ReadSensor/ReadMe.txt
  20. 110 0
      ReadSensor/ReadSensor.cpp
  21. 32 0
      ReadSensor/ReadSensor.h
  22. BIN
      ReadSensor/ReadSensor.rc
  23. 143 0
      ReadSensor/ReadSensor.vcxproj
  24. 81 0
      ReadSensor/ReadSensor.vcxproj.filters
  25. 414 0
      ReadSensor/ReadSensorDlg.cpp
  26. 50 0
      ReadSensor/ReadSensorDlg.h
  27. 21 0
      ReadSensor/Release/ReadSensor.Build.CppClean.log
  28. 3 0
      ReadSensor/Release/ReadSensor.log
  29. BIN
      ReadSensor/Release/ReadSensor.tlog/CL.read.1.tlog
  30. BIN
      ReadSensor/Release/ReadSensor.tlog/CL.write.1.tlog
  31. 2 0
      ReadSensor/Release/ReadSensor.tlog/ReadSensor.lastbuildstate
  32. BIN
      ReadSensor/Release/ReadSensor.tlog/cl.command.1.tlog
  33. BIN
      ReadSensor/Release/ReadSensor.tlog/link.command.1.tlog
  34. BIN
      ReadSensor/Release/ReadSensor.tlog/link.read.1.tlog
  35. BIN
      ReadSensor/Release/ReadSensor.tlog/link.write.1.tlog
  36. BIN
      ReadSensor/Release/ReadSensor.tlog/rc.command.1.tlog
  37. BIN
      ReadSensor/Release/ReadSensor.tlog/rc.read.1.tlog
  38. BIN
      ReadSensor/Release/ReadSensor.tlog/rc.write.1.tlog
  39. 5 0
      ReadSensor/conn.ini
  40. 72 0
      ReadSensor/global.cpp
  41. 22 0
      ReadSensor/global.h
  42. BIN
      ReadSensor/res/ReadSensor.ico
  43. BIN
      ReadSensor/res/ReadSensor.rc2
  44. BIN
      ReadSensor/resource.h
  45. 8 0
      ReadSensor/stdafx.cpp
  46. 54 0
      ReadSensor/stdafx.h
  47. 8 0
      ReadSensor/targetver.h
  48. 6 0
      clear.bat
  49. BIN
      安装包/20210506/ReadSensor.exe
  50. 11 0
      安装包/copy.bat
  51. BIN
      安装包/传感器数据读取工具 V1.1.zip
  52. BIN
      安装包/传感器数据读取工具 V1.1/files/ReadSensor/ReadSensor.exe
  53. 8 0
      安装包/传感器数据读取工具 V1.1/files/bat/copy.bat
  54. 31 0
      安装包/传感器数据读取工具 V1.1/files/bat/shortcut.bat
  55. 18 0
      安装包/传感器数据读取工具 V1.1/安装.bat
  56. 1 0
      安装包/传感器数据读取工具 V1.1/安装说明.txt

BIN
Bin/ReadSensor.exe


+ 22 - 0
ReadSensor.sln

@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.40629.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReadSensor", "ReadSensor\ReadSensor.vcxproj", "{7404B4EA-7E6C-4286-9E49-D52B957E2F58}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Release|Win32 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{7404B4EA-7E6C-4286-9E49-D52B957E2F58}.Debug|Win32.ActiveCfg = Debug|Win32
+		{7404B4EA-7E6C-4286-9E49-D52B957E2F58}.Debug|Win32.Build.0 = Debug|Win32
+		{7404B4EA-7E6C-4286-9E49-D52B957E2F58}.Release|Win32.ActiveCfg = Release|Win32
+		{7404B4EA-7E6C-4286-9E49-D52B957E2F58}.Release|Win32.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

BIN
ReadSensor.v12.suo


+ 279 - 0
ReadSensor/ComHandle.cpp

@@ -0,0 +1,279 @@
+#include "stdafx.h"
+#include "ComHandle.h"
+#include "global.h"
+#include <string>
+#include "ReadSensor.h"
+using namespace std;
+
+typedef union
+{
+	float f;
+
+	char c[4];
+} UNION_FLOAT_CONV_TypeDef;
+
+float __ltobf(BYTE* pc)
+{
+	UNION_FLOAT_CONV_TypeDef d1, d2;
+
+	d1.c[0] = *pc;
+	d1.c[1] = *(pc + 1);
+	d1.c[2] = *(pc + 2);
+	d1.c[3] = *(pc + 3);
+
+
+	//d1.c[0] = 0x41;
+	//d1.c[1] = 0xcc;
+	//d1.c[2] = 0x00;
+	//d1.c[3] = 0x00;
+
+	d2.c[0] = d1.c[3];
+	d2.c[1] = d1.c[2];
+	d2.c[2] = d1.c[1];
+	d2.c[3] = d1.c[0];
+
+	return d2.f;
+}
+
+
+extern float g_pressure;
+extern float g_tem;
+extern int g_readtype;
+
+
+ComHandle::ComHandle()
+{
+
+}
+
+
+int ComHandle::opencom(int portno)
+{
+
+
+	closecom();
+
+	if (portno > 0)
+	{
+		//新建串口通讯对象
+		m_pSerial = new CMyCESeries();
+		m_pSerial->m_OnSeriesRead = OnComRead;
+		//m_nPortNo = portNo;
+
+
+		int rtn = m_pSerial->OpenPort(this, portno,19200);
+
+		//打开串口
+		if (rtn)
+		{
+			addText("打开串口" + std::to_string(portno) + "成功");
+		}
+		else
+		{
+			addText("打开串口" + std::to_string(portno) + "失败");
+
+
+			if (m_pSerial)
+			{
+				delete m_pSerial;
+				m_pSerial = NULL;
+			}
+		}
+
+		return rtn;
+	}
+	else
+		return false;
+
+}
+
+
+int ComHandle::closecom()
+{
+	if (m_pSerial)
+	{
+		m_pSerial->ClosePort();
+
+		delete m_pSerial;
+		m_pSerial = NULL;
+
+		return true;
+	}
+	return false;
+}
+
+int ComHandle::senddata()
+{
+
+
+
+	//int nRc = m_pSerial->WriteSyncPort(buff, len);
+	//return nRc;
+
+	return false;
+}
+
+void ComHandle::addText(string str)
+{
+	if (m_pRichEdit)
+	{
+		m_pRichEdit->SetSel(-1, -1);
+
+		m_pRichEdit->ReplaceSel((str+ string("\r\n")).c_str());
+
+		m_pRichEdit->PostMessage(WM_VSCROLL, SB_BOTTOM, 0);
+	}
+}
+
+
+bool ComHandle::ProcessComData(BYTE* buf, DWORD bufLen)
+{
+	int datalen = 0;
+	if (g_readtype == 0)
+	{
+		datalen = 9;
+	}
+	else if (g_readtype == 1)
+	{
+		datalen = 9;
+	}
+	else if (g_readtype == 2)
+	{
+		datalen = 13;
+	}
+	else if (g_readtype == 10)
+	{
+		datalen = 8;
+	}
+
+	if (bufLen > 13 || CommBufLen > 13)
+	{
+		addText("收到数据长度过长,弃用");
+		memset(CommBuf, 0, 128);
+		CommBufLen = 0;
+		return false;
+	}
+
+
+	CString strS = "";
+	for (int i = 0; i < bufLen; ++i)
+	{
+		CString strW;
+		CStringA str;
+		strW.Format(_T("%.2x"), buf[i]);
+		strS += strW + " ";
+	}
+
+	CString str;
+	str.Format("%s 收到数据:%s", getCurrentTime().c_str(), strS);
+	addText(str.GetString());
+
+
+	if (CommBufLen == 0)
+	{
+		memcpy(CommBuf, buf, bufLen);
+		CommBufLen = bufLen;
+	}
+	else
+	{
+		memcpy(CommBuf + CommBufLen, buf, bufLen);
+		CommBufLen += bufLen;
+	}
+
+
+
+	if (CommBufLen != datalen)
+	{
+		return false;
+	}
+
+
+
+	strS = "";
+	for (int i = 0; i < CommBufLen; ++i)
+	{
+		CString strW;
+		CStringA str;
+		strW.Format(_T("%.2x"), CommBuf[i]);
+		strS += strW + " ";
+	}
+
+	
+	str.Format("%s 收到数据合并:%s", getCurrentTime().c_str(), strS);
+	addText(str.GetString());
+
+
+
+
+
+	if (g_readtype == 0)
+	{
+		g_pressure = __ltobf(&CommBuf[3]);;
+	}
+	else if (g_readtype == 1)
+	{
+		g_tem = __ltobf(&CommBuf[3]);;
+	}
+	else if (g_readtype == 2)
+	{
+		g_pressure = __ltobf(&CommBuf[3]);;
+		g_tem = __ltobf(&CommBuf[3+4]);;
+	}
+
+
+	memset(CommBuf, 0, 128);
+	CommBufLen = 0;
+
+	//float a;
+	//a = __ltobf();
+	//printf("%0.4f \n", a);
+
+
+	PostMessage(theApp.GetMainWnd()->GetSafeHwnd(), WM_DATARECEIVED, 0, 0);
+
+
+
+
+	return true;
+}
+
+
+void ComHandle::linkRichEdit(CRichEditCtrl* pRichEdit)
+{
+	m_pRichEdit = pRichEdit;
+}
+
+
+int ComHandle::senddata(const BYTE*buf, DWORD bufLen)
+{
+	if (!m_pSerial)
+	{
+		addText("串口未成功打开");
+		return false;
+	}
+
+
+	int nRc = m_pSerial->WriteSyncPort(buf, bufLen);
+
+	if (nRc)
+	{
+		CString strS = "";
+		for (int i = 0; i < bufLen; ++i)
+		{
+			CString strW;
+			CStringA str;
+			strW.Format(_T("%.2x"), buf[i]);
+			strS += strW + " ";
+		}
+
+		addText(getCurrentTime() + string(" 发送:") + strS.GetString());
+	}
+	else
+	{
+		addText("发送数据失败");
+	}
+
+
+
+	return nRc;
+}

+ 49 - 0
ReadSensor/ComHandle.h

@@ -0,0 +1,49 @@
+#pragma once
+
+#include "MySeries.h"
+
+#include <string>
+using std::string;
+
+class ComHandle
+{
+public:
+	ComHandle();
+
+	int opencom(int portno);
+
+	int closecom();
+
+	int senddata();
+
+	void addText(string str);
+
+	bool ProcessComData(BYTE* buf, DWORD bufLen);
+
+	static void CALLBACK OnComRead(void * pOwner, BYTE* buf, DWORD bufLen)
+	{
+		if (bufLen <= 1024)
+		{
+			ComHandle* pThis = (ComHandle*)pOwner;
+
+			pThis->ProcessComData(buf, bufLen);
+		}
+	}
+
+
+	void linkRichEdit(CRichEditCtrl* pRichEdit);
+
+	int senddata(const BYTE*buf, DWORD bufLen);
+
+
+	BYTE CommBuf[128];
+	unsigned CommBufLen = 0;
+
+
+protected:
+	CMyCESeries* m_pSerial;
+	CRichEditCtrl* m_pRichEdit;
+	
+};
+
+

+ 2 - 0
ReadSensor/Debug/ReadSensor.log

@@ -0,0 +1,2 @@
+  ReadSensorDlg.cpp
+  ReadSensor.vcxproj -> C:\Bitbucket\ReadSensor\Bin\ReadSensor.exe

BIN
ReadSensor/Debug/ReadSensor.tlog/CL.read.1.tlog


BIN
ReadSensor/Debug/ReadSensor.tlog/CL.write.1.tlog


+ 2 - 0
ReadSensor/Debug/ReadSensor.tlog/ReadSensor.lastbuildstate

@@ -0,0 +1,2 @@
+#TargetFrameworkVersion=v4.0:PlatformToolSet=v120_xp:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit
+Debug|Win32|C:\Bitbucket\ReadSensor\|

BIN
ReadSensor/Debug/ReadSensor.tlog/cl.command.1.tlog


BIN
ReadSensor/Debug/ReadSensor.tlog/link.command.1.tlog


BIN
ReadSensor/Debug/ReadSensor.tlog/link.read.1.tlog


BIN
ReadSensor/Debug/ReadSensor.tlog/link.write.1.tlog


BIN
ReadSensor/Debug/ReadSensor.tlog/rc.command.1.tlog


BIN
ReadSensor/Debug/ReadSensor.tlog/rc.read.1.tlog


BIN
ReadSensor/Debug/ReadSensor.tlog/rc.write.1.tlog


+ 588 - 0
ReadSensor/MySeries.cpp

@@ -0,0 +1,588 @@
+/*-----------------------------------------
+* Copyright (c) 2008 Eric Wong
+* 本版紧供读者参考,不得用于任何商业行为
+*
+* 文件名称: CESeries.cpp
+* 文件标识: 
+* 摘要:用于封装WINCE 串口通讯
+*
+* 当前版本: 1.0
+* 作者: 汪兵 Eric Wong
+* 完成日期: 2008年1月17日
+*
+* 取代版本:
+* 原作者: 
+* 完成日期: 
+----------------------------------------*/
+#include "StdAfx.h"
+#include "MySeries.h"
+
+//构造函数
+CMyCESeries::CMyCESeries(UINT portNo, UINT baud, UINT parity, UINT databits, UINT stopbits)
+:m_portNo(portNo)
+,m_baud(baud)
+,m_parity(parity)
+,m_databits(databits)
+,m_stopbits(stopbits)
+,m_hReadThread(NULL)
+,m_hReadCloseEvent(NULL)
+{
+	//m_portNo		= portNo;		//串口号使用串口1 CAN模块和GPS共用
+	//m_baud			= baud;		//波特率
+	//m_parity		= parity;		//奇偶校验,0-None,1-Odd,2-Even
+	//m_databits		= databits;		//数据位
+	//m_stopbits		= stopbits;		//停止位 0-停止位1,1-停止位1.5,2-停止位2
+
+	//初始化内部变量
+	m_hComm = INVALID_HANDLE_VALUE;
+	m_OnSeriesRead = NULL;
+	m_hReadCloseEvent = NULL;
+	m_bOpened = false;
+
+	bCanComRead		= true;
+	m_bSyncOrAsync	= true;//使用同步方式或者异步方式(重叠方式),默认值为true:异步方式
+
+	memset(&m_olWrite,0,sizeof(OVERLAPPED));
+}
+
+//析构函数
+CMyCESeries::~CMyCESeries()
+{
+	if (m_bOpened)
+		ClosePort();
+}
+
+//串口读线程函数
+DWORD CMyCESeries::ReadThreadFunc(LPVOID lparam)
+{
+	CMyCESeries *ceSeries = (CMyCESeries*)lparam;
+	
+	
+	BYTE * readBuf = NULL;//读取的字节
+	DWORD actualReadLen=0;//实际读取的字节数
+	DWORD willReadLen;
+	
+	DWORD dwReadErrors;
+	COMSTAT	cmState;
+	//异步方式下将使用这些变量
+	//LPOVERLAPPED 
+	OVERLAPPED olWait;
+	//memset(&olWaite,0,sizeof(olWaite));  
+	memset(&olWait,0,sizeof(OVERLAPPED)); 
+    olWait.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL); 
+	
+	//同步方式,将使用该变量
+	DWORD	 evtMask;
+	
+
+
+	// 清空缓冲,并检查串口是否打开。
+	ASSERT(ceSeries->m_hComm !=INVALID_HANDLE_VALUE); 
+	
+	
+	//清空串口
+	PurgeComm(ceSeries->m_hComm, PURGE_RXCLEAR | PURGE_TXCLEAR );
+	
+	SetCommMask (ceSeries->m_hComm, EV_RXCHAR | EV_CTS | EV_DSR );//设置3个串口事件
+	
+	//可以查看串口设置了哪些事件
+	//DWORD dwMask1;
+	//GetCommMask(ceSeries->m_hComm,&dwMask1);
+
+	OVERLAPPED olRead;
+	memset(&olRead,0,sizeof(OVERLAPPED)); 
+	olRead.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
+
+
+	while(TRUE)
+	{
+		if(ceSeries->m_bSyncOrAsync)//异步方式下
+		{
+			DWORD dwCommStatus = 0;
+			BOOL bWait1=0;
+			bWait1= WaitCommEvent(ceSeries->m_hComm,&dwCommStatus,&olWait);//如果以上设置的3个事件中任何一个发生了,这里主要是监测接收缓冲区中有数据时
+			//while(!bWait1);//等待WaitCommEvent返回为TRUE,再往下执行,这种方式行不通,重叠方式(异步方式)时,该函数一直返回为false,
+			DWORD dwByte; //norains:It is only suitable for the GetOverlappedResult(),not undefined here.
+			if(GetOverlappedResult(ceSeries->m_hComm,&olWait,&dwByte,TRUE) == FALSE)//正常清空下,会一直在该函数阻塞,直到olWaite中的hEvent事件发生了
+			//则该函数不阻塞了,并且返回值为True
+			{
+				 if(GetLastError() != ERROR_IO_PENDING)
+				 {
+					 return 0x30;
+				 }
+				 //Clear the error flag
+				 DWORD dwErrors;
+				 COMSTAT comStat;
+				 memset(&comStat,0,sizeof(comStat));
+				 ClearCommError(ceSeries->m_hComm,&dwErrors,&comStat);
+				 return 0x35;
+			}
+			
+				//表示串口收到字符		
+			if (dwCommStatus & EV_RXCHAR) 
+			{
+				ClearCommError(ceSeries->m_hComm,&dwReadErrors,&cmState);
+				willReadLen = cmState.cbInQue ;
+				if (willReadLen <= 0)
+				{
+					continue;
+				}
+				
+				//异步方式
+				//分配内存
+				readBuf = new BYTE[willReadLen+1];
+				ZeroMemory(readBuf,willReadLen+1);
+				//读取串口数据
+
+				//异步方式
+				if(ReadFile(ceSeries->m_hComm, readBuf, willReadLen, &actualReadLen,&olRead)==FALSE)//异步操作,在读取完成以后返回TRUE
+				{
+					//释放内存
+					delete[] readBuf;
+					readBuf = NULL;
+
+					if(GetLastError() != ERROR_IO_PENDING)
+						return 0x40;
+
+					if(GetOverlappedResult(ceSeries->m_hComm,&olRead,&actualReadLen,TRUE) == FALSE)
+						return 0x45;
+
+					if(actualReadLen == 0)
+						return 0x50;
+				}
+				else//缓冲区中的数据读取完时
+				{
+					//如果读取的数据大于0,
+					if (actualReadLen>0)
+					{
+						//触发读取回调函数
+						if (ceSeries->m_OnSeriesRead)
+						{
+							ceSeries->m_OnSeriesRead(ceSeries->m_pOwner,readBuf,actualReadLen);
+						}
+					}
+					//释放内存
+					delete[] readBuf;
+					readBuf = NULL;
+				}
+			}
+			
+		}
+		else//同步方式下
+		{
+				if (WaitCommEvent(ceSeries->m_hComm,&evtMask,0))
+				{	
+					SetCommMask (ceSeries->m_hComm, EV_RXCHAR | EV_CTS | EV_DSR );
+					//表示串口收到字符
+					if (evtMask & EV_RXCHAR)
+					{
+						ClearCommError(ceSeries->m_hComm,&dwReadErrors,&cmState);
+						willReadLen = cmState.cbInQue ;
+						if (willReadLen <= 0)
+						{
+							continue;
+						}
+						
+						//分配内存
+						readBuf = new BYTE[willReadLen];
+						ZeroMemory(readBuf,willReadLen);
+						//读取串口数据
+						ReadFile(ceSeries->m_hComm, readBuf, willReadLen, &actualReadLen,0);
+						
+						//如果读取的数据大于0,
+						if (actualReadLen>0)
+						{
+							//触发读取回调函数
+							if (ceSeries->m_OnSeriesRead)
+							{
+								ceSeries->m_OnSeriesRead(ceSeries->m_pOwner,readBuf,actualReadLen);
+							}
+						}
+
+						//释放内存
+						delete[] readBuf;
+						readBuf = NULL;
+					}
+				}
+		}
+
+		
+		
+		//每次读线程执行到该处时,都会等待(或者叫阻塞)10milseconds,看是否关闭串口事件是否发生
+		//在ClosePort()函数体中调用了CloseHandle(m_hReadCloseEvent);来使得该事件有信号,我觉得可以用SetEvent(m_hReadCloseEvent)代替,该函数也是使得事件有信号
+		//当执行了ClosePotr()函数后,说明该事件已经发生了,则当在读线程函数中执行到此处时,
+		//将会跳出while(true),从而退出读线程,
+		if (WaitForSingleObject(ceSeries->m_hReadCloseEvent, 10) == WAIT_OBJECT_0)//
+		{
+			TRACE("线程ReadThreadFunc退出\n");
+			break;
+		}
+	}
+
+	//关闭事件
+	CloseHandle( olRead.hEvent );
+	CloseHandle( olWait.hEvent );
+
+	//释放内存
+	if(readBuf)
+	{
+		delete[] readBuf;
+		readBuf = NULL;
+	}
+
+	ExitThread(0);
+	return 0;
+}
+
+//关闭读线程
+void CMyCESeries::CloseReadThread()
+{
+	if( m_hComm != INVALID_HANDLE_VALUE )
+	{
+	//	SetEvent(m_hReadCloseEvent);
+	//	CloseHandle(m_hReadCloseEvent);
+
+		//WaitForSingleObject(m_hReadThread, 1000);
+
+	//	DWORD exitCode;
+	//	BOOL ret = GetExitCodeThread(m_hReadThread, &exitCode);
+		//if(ret && exitCode != 0)
+		{
+			TRACE("强行关闭ReadThreadFunc线程\n");
+			TerminateThread(m_hReadThread,0);
+		}
+	//	CloseHandle(m_hReadThread);
+
+		m_hReadThread = NULL;
+	}
+
+/*
+	if( m_hComm != INVALID_HANDLE_VALUE )
+	{
+		SetEvent(m_hReadCloseEvent);
+		//设置所有事件无效
+		SetCommMask(m_hComm, 0);
+		//清空所有将要读的数据
+		PurgeComm( m_hComm,  PURGE_RXCLEAR );
+		//等待4秒,如果读线程没有退出,则强制退出
+		if (WaitForSingleObject(m_hReadThread,4000) == WAIT_TIMEOUT)
+		{
+			TerminateThread(m_hReadThread,0);
+		}
+		m_hReadThread = NULL;
+	}
+//*/
+}
+
+
+//函数介绍:打开串口
+//入口参数:pPortOwner	:使用此串口类的窗体句柄
+//		   portNo		:串口号
+//		   baud			:波特率
+//		   parity		:奇偶校验
+//		   databits		:数据位
+//		   stopbits		:停止位
+//出口参数:(无)
+//返回值:TRUE:成功打开串口;FALSE:打开串口失败
+BOOL CMyCESeries::OpenPort(void * pOwner,
+						 UINT portNo	,			//串口号
+						 UINT baud		,			//波特率
+						 UINT parity	,			//奇偶校验
+						 UINT databits	,			//数据位
+						 UINT stopbits  ,				//停止位
+						 bool isASync
+						 )
+{
+	m_portNo		= portNo;		//串口号使用串口1 CAN模块和GPS共用
+	m_baud			= baud;		//波特率
+	m_parity		= parity;		//奇偶校验,0-None,1-Odd,2-Even
+	m_databits		= databits;		//数据位
+	m_stopbits		= stopbits;		//停止位 0-停止位1,1-停止位1.5,2-停止位2
+
+	m_bSyncOrAsync	= isASync;
+
+	DCB commParam;
+	TCHAR szPort[15];	
+
+	ASSERT(pOwner!=NULL);
+	m_pOwner = pOwner;
+	
+	// 已经打开的话,直接返回
+	if (m_hComm != INVALID_HANDLE_VALUE)
+	{
+		return TRUE;
+	}
+	
+	//设置串口名
+	//wsprintf(szPort, _T("\.\COM%d:"), portNo);
+	wsprintf(szPort, _T("\\\\.\\COM%d"), portNo);
+	//sprintf(szPort, "\\\\.\\COM%d", portNo);
+	//打开串口
+	
+	if(m_bSyncOrAsync)//m_bSyncOrAsync值为0,则用同步方式创建,否则以异步方式创建、
+	{
+			m_hComm = CreateFile(			//以异步方式创建
+			szPort,
+			GENERIC_READ | GENERIC_WRITE,	//允许读和写
+			0,								//独占方式(共享模式)
+			NULL,
+			OPEN_EXISTING,					//打开而不是创建(创建方式)
+			 FILE_FLAG_OVERLAPPED,
+			0
+			);
+	}
+	else
+	{
+		m_hComm = CreateFile(			//以同步方式创建
+		szPort,
+		GENERIC_READ | GENERIC_WRITE,	//允许读和写
+		0,								//独占方式(共享模式)
+		NULL,
+		OPEN_EXISTING,					//打开而不是创建(创建方式)
+		0,  
+		NULL
+		);
+	}
+
+
+	if (m_hComm == INVALID_HANDLE_VALUE)
+	{
+		// 无效句柄,返回。		
+		TRACE(_T("CreateFile 返回无效句柄\n"));
+		DWORD  ErrNo = GetLastError();
+		return FALSE;
+		
+	}
+	
+	// 得到打开串口的当前属性参数,修改后再重新设置串口。
+	if (!GetCommState(m_hComm,&commParam))
+	{		
+		//关闭串口
+		CloseHandle (m_hComm);
+		m_hComm = INVALID_HANDLE_VALUE;
+		return FALSE;
+	}
+
+	if(m_bSyncOrAsync)//如果是异步方式,每创建一个串口对象,并且成功打开一个串口对象时后,才创建一个相应的发送事件
+	{
+		 //异步写串口     
+		m_olWrite.hEvent = CreateEvent(NULL,TRUE,FALSE,_T("WriteData"));
+//		DWORD dwError = GetLastError();
+//		if(dwError !=0)
+//		{
+//			TRACE("异步方式创建串口对象时,为该串口对象所创建的写串口事件对象失败");
+//			return FALSE;
+//		}
+	}
+	
+	//设置串口参数
+	commParam.BaudRate = baud;					// 设置波特率 
+	commParam.fBinary = TRUE;					// 设置二进制模式,此处必须设置TRUE
+	commParam.fParity = TRUE;					// 支持奇偶校验 
+	commParam.ByteSize = databits;				// 数据位,范围:4-8 
+	commParam.Parity = parity;					// 校验模式
+	commParam.StopBits = stopbits;				// 停止位 
+	
+	commParam.fOutxCtsFlow = FALSE;				// No CTS output flow control 
+	commParam.fOutxDsrFlow = FALSE;				// No DSR output flow control 
+	commParam.fDtrControl = DTR_CONTROL_ENABLE; 
+	// DTR flow control type 
+	commParam.fDsrSensitivity = FALSE;			// DSR sensitivity 
+	commParam.fTXContinueOnXoff = TRUE;			// XOFF continues Tx 
+	commParam.fOutX = FALSE;					// No XON/XOFF out flow control 
+	commParam.fInX = FALSE;						// No XON/XOFF in flow control 
+	commParam.fErrorChar = FALSE;				// Disable error replacement 
+	commParam.fNull = FALSE;					// Disable null stripping 
+	commParam.fRtsControl = RTS_CONTROL_ENABLE; 
+	// RTS flow control 
+	commParam.fAbortOnError = FALSE;			// 当串口发生错误,并不终止串口读写
+	
+	//设置串口参数
+	if (!SetCommState(m_hComm, &commParam))
+	{
+		TRACE(_T("SetCommState error\n"));	
+		DWORD dwError = GetLastError();
+
+		//关闭串口
+		CloseHandle (m_hComm);
+		m_hComm = INVALID_HANDLE_VALUE;		
+		return FALSE;
+	}
+	
+    //设置串口读写时间
+	COMMTIMEOUTS CommTimeOuts;
+	GetCommTimeouts (m_hComm, &CommTimeOuts);
+	CommTimeOuts.ReadIntervalTimeout = MAXDWORD;  
+	CommTimeOuts.ReadTotalTimeoutMultiplier = 0;  
+	CommTimeOuts.ReadTotalTimeoutConstant = 0;    
+	CommTimeOuts.WriteTotalTimeoutMultiplier = 10;  
+	CommTimeOuts.WriteTotalTimeoutConstant = 1000;  
+	if(!SetCommTimeouts( m_hComm, &CommTimeOuts ))
+	{
+		TRACE( _T("SetCommTimeouts 返回错误\n") );
+		//关闭串口
+		CloseHandle (m_hComm);
+
+		m_hComm = INVALID_HANDLE_VALUE;
+		return FALSE;
+	}
+	
+	//指定端口监测的事件集
+	SetCommMask (m_hComm, EV_RXCHAR);
+	//分配串口设备缓冲区
+	SetupComm(m_hComm,1024,1024);
+	//SetupComm(m_hComm,512,512);
+	//初始化缓冲区中的信息
+	PurgeComm(m_hComm,PURGE_TXCLEAR|PURGE_RXCLEAR);
+	
+	CString strEvent;
+	strEvent.Format(_T("Com_ReadCloseEvent%d"),portNo);
+	m_hReadCloseEvent = CreateEvent(NULL,TRUE,FALSE,strEvent);
+
+	//创建串口读数据监听线程
+	if( bCanComRead == true )
+	{
+		m_hReadThread = CreateThread(NULL,0,ReadThreadFunc,this,0,&m_dwReadThreadID);//通过this指针将串口对象传递给读线程函数ReadThreadFunc的形参
+	}
+		
+	
+	TRACE(_T("串口%d打开成功\n"), portNo);
+	m_bOpened = true;
+	return TRUE;
+}
+
+
+
+//函数介绍:关闭串口
+//入口参数:(无)
+//出口参数:(无)
+//返回值:  (无)
+void CMyCESeries::ClosePort()
+{	
+	//表示串口还没有打开
+	if (m_hComm == INVALID_HANDLE_VALUE)
+		return ;
+
+	//关闭事件
+	//TRACE("关闭串口读事件\n");	
+	Sleep(100);
+	//关闭读线程
+	CloseReadThread();
+
+	//关闭串口
+	TRACE("CMyCESeries关闭串口%d句柄\n", m_portNo);	
+	CloseHandle (m_hComm);
+	
+
+	//关闭事件
+	CloseHandle(m_olWrite.hEvent);
+
+	m_hComm = INVALID_HANDLE_VALUE;
+	m_bOpened = false;
+}
+
+
+//函数介绍:往串口写入数据
+//入口参数:buf :待写入数据缓冲区
+//	       bufLen : 待写入缓冲区长度
+//出口参数:(无)
+//返回值:TRUE:设置成功;FALSE:设置失败
+BOOL CMyCESeries::WriteSyncPort(const BYTE*buf , DWORD bufLen)
+{
+	if( false == m_bSyncOrAsync )//同步方式
+	{
+		DWORD dwNumBytesWritten;
+		DWORD dwHaveNumWritten =0 ; //已经写入多少
+		
+		int iInc = 0; //如果3次写入不成功,返回FALSE
+		ASSERT(m_hComm != INVALID_HANDLE_VALUE);
+		do
+		{
+			if (WriteFile (m_hComm,					//串口句柄 
+				buf+dwHaveNumWritten,				//被写数据缓冲区 
+				bufLen - dwHaveNumWritten,          //被写数据缓冲区大小
+				&dwNumBytesWritten,					//函数执行成功后,返回实际向串口写的个数	
+				NULL))								//此处必须设置NULL
+			{
+				dwHaveNumWritten = dwHaveNumWritten + dwNumBytesWritten;
+				//写入完成
+				if (dwHaveNumWritten == bufLen)
+				{
+					break;
+				}
+				iInc++;
+				if (iInc >= 3)
+				{
+					TRACE("CMyCESeries::WriteSyncPort 同步写串口失败3次\n");
+					return FALSE;
+				}
+				Sleep(10);
+			}
+			else
+			{
+				TRACE("CMyCESeries::WriteSyncPort 同步写串口失败\n");
+				return FALSE;
+			}
+		}while (TRUE);
+		
+		return TRUE;	
+	}
+	else//异步方式
+	{
+		DWORD dwNumBytesWritten;
+		DWORD dwHaveNumWritten =0 ; //已经写入多少
+
+//		OVERLAPPED olWrite;
+//		memset(&olWrite,0,sizeof(OVERLAPPED));
+//		m_olWrite.hEvent = CreateEvent(NULL,TRUE,FALSE,_T("WriteData"));
+		 
+		//异步写串口     
+		if (WriteFile (m_hComm,					//串口句柄 
+						buf+dwHaveNumWritten,				//被写数据缓冲区 
+						bufLen - dwHaveNumWritten,          //被写数据缓冲区大小
+						&dwNumBytesWritten,					//函数执行成功后,返回实际向串口写的个数	
+						&m_olWrite) == FALSE)//并不是表示写入失败,而是没有将所有数据写入到缓冲区中,而只是写入了部分而已
+		{
+			if(GetLastError() != ERROR_IO_PENDING)
+			{
+				TRACE("CMyCESeries::WriteSyncPort 异步写串口0x20\n");
+				return 0x20;
+			}
+			if(GetOverlappedResult(m_hComm,&m_olWrite,&dwNumBytesWritten,TRUE) == FALSE)//这里将一直阻塞,直到将所有数据写入到缓冲区为止
+			{
+				TRACE("CMyCESeries::WriteSyncPort 异步写串口0x25\n");
+				return 0x25;
+			 }	
+		}
+		//else//写入成功
+		{
+			dwHaveNumWritten = dwHaveNumWritten + dwNumBytesWritten;
+			//写入完成
+			if (dwHaveNumWritten == bufLen)
+				return TRUE;
+			else
+			{
+				TRACE("CMyCESeries::WriteSyncPort 异步写串口%d失败\n", m_portNo);
+				return FALSE;
+			}
+		}
+	}
+}
+
+
+//函数介绍:设置串口读取、写入超时
+//入口参数:CommTimeOuts : 指向COMMTIMEOUTS结构
+//出口参数:(无)
+//返回值:TRUE:设置成功;FALSE:设置失败
+BOOL CMyCESeries::SetSeriesTimeouts(COMMTIMEOUTS CommTimeOuts)
+{
+	ASSERT(m_hComm != INVALID_HANDLE_VALUE);
+	return SetCommTimeouts(m_hComm,&CommTimeOuts);
+}
+
+
+//得到串口是否打开
+BOOL CMyCESeries::GetComOpened()
+{
+	return m_bOpened;
+}

+ 80 - 0
ReadSensor/MySeries.h

@@ -0,0 +1,80 @@
+/*-----------------------------------------
+* Copyright (c) 2008 Eric Wong
+* 本版紧供读者参考,不得用于任何商业行为
+*
+* 文件名称: CESeries.h
+* 文件标识: 
+* 摘要:用于封装WINCE 串口通讯
+*
+* 当前版本: 1.0
+* 作者: 汪兵 Eric Wong
+* 完成日期: 2008年1月17日
+*
+* 取代版本:
+* 原作者: 
+* 完成日期: 
+----------------------------------------*/
+#pragma once
+
+//定义串口接收数据函数类型
+typedef void (CALLBACK* MY_ONSERIESREAD)(void * pOwner /*父对象指针*/
+									  ,BYTE* buf  /*接收到的缓冲区*/
+									  ,DWORD dwBufLen /*接收到的缓冲区长度*/);
+
+
+class CMyCESeries
+{
+public:
+	bool bCanComRead;
+	bool m_bSyncOrAsync;//使用同步方式或者异步方式(重叠方式),默认值为true:异步方式
+	CMyCESeries(UINT portNo = -1, UINT baud = 9600, UINT parity = NOPARITY, UINT databits = 8, UINT stopbits = 0);
+	~CMyCESeries(void);
+public:
+	UINT m_portNo;				//串口号
+	UINT m_baud;				//波特率
+	UINT m_parity;				//奇偶校验
+	UINT m_databits;			//数据位
+	UINT m_stopbits;			//停止位
+
+	//打开串口
+	BOOL OpenPort(void* pOwner,/*指向父指针*/
+				  UINT portNo	= 1,		/*串口号*/
+				  UINT baud		= 9600,	/*波特率*/
+				  UINT parity	= 0,	/*奇偶校验*/
+				  UINT databits	= 8,		/*数据位*/
+				  UINT stopbits	= 0,        /*停止位*/
+				  bool isASync	= true
+				  );
+
+	//关闭串口
+	void ClosePort();
+	//写入数据
+	BOOL WriteSyncPort(const BYTE*buf , DWORD bufLen);
+	//设置串口读取、写入超时
+	BOOL SetSeriesTimeouts(COMMTIMEOUTS CommTimeOuts);
+	//得到串口是否打开
+	BOOL GetComOpened();
+
+private:
+    //同步串口读线程函数
+	static  DWORD WINAPI ReadThreadFunc(LPVOID lparam);
+	//static  DWORD WINAPI ReadThreadFunc2(LPVOID lparam);
+private:
+	//关闭读线程
+	void CloseReadThread();
+private:
+    //已打开的串口句柄
+//	HANDLE	m_hComm;
+	//读线程句柄
+	HANDLE m_hReadThread;
+	//读线程ID标识
+	DWORD m_dwReadThreadID;
+	//读线程退出事件
+	HANDLE m_hReadCloseEvent;
+	bool m_bOpened; //串口是否打开
+	void * m_pOwner; //指定父对象指针
+public:
+	MY_ONSERIESREAD m_OnSeriesRead; //同步方式下,串口读取回调函数
+	HANDLE	m_hComm;
+	OVERLAPPED m_olWrite;//假如该串口使用异步方式时,将会用到该变量
+};

+ 99 - 0
ReadSensor/ReadMe.txt

@@ -0,0 +1,99 @@
+================================================================================
+    MICROSOFT FOUNDATION CLASS LIBRARY : ReadSensor Project Overview
+===============================================================================
+
+The application wizard has created this ReadSensor application for
+you.  This application not only demonstrates the basics of using the Microsoft
+Foundation Classes but is also a starting point for writing your application.
+
+This file contains a summary of what you will find in each of the files that
+make up your ReadSensor application.
+
+ReadSensor.vcxproj
+    This is the main project file for VC++ projects generated using an application wizard.
+    It contains information about the version of Visual C++ that generated the file, and
+    information about the platforms, configurations, and project features selected with the
+    application wizard.
+
+ReadSensor.vcxproj.filters
+    This is the filters file for VC++ projects generated using an Application Wizard. 
+    It contains information about the association between the files in your project 
+    and the filters. This association is used in the IDE to show grouping of files with
+    similar extensions under a specific node (for e.g. ".cpp" files are associated with the
+    "Source Files" filter).
+
+ReadSensor.h
+    This is the main header file for the application.  It includes other
+    project specific headers (including Resource.h) and declares the
+    CReadSensorApp application class.
+
+ReadSensor.cpp
+    This is the main application source file that contains the application
+    class CReadSensorApp.
+
+ReadSensor.rc
+    This is a listing of all of the Microsoft Windows resources that the
+    program uses.  It includes the icons, bitmaps, and cursors that are stored
+    in the RES subdirectory.  This file can be directly edited in Microsoft
+    Visual C++. Your project resources are in 1033.
+
+res\ReadSensor.ico
+    This is an icon file, which is used as the application's icon.  This
+    icon is included by the main resource file ReadSensor.rc.
+
+res\ReadSensor.rc2
+    This file contains resources that are not edited by Microsoft
+    Visual C++. You should place all resources not editable by
+    the resource editor in this file.
+
+
+/////////////////////////////////////////////////////////////////////////////
+
+The application wizard creates one dialog class:
+
+ReadSensorDlg.h, ReadSensorDlg.cpp - the dialog
+    These files contain your CReadSensorDlg class.  This class defines
+    the behavior of your application's main dialog.  The dialog's template is
+    in ReadSensor.rc, which can be edited in Microsoft Visual C++.
+
+/////////////////////////////////////////////////////////////////////////////
+
+Other Features:
+
+ActiveX Controls
+    The application includes support to use ActiveX controls.
+
+/////////////////////////////////////////////////////////////////////////////
+
+Other standard files:
+
+StdAfx.h, StdAfx.cpp
+    These files are used to build a precompiled header (PCH) file
+    named ReadSensor.pch and a precompiled types file named StdAfx.obj.
+
+Resource.h
+    This is the standard header file, which defines new resource IDs.
+    Microsoft Visual C++ reads and updates this file.
+
+ReadSensor.manifest
+	Application manifest files are used by Windows XP to describe an applications
+	dependency on specific versions of Side-by-Side assemblies. The loader uses this
+	information to load the appropriate assembly from the assembly cache or private
+	from the application. The Application manifest  maybe included for redistribution
+	as an external .manifest file that is installed in the same folder as the application
+	executable or it may be included in the executable in the form of a resource.
+/////////////////////////////////////////////////////////////////////////////
+
+Other notes:
+
+The application wizard uses "TODO:" to indicate parts of the source code you
+should add to or customize.
+
+If your application uses MFC in a shared DLL, you will need
+to redistribute the MFC DLLs. If your application is in a language
+other than the operating system's locale, you will also have to
+redistribute the corresponding localized resources mfc110XXX.DLL.
+For more information on both of these topics, please see the section on
+redistributing Visual C++ applications in MSDN documentation.
+
+/////////////////////////////////////////////////////////////////////////////

+ 110 - 0
ReadSensor/ReadSensor.cpp

@@ -0,0 +1,110 @@
+
+// ReadSensor.cpp : Defines the class behaviors for the application.
+//
+
+#include "stdafx.h"
+#include "ReadSensor.h"
+#include "ReadSensorDlg.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+
+// CReadSensorApp
+
+BEGIN_MESSAGE_MAP(CReadSensorApp, CWinApp)
+	ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
+END_MESSAGE_MAP()
+
+
+// CReadSensorApp construction
+
+CReadSensorApp::CReadSensorApp()
+{
+	// support Restart Manager
+	m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
+
+	// TODO: add construction code here,
+	// Place all significant initialization in InitInstance
+}
+
+
+// The one and only CReadSensorApp object
+
+CReadSensorApp theApp;
+
+
+// CReadSensorApp initialization
+
+BOOL CReadSensorApp::InitInstance()
+{
+//TODO: call AfxInitRichEdit2() to initialize richedit2 library.
+	// InitCommonControlsEx() is required on Windows XP if an application
+	// manifest specifies use of ComCtl32.dll version 6 or later to enable
+	// visual styles.  Otherwise, any window creation will fail.
+	INITCOMMONCONTROLSEX InitCtrls;
+	InitCtrls.dwSize = sizeof(InitCtrls);
+	// Set this to include all the common control classes you want to use
+	// in your application.
+	InitCtrls.dwICC = ICC_WIN95_CLASSES;
+	InitCommonControlsEx(&InitCtrls);
+
+
+
+	AfxInitRichEdit();
+
+	AfxInitRichEdit2();
+
+
+	CWinApp::InitInstance();
+
+
+	AfxEnableControlContainer();
+
+	// Create the shell manager, in case the dialog contains
+	// any shell tree view or shell list view controls.
+	CShellManager *pShellManager = new CShellManager;
+
+	// Activate "Windows Native" visual manager for enabling themes in MFC controls
+	CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
+
+	// Standard initialization
+	// If you are not using these features and wish to reduce the size
+	// of your final executable, you should remove from the following
+	// the specific initialization routines you do not need
+	// Change the registry key under which our settings are stored
+	// TODO: You should modify this string to be something appropriate
+	// such as the name of your company or organization
+	SetRegistryKey(_T("Local AppWizard-Generated Applications"));
+
+	CReadSensorDlg dlg;
+	m_pMainWnd = &dlg;
+	INT_PTR nResponse = dlg.DoModal();
+	if (nResponse == IDOK)
+	{
+		// TODO: Place code here to handle when the dialog is
+		//  dismissed with OK
+	}
+	else if (nResponse == IDCANCEL)
+	{
+		// TODO: Place code here to handle when the dialog is
+		//  dismissed with Cancel
+	}
+	else if (nResponse == -1)
+	{
+		TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n");
+		TRACE(traceAppMsg, 0, "Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n");
+	}
+
+	// Delete the shell manager created above.
+	if (pShellManager != NULL)
+	{
+		delete pShellManager;
+	}
+
+	// Since the dialog has been closed, return FALSE so that we exit the
+	//  application, rather than start the application's message pump.
+	return FALSE;
+}
+

+ 32 - 0
ReadSensor/ReadSensor.h

@@ -0,0 +1,32 @@
+
+// ReadSensor.h : main header file for the PROJECT_NAME application
+//
+
+#pragma once
+
+#ifndef __AFXWIN_H__
+	#error "include 'stdafx.h' before including this file for PCH"
+#endif
+
+#include "resource.h"		// main symbols
+
+
+// CReadSensorApp:
+// See ReadSensor.cpp for the implementation of this class
+//
+
+class CReadSensorApp : public CWinApp
+{
+public:
+	CReadSensorApp();
+
+// Overrides
+public:
+	virtual BOOL InitInstance();
+
+// Implementation
+
+	DECLARE_MESSAGE_MAP()
+};
+
+extern CReadSensorApp theApp;

BIN
ReadSensor/ReadSensor.rc


+ 143 - 0
ReadSensor/ReadSensor.vcxproj

@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{7404B4EA-7E6C-4286-9E49-D52B957E2F58}</ProjectGuid>
+    <RootNamespace>ReadSensor</RootNamespace>
+    <Keyword>MFCProj</Keyword>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v120_xp</PlatformToolset>
+    <CharacterSet>MultiByte</CharacterSet>
+    <UseOfMfc>Static</UseOfMfc>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v120_xp</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+    <UseOfMfc>Static</UseOfMfc>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+    <OutDir>$(SolutionDir)Bin\</OutDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+    <OutDir>$(SolutionDir)Bin\</OutDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <SDLCheck>true</SDLCheck>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+    <Midl>
+      <MkTypLibCompatible>false</MkTypLibCompatible>
+      <ValidateAllParameters>true</ValidateAllParameters>
+      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </Midl>
+    <ResourceCompile>
+      <Culture>0x0409</Culture>
+      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ResourceCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <SDLCheck>true</SDLCheck>
+    </ClCompile>
+    <Link>
+      <SubSystem>Windows</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+    <Midl>
+      <MkTypLibCompatible>false</MkTypLibCompatible>
+      <ValidateAllParameters>true</ValidateAllParameters>
+      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+    </Midl>
+    <ResourceCompile>
+      <Culture>0x0409</Culture>
+      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+    </ResourceCompile>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <Text Include="ReadMe.txt" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="ComHandle.h" />
+    <ClInclude Include="global.h" />
+    <ClInclude Include="MySeries.h" />
+    <ClInclude Include="ReadSensor.h" />
+    <ClInclude Include="ReadSensorDlg.h" />
+    <ClInclude Include="Resource.h" />
+    <ClInclude Include="stdafx.h" />
+    <ClInclude Include="targetver.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="ComHandle.cpp" />
+    <ClCompile Include="global.cpp" />
+    <ClCompile Include="MySeries.cpp" />
+    <ClCompile Include="ReadSensor.cpp" />
+    <ClCompile Include="ReadSensorDlg.cpp" />
+    <ClCompile Include="stdafx.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="ReadSensor.rc" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="res\ReadSensor.rc2" />
+  </ItemGroup>
+  <ItemGroup>
+    <Image Include="res\ReadSensor.ico" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+  <ProjectExtensions>
+    <VisualStudio>
+      <UserProperties RESOURCE_FILE="ReadSensor.rc" />
+    </VisualStudio>
+  </ProjectExtensions>
+</Project>

+ 81 - 0
ReadSensor/ReadSensor.vcxproj.filters

@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <Text Include="ReadMe.txt" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="ReadSensor.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="ReadSensorDlg.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="stdafx.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="targetver.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Resource.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="global.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="ComHandle.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="MySeries.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="ReadSensor.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="ReadSensorDlg.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="stdafx.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="global.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="ComHandle.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="MySeries.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="ReadSensor.rc">
+      <Filter>Resource Files</Filter>
+    </ResourceCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="res\ReadSensor.rc2">
+      <Filter>Resource Files</Filter>
+    </None>
+  </ItemGroup>
+  <ItemGroup>
+    <Image Include="res\ReadSensor.ico">
+      <Filter>Resource Files</Filter>
+    </Image>
+  </ItemGroup>
+</Project>

+ 414 - 0
ReadSensor/ReadSensorDlg.cpp

@@ -0,0 +1,414 @@
+
+// ReadSensorDlg.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "ReadSensor.h"
+#include "ReadSensorDlg.h"
+#include "afxdialogex.h"
+#include "global.h"
+#include "ComHandle.h"
+#include <string>
+using namespace std;
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+
+// CReadSensorDlg dialog
+
+ComHandle g_com;
+float g_pressure;
+float g_tem;
+int g_readtype;
+
+
+CReadSensorDlg::CReadSensorDlg(CWnd* pParent /*=NULL*/)
+	: CDialogEx(CReadSensorDlg::IDD, pParent)
+{
+	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
+}
+
+void CReadSensorDlg::DoDataExchange(CDataExchange* pDX)
+{
+	CDialogEx::DoDataExchange(pDX);
+	DDX_Control(pDX, IDC_RICHEDIT21, m_richedit);
+	DDX_Control(pDX, IDC_COMBO1, CB_Port);
+	DDX_Control(pDX, IDC_EDIT1, ED_PRESSURE);
+	DDX_Control(pDX, IDC_EDIT2, ED_TEM);
+	DDX_Control(pDX, IDC_CHECK1, BTN_Loop);
+	DDX_Control(pDX, IDC_EDIT3, ED_LoopTime);
+}
+
+BEGIN_MESSAGE_MAP(CReadSensorDlg, CDialogEx)
+	ON_WM_PAINT()
+	ON_WM_QUERYDRAGICON()
+	ON_BN_CLICKED(IDC_OPENCOMM, &CReadSensorDlg::OnBnClickedOpencomm)
+	ON_BN_CLICKED(IDC_READ_PRESSURE, &CReadSensorDlg::OnBnClickedReadPressure)
+	ON_BN_CLICKED(IDC_READ_TEM, &CReadSensorDlg::OnBnClickedReadTem)
+	ON_BN_CLICKED(IDC_READ_ALL, &CReadSensorDlg::OnBnClickedReadAll)
+	ON_BN_CLICKED(IDC_CHECK1, &CReadSensorDlg::OnBnClickedCheck1)
+	ON_MESSAGE(WM_DATARECEIVED, OnMyMessage)
+	ON_WM_TIMER()
+	ON_EN_CHANGE(IDC_EDIT3, &CReadSensorDlg::OnEnChangeEdit3)
+	ON_BN_CLICKED(IDC_CLEAR, &CReadSensorDlg::OnBnClickedClear)
+	ON_BN_CLICKED(IDC_Reflash, &CReadSensorDlg::OnBnClickedReflash)
+END_MESSAGE_MAP()
+
+
+// CReadSensorDlg message handlers
+
+BOOL CReadSensorDlg::OnInitDialog()
+{
+	CDialogEx::OnInitDialog();
+
+	// Set the icon for this dialog.  The framework does this automatically
+	//  when the application's main window is not a dialog
+	SetIcon(m_hIcon, TRUE);			// Set big icon
+	SetIcon(m_hIcon, FALSE);		// Set small icon
+
+	// TODO: Add extra initialization here
+
+
+	g_com.linkRichEdit(&m_richedit);
+
+
+
+	std::string strport = getConfig("port");
+
+
+
+
+	CString strCom[255];
+	CString strTemp;
+	CString strPort;
+
+	HANDLE hCom;
+	int index = 0;
+	for (int i = 0; i<255; i++)
+	{
+		strTemp.Format("\\\\.\\COM%d", i + 1);
+		strPort.Format("%d", i + 1);
+		hCom = CreateFile(strTemp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
+			OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
+		if (INVALID_HANDLE_VALUE == hCom)
+			continue;
+
+
+		strCom[i] = strTemp;
+		CB_Port.AddString(strPort);
+
+		//if (string(strPort.GetString()) == strport)
+		//{
+		//	CB_Port.SetCurSel(index);
+
+		//}
+
+		
+
+		index++;
+
+		CloseHandle(hCom);
+	}
+
+	for (int i = 0; i < CB_Port.GetCount(); i++)
+	{
+		CString str;
+		CB_Port.GetLBText(i, str);
+		if (string(str.GetString()) == strport)
+		{
+			CB_Port.SetCurSel(i);
+		}
+	}
+
+	BTN_Loop.SetCheck(getConfig_INT("Loop"));
+
+
+	ED_LoopTime.SetWindowText(getConfig("LoopTime").c_str());
+
+
+	if (BTN_Loop.GetCheck())
+	{
+		CString str;
+		ED_LoopTime.GetWindowText(str);
+		int time = atoi(str);
+
+		if (time > 0)
+		{
+			SetTimer(1, time, NULL);
+		}
+	}
+
+
+
+
+
+	g_readtype = getConfig_INT("ReadType");
+
+
+	OnBnClickedOpencomm();
+
+
+
+	return TRUE;  // return TRUE  unless you set the focus to a control
+}
+
+// If you add a minimize button to your dialog, you will need the code below
+//  to draw the icon.  For MFC applications using the document/view model,
+//  this is automatically done for you by the framework.
+
+void CReadSensorDlg::OnPaint()
+{
+	if (IsIconic())
+	{
+		CPaintDC dc(this); // device context for painting
+
+		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
+
+		// Center icon in client rectangle
+		int cxIcon = GetSystemMetrics(SM_CXICON);
+		int cyIcon = GetSystemMetrics(SM_CYICON);
+		CRect rect;
+		GetClientRect(&rect);
+		int x = (rect.Width() - cxIcon + 1) / 2;
+		int y = (rect.Height() - cyIcon + 1) / 2;
+
+		// Draw the icon
+		dc.DrawIcon(x, y, m_hIcon);
+	}
+	else
+	{
+		CDialogEx::OnPaint();
+	}
+}
+
+// The system calls this function to obtain the cursor to display while the user drags
+//  the minimized window.
+HCURSOR CReadSensorDlg::OnQueryDragIcon()
+{
+	return static_cast<HCURSOR>(m_hIcon);
+}
+
+
+
+void CReadSensorDlg::OnBnClickedOpencomm()
+{
+	int portno = 0;
+
+	CString strport;
+	CB_Port.GetWindowText(strport);
+
+	portno = atoi(strport.GetString());
+
+	g_com.opencom(portno);
+
+	if (!strport.IsEmpty())
+	{
+		saveConfig("port", strport.GetString());
+	}
+}
+
+
+void CReadSensorDlg::OnBnClickedReadPressure()
+{
+	ED_PRESSURE.SetWindowText("");
+	ED_TEM.SetWindowText("");
+
+
+	g_readtype = 0;
+	saveConfig("ReadType", g_readtype);
+
+	BYTE buf[] = { 0x02, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x38};
+	g_com.senddata(buf, _countof(buf));
+}
+
+
+void CReadSensorDlg::OnBnClickedReadTem()
+{
+	ED_PRESSURE.SetWindowText("");
+	ED_TEM.SetWindowText("");
+
+
+	g_readtype = 1;
+	saveConfig("ReadType", g_readtype);
+	BYTE buf[] = { 0x02, 0x03, 0x00, 0x04, 0x00, 0x02, 0x85, 0xF9 };
+	g_com.senddata(buf, _countof(buf));
+}
+
+
+void CReadSensorDlg::OnBnClickedReadAll()
+{
+	ED_PRESSURE.SetWindowText("");
+	ED_TEM.SetWindowText("");
+
+	g_readtype = 2;
+	saveConfig("ReadType", g_readtype);
+	BYTE buf[] = { 0x02, 0x03, 0x00, 0x00, 0x00, 0x04, 0x44, 0x3A };
+	g_com.senddata(buf, _countof(buf));
+
+}
+
+
+void CReadSensorDlg::OnBnClickedCheck1()
+{
+
+	saveConfig("Loop", BTN_Loop.GetCheck());
+
+	if (BTN_Loop.GetCheck())
+	{
+		ED_LoopTime.EnableWindow(FALSE);
+
+		CString str;
+		ED_LoopTime.GetWindowText(str);
+		int time = atoi(str);
+
+		if (time > 0)
+		{
+			SetTimer(1, time, NULL);
+		}
+	}
+	else
+	{
+		ED_LoopTime.EnableWindow(TRUE);
+		KillTimer(1);
+	}
+
+}
+
+LRESULT CReadSensorDlg::OnMyMessage(WPARAM wParam, LPARAM lParam)
+{
+	char pre[10] = { 0 };
+	char tem[10] = { 0 };
+	if (g_readtype == 0)
+	{
+		sprintf_s(pre, "%.4f", g_pressure);
+		ED_PRESSURE.SetWindowText(pre);
+	}
+	else if (g_readtype == 1)
+	{
+		ED_TEM.SetWindowText(to_string(g_tem).c_str());
+	}
+	else if (g_readtype == 2)
+	{
+		ED_PRESSURE.SetWindowText(to_string(g_pressure).c_str());
+		ED_TEM.SetWindowText(to_string(g_tem).c_str());
+	}
+
+
+	return 1;
+}
+
+void CReadSensorDlg::OnTimer(UINT_PTR nIDEvent)
+{
+	// TODO: Add your message handler code here and/or call default
+
+	if (g_readtype == 0)
+	{
+		OnBnClickedReadPressure();
+	}
+	else if (g_readtype == 1)
+	{
+		OnBnClickedReadTem();
+	}
+	else if (g_readtype == 2)
+	{
+		OnBnClickedReadAll();
+	}
+
+
+
+
+
+	CDialogEx::OnTimer(nIDEvent);
+}
+
+
+void CReadSensorDlg::OnEnChangeEdit3()
+{
+
+	CString str;
+	ED_LoopTime.GetWindowText(str);
+	int time = atoi(str);
+
+	if (time > 0)
+	{
+		saveConfig("LoopTime", time);
+	}
+
+	if (BTN_Loop.GetCheck())
+	{
+
+		if (time > 0)
+		{
+			SetTimer(1, time, NULL);
+		}
+	}
+}
+
+
+void CReadSensorDlg::OnBnClickedClear()
+{
+	ED_PRESSURE.SetWindowText("");
+	ED_TEM.SetWindowText("");
+
+
+	g_readtype = 10;
+	//saveConfig("ReadType", g_readtype);
+	BYTE buf[] = { 0x02, 0x06, 0x00, 0x00, 0x00, 0x00, 0x89, 0xF9 };
+	g_com.senddata(buf, _countof(buf));
+}
+
+
+void CReadSensorDlg::OnBnClickedReflash()
+{
+	CB_Port.ResetContent();
+	g_com.closecom();
+
+	std::string strport = getConfig("port");
+
+
+	CString strCom[255];
+	CString strTemp;
+	CString strPort;
+
+	HANDLE hCom;
+	int index = 0;
+	for (int i = 0; i<255; i++)
+	{
+		strTemp.Format("\\\\.\\COM%d", i + 1);
+		strPort.Format("%d", i + 1);
+		hCom = CreateFile(strTemp, GENERIC_READ | GENERIC_WRITE, 0, NULL,
+			OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
+		if (INVALID_HANDLE_VALUE == hCom)
+			continue;
+
+
+		strCom[i] = strTemp;
+		CB_Port.AddString(strPort);
+
+		//if (string(strPort.GetString()) == strport)
+		//{
+		//	CB_Port.SetCurSel(index);
+		//	
+		//}
+
+
+
+		index++;
+
+		CloseHandle(hCom);
+	}
+
+	for (int i = 0; i < CB_Port.GetCount(); i++)
+	{
+		CString str;
+		CB_Port.GetLBText(i, str);
+		if (string(str.GetString()) == strport)
+		{
+			CB_Port.SetCurSel(i);
+		}
+	}
+
+	OnBnClickedOpencomm();
+}

+ 50 - 0
ReadSensor/ReadSensorDlg.h

@@ -0,0 +1,50 @@
+
+// ReadSensorDlg.h : header file
+//
+
+#pragma once
+#include "afxcmn.h"
+#include "afxwin.h"
+
+
+// CReadSensorDlg dialog
+class CReadSensorDlg : public CDialogEx
+{
+// Construction
+public:
+	CReadSensorDlg(CWnd* pParent = NULL);	// standard constructor
+
+// Dialog Data
+	enum { IDD = IDD_READSENSOR_DIALOG };
+
+	protected:
+	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
+
+
+// Implementation
+protected:
+	HICON m_hIcon;
+
+	// Generated message map functions
+	virtual BOOL OnInitDialog();
+	afx_msg void OnPaint();
+	afx_msg HCURSOR OnQueryDragIcon();
+	DECLARE_MESSAGE_MAP()
+public:
+	CRichEditCtrl m_richedit;
+	CComboBox CB_Port;
+	CEdit ED_PRESSURE;
+	CEdit ED_TEM;
+	CButton BTN_Loop;
+	CEdit ED_LoopTime;
+	afx_msg void OnBnClickedOpencomm();
+	afx_msg void OnBnClickedReadPressure();
+	afx_msg void OnBnClickedReadTem();
+	afx_msg void OnBnClickedReadAll();
+	afx_msg void OnBnClickedCheck1();
+	afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);
+	afx_msg void OnTimer(UINT_PTR nIDEvent);
+	afx_msg void OnEnChangeEdit3();
+	afx_msg void OnBnClickedClear();
+	afx_msg void OnBnClickedReflash();
+};

+ 21 - 0
ReadSensor/Release/ReadSensor.Build.CppClean.log

@@ -0,0 +1,21 @@
+c:\bitbucket\readsensor\readsensor\release\readsensor.pch
+c:\bitbucket\readsensor\readsensor\release\vc120.pdb
+c:\bitbucket\readsensor\readsensor\release\stdafx.obj
+c:\bitbucket\readsensor\readsensor\release\readsensordlg.obj
+c:\bitbucket\readsensor\readsensor\release\readsensor.obj
+c:\bitbucket\readsensor\readsensor\release\myseries.obj
+c:\bitbucket\readsensor\readsensor\release\global.obj
+c:\bitbucket\readsensor\readsensor\release\comhandle.obj
+c:\bitbucket\readsensor\bin\readsensor.exe
+c:\bitbucket\readsensor\bin\readsensor.pdb
+c:\bitbucket\readsensor\readsensor\release\readsensor.res
+c:\bitbucket\readsensor\bin\readsensor.ilk
+c:\bitbucket\readsensor\readsensor\release\readsensor.tlog\cl.command.1.tlog
+c:\bitbucket\readsensor\readsensor\release\readsensor.tlog\cl.read.1.tlog
+c:\bitbucket\readsensor\readsensor\release\readsensor.tlog\cl.write.1.tlog
+c:\bitbucket\readsensor\readsensor\release\readsensor.tlog\link.command.1.tlog
+c:\bitbucket\readsensor\readsensor\release\readsensor.tlog\link.read.1.tlog
+c:\bitbucket\readsensor\readsensor\release\readsensor.tlog\link.write.1.tlog
+c:\bitbucket\readsensor\readsensor\release\readsensor.tlog\rc.command.1.tlog
+c:\bitbucket\readsensor\readsensor\release\readsensor.tlog\rc.read.1.tlog
+c:\bitbucket\readsensor\readsensor\release\readsensor.tlog\rc.write.1.tlog

+ 3 - 0
ReadSensor/Release/ReadSensor.log

@@ -0,0 +1,3 @@
+  Generating code
+  Finished generating code
+  ReadSensor.vcxproj -> C:\Bitbucket\ReadSensor\Bin\ReadSensor.exe

BIN
ReadSensor/Release/ReadSensor.tlog/CL.read.1.tlog


BIN
ReadSensor/Release/ReadSensor.tlog/CL.write.1.tlog


+ 2 - 0
ReadSensor/Release/ReadSensor.tlog/ReadSensor.lastbuildstate

@@ -0,0 +1,2 @@
+#TargetFrameworkVersion=v4.0:PlatformToolSet=v120_xp:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit
+Release|Win32|C:\Bitbucket\ReadSensor\|

BIN
ReadSensor/Release/ReadSensor.tlog/cl.command.1.tlog


BIN
ReadSensor/Release/ReadSensor.tlog/link.command.1.tlog


BIN
ReadSensor/Release/ReadSensor.tlog/link.read.1.tlog


BIN
ReadSensor/Release/ReadSensor.tlog/link.write.1.tlog


BIN
ReadSensor/Release/ReadSensor.tlog/rc.command.1.tlog


BIN
ReadSensor/Release/ReadSensor.tlog/rc.read.1.tlog


BIN
ReadSensor/Release/ReadSensor.tlog/rc.write.1.tlog


+ 5 - 0
ReadSensor/conn.ini

@@ -0,0 +1,5 @@
+[Config]
+port=51
+LoopTime=300
+Loop=0
+ReadType=1

+ 72 - 0
ReadSensor/global.cpp

@@ -0,0 +1,72 @@
+#include "stdafx.h"
+
+#include "global.h"
+
+
+
+#define CONAPPNAME "Config"
+#define CONPATH ".\\conn.ini"
+
+string getConfig(string key)
+{
+	char ch[100] = { 0 };
+	GetPrivateProfileString(CONAPPNAME, key.c_str(), "", ch, 100, CONPATH);
+	string val = ch;
+	return val;
+}
+int getConfig_INT(string key)
+{
+	char ch[100] = { 0 };
+	GetPrivateProfileString(CONAPPNAME, key.c_str(), "", ch, 100, CONPATH);
+	return atoi(ch);
+}
+
+void saveConfig(string key,string val)
+{
+	WritePrivateProfileString(CONAPPNAME, key.c_str(), val.c_str(), CONPATH);
+}
+void saveConfig(string key, int val)
+{
+	WritePrivateProfileString(CONAPPNAME, key.c_str(), std::to_string(val).c_str(), CONPATH);
+}
+
+WORD calccrc(BYTE crcbuf, WORD crc, WORD polynom)
+{
+	BYTE i;
+	crc = crc ^ crcbuf;
+	for (i = 0; i<8; i++) {
+		BYTE chk;
+		chk = crc & 1;
+		crc = crc >> 1;
+		crc = crc & 0x7fff;
+		if (chk == 1)
+			crc = crc^polynom;
+		crc = crc & 0xffff;
+	}
+	return crc;
+}
+
+//注意modbus算出来高低位要调转
+WORD chkcrc_modbus(BYTE *buf, WORD len, WORD polynom)
+{
+	WORD i;
+	WORD crc;
+	crc = 0xffff;
+	for (i = 0; i<len; i++) {
+		crc = calccrc(*buf, crc, polynom);
+		buf++;
+	}
+	return crc;
+}
+
+std::string getCurrentTime()
+{
+	CTime tm = CTime::GetCurrentTime();
+
+
+	char time[30] = { 0 };
+	sprintf_s(time, "%02d:%02d:%02d", tm.GetHour(),tm.GetMinute(), tm.GetSecond());
+
+	std::string str = time;
+	return str;
+}

+ 22 - 0
ReadSensor/global.h

@@ -0,0 +1,22 @@
+#pragma once
+
+#include <string>
+using std::string;
+
+
+
+#define WM_DATARECEIVED WM_USER+100
+
+
+string getConfig(string key);
+int getConfig_INT(string key);
+
+void saveConfig(string key, string val);
+void saveConfig(string key, int val);
+
+WORD calccrc(BYTE crcbuf, WORD crc, WORD polynom);
+
+WORD chkcrc_modbus(BYTE *buf, WORD len, WORD polynom);
+
+
+std::string getCurrentTime();

BIN
ReadSensor/res/ReadSensor.ico


BIN
ReadSensor/res/ReadSensor.rc2


BIN
ReadSensor/resource.h


+ 8 - 0
ReadSensor/stdafx.cpp

@@ -0,0 +1,8 @@
+
+// stdafx.cpp : source file that includes just the standard includes
+// ReadSensor.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+

+ 54 - 0
ReadSensor/stdafx.h

@@ -0,0 +1,54 @@
+
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently,
+// but are changed infrequently
+
+#pragma once
+
+#ifndef VC_EXTRALEAN
+#define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
+#endif
+
+#include "targetver.h"
+
+#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit
+
+// turns off MFC's hiding of some common and often safely ignored warning messages
+#define _AFX_ALL_WARNINGS
+
+#include <afxwin.h>         // MFC core and standard components
+#include <afxext.h>         // MFC extensions
+
+
+#include <afxdisp.h>        // MFC Automation classes
+
+
+
+#ifndef _AFX_NO_OLE_SUPPORT
+#include <afxdtctl.h>           // MFC support for Internet Explorer 4 Common Controls
+#endif
+#ifndef _AFX_NO_AFXCMN_SUPPORT
+#include <afxcmn.h>             // MFC support for Windows Common Controls
+#endif // _AFX_NO_AFXCMN_SUPPORT
+
+#include <afxcontrolbars.h>     // MFC support for ribbons and control bars
+
+
+
+
+
+
+
+
+
+#ifdef _UNICODE
+#if defined _M_IX86
+#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
+#elif defined _M_X64
+#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
+#else
+#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
+#endif
+#endif
+
+

+ 8 - 0
ReadSensor/targetver.h

@@ -0,0 +1,8 @@
+#pragma once
+
+// Including SDKDDKVer.h defines the highest available Windows platform.
+
+// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
+// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
+
+#include <SDKDDKVer.h>

+ 6 - 0
clear.bat

@@ -0,0 +1,6 @@
+@echo off
+rem 正在搜索...
+rem 删除文件
+for /f "delims=" %%i in ('dir /b /a-d /s "*.sdf" "*.ipch" "*.obj" "*.pdb" "*.pch" "*.ilk" "*.idb" "*.ncb" "*.res" "*.bsc" "*.sbr" "*.aps"') do del %%i
+rem 删除完毕
+pause

BIN
安装包/20210506/ReadSensor.exe


+ 11 - 0
安装包/copy.bat

@@ -0,0 +1,11 @@
+set dd=%date:~8,2%
+set mm=%date:~5,2%
+set yy=%date:~0,4%
+set folder="%yy%%mm%%dd%"
+echo.
+echo µ±Ç°Ê±¼äΪ%folder% 
+md .\%folder%
+
+
+copy ..\Bin\ReadSensor.exe .\%folder%  /y
+

BIN
安装包/传感器数据读取工具 V1.1.zip


BIN
安装包/传感器数据读取工具 V1.1/files/ReadSensor/ReadSensor.exe


+ 8 - 0
安装包/传感器数据读取工具 V1.1/files/bat/copy.bat

@@ -0,0 +1,8 @@
+
+
+XCOPY .\files\ReadSensor C:\ReadSensor\ /s /e /y
+
+
+
+
+ 

+ 31 - 0
安装包/传感器数据读取工具 V1.1/files/bat/shortcut.bat

@@ -0,0 +1,31 @@
+@echo off
+::设置程序或文件的完整路径(必选)
+set Program=C:\ReadSensor\ReadSensor.exe
+ 
+::设置快捷方式名称(必选)
+set LnkName=传感器数据读取工具
+ 
+::设置程序的工作路径,一般为程序主目录,此项若留空,脚本将自行分析路径
+set WorkDir=
+ 
+::设置快捷方式显示的说明(可选)
+set Desc=测试
+ 
+if not defined WorkDir call:GetWorkDir "%Program%"
+(echo Set WshShell=CreateObject("WScript.Shell"^)
+echo strDesKtop=WshShell.SpecialFolders("DesKtop"^)
+echo Set oShellLink=WshShell.CreateShortcut(strDesKtop^&"\%LnkName%.lnk"^)
+echo oShellLink.TargetPath="%Program%"
+echo oShellLink.WorkingDirectory="%WorkDir%"
+echo oShellLink.WindowStyle=1
+echo oShellLink.Description="%Desc%"
+echo oShellLink.Save)>makelnk.vbs
+echo 桌面快捷方式创建成功!
+makelnk.vbs
+del /f /q makelnk.vbs
+
+goto :eof
+:GetWorkDir
+set WorkDir=%~dp1
+set WorkDir=%WorkDir:~,-1%
+goto :eof

+ 18 - 0
安装包/传感器数据读取工具 V1.1/安装.bat

@@ -0,0 +1,18 @@
+@echo off
+setlocal enabledelayedexpansion
+set ms=mshta vbscript:CreateObject("Scripting.FileSystemObject").GetStandardStream(1).Write(msgbox("是否确定安装升级?",4096+64+4,"传感器数据读取工具安装升级"))(window.close)
+for /f %%i in ('!ms!') do (
+  if "%%i"=="6" echo 选择了“是”
+  if "%%i"=="7"  exit
+)
+
+taskkill /f /im ReadSensor.exe
+
+cd /d %~dp0
+call .\files\bat\copy.bat
+cd /d %~dp0
+call .\files\bat\shortcut.bat
+
+
+
+mshta vbscript:msgbox("安装升级完成!",4096+64+4,"提示")(window.close)

+ 1 - 0
安装包/传感器数据读取工具 V1.1/安装说明.txt

@@ -0,0 +1 @@
+双击安装包内的“安装.bat”,安装完成后,在桌面会生成“传感器数据读取工具”的快捷方式。安装目录为C盘的ReadSensor