Просмотр исходного кода

1、项目配置,输出到磁盘bin目录;
2、完成pyd接口及测试用例;

scbc.sat2 5 лет назад
Родитель
Сommit
8fd98ce7b3

+ 6 - 6
Chroma22293/Chroma22293.sln

@@ -7,18 +7,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chroma22293", "Chroma22293\
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
-		Debug|x64 = Debug|x64
+		Debug_Pyd|x86 = Debug_Pyd|x86
 		Debug|x86 = Debug|x86
-		Release|x64 = Release|x64
+		Release_Pyd|x86 = Release_Pyd|x86
 		Release|x86 = Release|x86
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
-		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Debug|x64.ActiveCfg = Debug|x64
-		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Debug|x64.Build.0 = Debug|x64
+		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Debug_Pyd|x86.ActiveCfg = Debug_Pyd|Win32
+		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Debug_Pyd|x86.Build.0 = Debug_Pyd|Win32
 		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Debug|x86.ActiveCfg = Debug|Win32
 		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Debug|x86.Build.0 = Debug|Win32
-		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Release|x64.ActiveCfg = Release|x64
-		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Release|x64.Build.0 = Release|x64
+		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Release_Pyd|x86.ActiveCfg = Release_Pyd|Win32
+		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Release_Pyd|x86.Build.0 = Release_Pyd|Win32
 		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Release|x86.ActiveCfg = Release|Win32
 		{AB7C4CB9-6CD2-461B-B9B1-931C77DEBD13}.Release|x86.Build.0 = Release|Win32
 	EndGlobalSection

+ 426 - 8
Chroma22293/Chroma22293/Chroma22293.cpp

@@ -3,7 +3,11 @@
 
 #include "stdafx.h"
 #include "framework.h"
+#ifndef _PYD_
 #include "Chroma22293.h"
+#else
+#include "Python.h"
+#endif
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -12,6 +16,13 @@
 #define READ_LEN 8912
 // 唯一的应用程序对象
 
+//////////////////////////////////////////////////////////////////////////
+// 全局变量;
+std::string g_strData;
+CSynSerial g_SynSerial;
+DoException g_funExp = NULL;
+
+#ifndef _PYD_
 CWinApp theApp;
 
 using namespace std;
@@ -54,7 +65,7 @@ int main()
 				if (SetBlueOFF())
 					printf("SetBlueOFF成功\n");
 
-				if (SetBuleON())
+				if (SetBlueON())
 					printf("SetBuleON成功\n");
 
 				if (SetGreenOFF())
@@ -92,10 +103,7 @@ int main()
 }
 
 //////////////////////////////////////////////////////////////////////////
-// 全局变量;
-std::string g_strData;
-CSynSerial g_SynSerial;
-
+// C接口;
 CHROMA22293_API BOOL OpenDevice(BYTE byCommPort, DWORD dwBaudRate, BYTE bySize, BYTE byParity, BYTE byStopBits)
 {
 	if (g_SynSerial.IsOpen())
@@ -298,7 +306,7 @@ CHROMA22293_API BOOL SetBlueOFF()
 	return !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData);
 }
 
-CHROMA22293_API BOOL SetBuleON()
+CHROMA22293_API BOOL SetBlueON()
 {
 	std::string data = "b on;\r";
 	if (!g_SynSerial.IsOpen())
@@ -480,7 +488,417 @@ CHROMA22293_API BOOL SetKeyBoardUnLock()
 	return !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData);
 }
 
-CHROMA22293_API void SetCallBack()
+CHROMA22293_API void SetExceptionCallBack(DoException funExp)
+{
+	g_funExp = funExp;
+}
+
+#else
+static PyObject* OpenDevice(PyObject* self, PyObject* args)
+{
+	// 应用程序路径;
+	unsigned int port, baudrate, datasize, parity, stopbite;
+	if (!PyArg_ParseTuple(args, "IIIII", &port, &baudrate, &datasize, &parity, &stopbite))
+		return NULL;
+
+	if (g_SynSerial.IsOpen())
+	{
+		g_SynSerial.CloseSerialPort();
+	}
+
+	// 返回进程Id;
+	return Py_BuildValue("b", g_SynSerial.OpenSerialPort(port, baudrate, datasize, parity, stopbite, 0, 0));
+}
+
+static PyObject* CloseDevice(PyObject* self, PyObject* args)
+{
+	g_SynSerial.CloseSerialPort();
+	return Py_BuildValue("");	// 返回None;
+}
+
+static PyObject* GetBufStatus(PyObject* self, PyObject* args)
+{
+	std::string data = "dummy;\r";
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data.data(), data.size());
+	if (dwData != data.size())
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData));
+}
+
+static PyObject* GetDeviceSoft(PyObject* self, PyObject* args)
+{
+	std::string data = "report ver;\r";
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("s", _T(""));
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data.data(), data.size());
+	if (dwData != data.size())
+	{
+		return Py_BuildValue("s", _T(""));
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("s", _T(""));
+	}
+
+	g_strData = (char*)byData;
+
+	return Py_BuildValue("s", g_strData.c_str());
+}
+
+static PyObject* GetDeviceName(PyObject* self, PyObject* args)
+{
+	std::string data = "report model;\r";
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("s", _T(""));
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data.data(), data.size());
+	if (dwData != data.size())
+	{
+		return Py_BuildValue("s", _T(""));
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("s", _T(""));
+	}
+
+	g_strData = (char*)byData;
+
+	return Py_BuildValue("s", g_strData.c_str());
+}
+
+static PyObject* SetPattern(PyObject* self, PyObject* args)
+{
+	unsigned int param;
+	if (!PyArg_ParseTuple(args, "I", &param))
+		return NULL;
+
+	char data[128] = { 0 };
+	_stprintf_s(data, _T("run ptn %ld;\r"), param);
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data, sizeof(data));
+	if (dwData != sizeof(data))
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData));
+}
+
+static PyObject* SetTiming(PyObject* self, PyObject* args)
+{
+	unsigned int param;
+	if (!PyArg_ParseTuple(args, "I", &param))
+		return NULL;
+
+	char data[128] = { 0 };
+	_stprintf_s(data, _T("run tim %ld;\r"), param);
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data, sizeof(data));
+	if (dwData != sizeof(data))
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData));
+}
+
+static PyObject* SetTimingPattern(PyObject* self, PyObject* args)
+{
+	unsigned int param1, param2;
+	if (!PyArg_ParseTuple(args, "II", &param1, &param2))
+		return NULL;
+
+	char data[128] = { 0 };
+	_stprintf_s(data, _T("run tim %ld;run tim %ld;\r"), param1, param2);
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data, strlen(data));
+	if (dwData != strlen(data))
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\nok;\r\n", (const byte*)byData));
+}
+
+static PyObject* SetBlueOFF(PyObject* self, PyObject* args)
+{
+	std::string data = "b off;\r";
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data.data(), data.size());
+	if (dwData != data.size())
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData));
+}
+
+static PyObject* SetBlueON(PyObject* self, PyObject* args)
+{
+	std::string data = "b on;\r";
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data.data(), data.size());
+	if (dwData != data.size())
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData));
+}
+
+static PyObject* SetGreenOFF(PyObject* self, PyObject* args)
+{
+	std::string data = "g off;\r";
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data.data(), data.size());
+	if (dwData != data.size())
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData));
+}
+
+static PyObject* SetGreenON(PyObject* self, PyObject* args)
+{
+	std::string data = "g on;\r";
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data.data(), data.size());
+	if (dwData != data.size())
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData));
+}
+
+static PyObject* SetRedOFF(PyObject* self, PyObject* args)
+{
+	std::string data = "r off;\r";
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data.data(), data.size());
+	if (dwData != data.size())
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData));
+}
+
+static PyObject* SetRedON(PyObject* self, PyObject* args)
+{
+	std::string data = "r on;\r";
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data.data(), data.size());
+	if (dwData != data.size())
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData));
+}
+
+static PyObject* SetKeyBoardLock(PyObject* self, PyObject* args)
+{
+	std::string data = "kb lock on;\r";
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data.data(), data.size());
+	if (dwData != data.size())
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData));
+}
+
+static PyObject* SetKeyBoardUnLock(PyObject* self, PyObject* args)
+{
+	std::string data = "kb lock off;\r";
+	if (!g_SynSerial.IsOpen())
+		return Py_BuildValue("b", 0);
+
+	// 写串口数据;
+	DWORD dwData = g_SynSerial.WriteComm((byte*)data.data(), data.size());
+	if (dwData != data.size())
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	// 读取串口数据;
+	byte byData[READ_LEN] = { 0 };
+	dwData = g_SynSerial.ReadComm(byData, READ_LEN);
+	if (dwData == 0)
+	{
+		return Py_BuildValue("b", 0);
+	}
+
+	return Py_BuildValue("b", !_mbsicmp((const byte*)"ok;\r\n", (const byte*)byData));
+}
+
+// 描述方法,暴露给python的函数;
+static PyMethodDef Chroma22293_Methods[] = {
+	{"OpenDevice",OpenDevice,METH_VARARGS,"打开设备"},
+	{"CloseDevice", CloseDevice, METH_VARARGS, "关闭设备"},
+	{"GetBufStatus", GetBufStatus, METH_VARARGS, "BUF测试"},
+	{"GetDeviceSoft", GetDeviceSoft, METH_VARARGS, "设备版本"},
+	{"GetDeviceName", GetDeviceName, METH_VARARGS, "设备信息"},
+	{"SetPattern", SetPattern, METH_VARARGS, "设置Ptn"},
+	{"SetTiming", SetTiming, METH_VARARGS, "设置Tim"},
+	{"SetTimingPattern", SetTimingPattern, METH_VARARGS, "设置Ptn和Tim"},
+	{"SetBlueOFF", SetBlueOFF, METH_VARARGS, "关蓝"},
+	{"SetBlueON", SetBlueON, METH_VARARGS, "开蓝"},
+	{"SetGreenOFF", SetGreenOFF, METH_VARARGS, "关绿"},
+	{"SetGreenON", SetGreenON, METH_VARARGS, "开绿"},
+	{"SetRedOFF", SetRedOFF, METH_VARARGS, "关红"},
+	{"SetRedON", SetRedON, METH_VARARGS, "开红"},
+	{"SetKeyBoardLock", SetKeyBoardLock, METH_VARARGS, "锁键盘"},
+	{"SetKeyBoardUnLock", SetKeyBoardUnLock, METH_VARARGS, "解锁键盘"},
+	//{"SetCallBack", SetCallBack, METH_VARARGS, "设置回调"},// Pyd暂时未了解如何实现回调;
+	{NULL,NULL}
+};
+
+// 初始模块;//格式:init<模块名称>
+PyMODINIT_FUNC initChroma22293()
 {
-	return CHROMA22293_API void();
+	// 初始化pyd函数列表;
+	PyObject* m, * d;
+	m = Py_InitModule("Chroma22293", Chroma22293_Methods);
+	d = PyModule_GetDict(m);
 }
+#endif

+ 10 - 29
Chroma22293/Chroma22293/Chroma22293.h

@@ -11,34 +11,13 @@
 #endif
 
 
-// 此类是从 dll 导出的
-class CHROMA22293_API CChroma22293 
-{
-public:
-	CChroma22293();
-	~CChroma22293();
-
-public:
-	// TODO: 在此处添加方法。
-	BOOL OpenDevice(
-		BYTE byCommPort,		// 串口号;
-		DWORD dwBaudRate,		// 波特率;
-		BYTE bySize,			// 数据位;
-		BYTE byParity,		// 校验位;
-		BYTE byStopBits		// 停止位;
-	);
-
-	void CloseDevice();
-};
-
-//
-//extern CHROMA22293_API int nChroma22293;
-//
-//extern "C" CHROMA22293_API int fnChroma22293(void);
-
-
 // 打开串口设备;
-extern "C" CHROMA22293_API BOOL OpenDevice(BYTE byCommPort, DWORD dwBaudRate, BYTE bySize, BYTE byParity, BYTE byStopBits);
+extern "C" CHROMA22293_API BOOL OpenDevice(
+	BYTE byCommPort, 
+	DWORD dwBaudRate, 
+	BYTE bySize, 
+	BYTE byParity, 
+	BYTE byStopBits);
 // 关闭串口设备;
 extern "C" CHROMA22293_API void CloseDevice();
 // 发送功能指令,并解析结果;
@@ -49,7 +28,7 @@ extern "C" CHROMA22293_API BOOL SetPattern(int param);
 extern "C" CHROMA22293_API BOOL SetTiming(int param);
 extern "C" CHROMA22293_API BOOL SetTimingPattern(int param1, int param2);
 extern "C" CHROMA22293_API BOOL SetBlueOFF();
-extern "C" CHROMA22293_API BOOL SetBuleON();
+extern "C" CHROMA22293_API BOOL SetBlueON();
 extern "C" CHROMA22293_API BOOL SetGreenOFF();
 extern "C" CHROMA22293_API BOOL SetGreenON();
 extern "C" CHROMA22293_API BOOL SetRedOFF();
@@ -57,4 +36,6 @@ extern "C" CHROMA22293_API BOOL SetRedON();
 extern "C" CHROMA22293_API BOOL SetKeyBoardLock();
 extern "C" CHROMA22293_API BOOL SetKeyBoardUnLock();
 // 设置异常回调函数
-extern "C" CHROMA22293_API void SetCallBack();
+// 参数:设备串口号、设备类型、异常发生时间、异常信息描述;
+typedef void (CALLBACK * DoException)(LPCTSTR lpDevicePort, DWORD dwDeviceType, LPCTSTR lpGenDateTime, LPCTSTR lpExceptionDes);
+extern "C" CHROMA22293_API void SetExceptionCallBack(DoException funExp);

+ 48 - 30
Chroma22293/Chroma22293/Chroma22293.vcxproj

@@ -1,21 +1,21 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug_Pyd|Win32">
+      <Configuration>Debug_Pyd</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
     <ProjectConfiguration Include="Debug|Win32">
       <Configuration>Debug</Configuration>
       <Platform>Win32</Platform>
     </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
+    <ProjectConfiguration Include="Release_Pyd|Win32">
+      <Configuration>Release_Pyd</Configuration>
       <Platform>Win32</Platform>
     </ProjectConfiguration>
-    <ProjectConfiguration Include="Debug|x64">
-      <Configuration>Debug</Configuration>
-      <Platform>x64</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|x64">
+    <ProjectConfiguration Include="Release|Win32">
       <Configuration>Release</Configuration>
-      <Platform>x64</Platform>
+      <Platform>Win32</Platform>
     </ProjectConfiguration>
   </ItemGroup>
   <PropertyGroup Label="Globals">
@@ -33,27 +33,27 @@
     <CharacterSet>MultiByte</CharacterSet>
     <UseOfMfc>Dynamic</UseOfMfc>
   </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Pyd|Win32'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
+    <UseDebugLibraries>true</UseDebugLibraries>
     <PlatformToolset>v142</PlatformToolset>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
     <CharacterSet>MultiByte</CharacterSet>
     <UseOfMfc>Dynamic</UseOfMfc>
   </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
+    <UseDebugLibraries>false</UseDebugLibraries>
     <PlatformToolset>v142</PlatformToolset>
-    <CharacterSet>Unicode</CharacterSet>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
     <UseOfMfc>Dynamic</UseOfMfc>
   </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Pyd|Win32'" Label="Configuration">
     <ConfigurationType>DynamicLibrary</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
     <PlatformToolset>v142</PlatformToolset>
     <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
+    <CharacterSet>MultiByte</CharacterSet>
     <UseOfMfc>Dynamic</UseOfMfc>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
@@ -64,27 +64,35 @@
   <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'">
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Pyd|Win32'" Label="PropertySheets">
     <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)'=='Debug|x64'">
+  <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>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release_Pyd|Win32'" Label="PropertySheets">
     <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>..\..\..\..\bin\$(SolutionName)\</OutDir>
+    <IntDir>$(OutDir)$(ProjectName)\$(Configuration)\</IntDir>
   </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Pyd|Win32'">
     <LinkIncremental>true</LinkIncremental>
+    <OutDir>..\..\..\..\bin\$(SolutionName)\</OutDir>
+    <IntDir>$(OutDir)$(ProjectName)\$(Configuration)\</IntDir>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <LinkIncremental>false</LinkIncremental>
+    <OutDir>..\..\..\..\bin\$(SolutionName)\</OutDir>
+    <IntDir>$(OutDir)$(ProjectName)\$(Configuration)\</IntDir>
   </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Pyd|Win32'">
     <LinkIncremental>false</LinkIncremental>
+    <OutDir>..\..\..\..\bin\$(SolutionName)\</OutDir>
+    <IntDir>$(OutDir)$(ProjectName)\$(Configuration)\</IntDir>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
@@ -101,20 +109,25 @@
       <EnableUAC>false</EnableUAC>
     </Link>
   </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_Pyd|Win32'">
     <ClCompile>
       <PrecompiledHeader>Use</PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <SDLCheck>true</SDLCheck>
-      <PreprocessorDefinitions>_DEBUG;CHROMA22293_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+      <PreprocessorDefinitions>WIN32;_DEBUG;CHROMA22293_EXPORTS;_WINDOWS;_USRDLL;_PYD_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
+      <AdditionalIncludeDirectories>C:\Python27\include</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
-      <SubSystem>Windows</SubSystem>
+      <SubSystem>Console</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableUAC>false</EnableUAC>
+      <AdditionalLibraryDirectories>C:\Python27\libs</AdditionalLibraryDirectories>
     </Link>
+    <PostBuildEvent>
+      <Command>copy $(TargetPath)  $(TargetDir)$(TargetName).pyd /y/a</Command>
+    </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
@@ -135,7 +148,7 @@
       <EnableUAC>false</EnableUAC>
     </Link>
   </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_Pyd|Win32'">
     <ClCompile>
       <PrecompiledHeader>Use</PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
@@ -143,8 +156,9 @@
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <SDLCheck>true</SDLCheck>
-      <PreprocessorDefinitions>NDEBUG;CHROMA22293_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+      <PreprocessorDefinitions>WIN32;NDEBUG;CHROMA22293_EXPORTS;_WINDOWS;_USRDLL;_PYD_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
+      <AdditionalIncludeDirectories>C:\Python27\include</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -152,7 +166,11 @@
       <OptimizeReferences>true</OptimizeReferences>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <EnableUAC>false</EnableUAC>
+      <AdditionalLibraryDirectories>C:\Python27\libs</AdditionalLibraryDirectories>
     </Link>
+    <PostBuildEvent>
+      <Command>copy $(TargetPath)  $(TargetDir)$(TargetName).pyd /y/a</Command>
+    </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClInclude Include="Chroma22293.h" />
@@ -166,9 +184,9 @@
     <ClCompile Include="Chroma22293.cpp" />
     <ClCompile Include="stdafx.cpp">
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
-      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug_Pyd|Win32'">Create</PrecompiledHeader>
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
-      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release_Pyd|Win32'">Create</PrecompiledHeader>
     </ClCompile>
     <ClCompile Include="SynSerial.cpp" />
   </ItemGroup>

+ 79 - 0
Chroma22293/test.py

@@ -0,0 +1,79 @@
+# -*- coding: UTF-8 -*-
+import Chroma22293
+
+if __name__ == "__main__":
+    print '测试C++ Pyd库'
+    # 打开设备
+    if not Chroma22293.OpenDevice(3, 115200, 8, 0, 1):
+        print "打开设备失败"
+
+    print "成功打开设备……"
+    # print "获取设备版本:", Chroma22293.GetDeviceSoft()
+    # print "获取设备信息:\n", Chroma22293.GetDeviceName()
+
+    if Chroma22293.GetBufStatus():
+        print "\nGetBufStatus 成功"
+    else:
+        print "\nGetBufStatus 失败"
+
+    if Chroma22293.SetPattern(11):
+        print "\nSetPattern 成功"
+    else:
+        print "\nSetPattern 失败"
+
+    if Chroma22293.SetTiming(11):
+        print "\nSetTiming 成功"
+    else:
+        print "\nSetTiming 失败"
+
+    if Chroma22293.SetTimingPattern(11, 11):
+        print "\nSetTimingPattern 成功"
+    else:
+        print "\nSetTimingPattern 失败"
+
+    # 设置Blue;
+    if Chroma22293.SetBlueOFF():
+        print "\nSetBlueOFF 成功"
+    else:
+        print "\nSetBlueOFF 失败"
+
+    if Chroma22293.SetBlueON():
+        print "\nSetBlueON 成功"
+    else:
+        print "\nSetBlueON 失败"
+
+    # 设置Green;
+    if Chroma22293.SetGreenOFF():
+        print "\nSetGreenOFF 成功"
+    else:
+        print "\nSetGreenOFF 失败"
+
+    if Chroma22293.SetGreenON():
+        print "\nSetGreenON 成功"
+    else:
+        print "\nSetGreenON 失败"
+
+    # 设置Red;
+    if Chroma22293.SetRedOFF():
+        print "\nSetRedOFF 成功"
+    else:
+        print "\nSetRedOFF 失败"
+
+    if Chroma22293.SetRedON():
+        print "\nSetRedON 成功"
+    else:
+        print "\nSetRedON 失败"
+
+    # 设置kb lock;
+    if Chroma22293.SetKeyBoardLock():
+        print "\nSetKeyBoardLock 成功"
+    else:
+        print "\nSetKeyBoardLock 失败"
+
+    if Chroma22293.SetKeyBoardUnLock():
+        print "\nSetKeyBoardUnLock 成功"
+    else:
+        print "\nSetKeyBoardUnLock 失败"
+    
+    # 关掉设备;
+    Chroma22293.CloseDevice()