ʵս¹¹½¨PythonºÍC++»ìºÏϵͳ
¹ØÓÚC++ºÍPythonÖ®¼ä»¥Ïàµ÷ÓõÄÎÊÌ⣬¿ÉÒÔ²éÕÒµ½ºÜ¶à×ÊÁÏ¡£±¾ÎĽ«Ö÷Òª´Ó½â¾öʵ¼ÊÎÊÌâµÄ½Ç¶È¿´ÈçºÎ¹¹½¨Ò»¸öPythonºÍC++»ìºÏϵͳ¡£
Á¦Îª 2009
Ò»¡¢¸ÅÄî
»ìºÏϵͳ£º²ÉÓöàÖÖÓïÑÔ¹¹½¨µÄϵͳ¡£±ÈÈçNative C++ºÍdotNetµÄ»ìºÏϵͳ£¬Python/LuaºÍC++µÄ»ìºÏϵͳ¡£
PythonºÍC++¸÷Óи÷µÄÓÅȱµã£¬¹¹½¨Á½Õß»ìºÏϵͳµÄÖ÷ҪĿµÄ¾ÍÊÇÀûÓÃPythonµÄÁé»îÐÔºÍC++¸ßЧÐÔ£¬Ôö¼Ó³ÌÐòµÄÀ©Õ¹ÐÔ¡£µ±È»»¹ÓÐÆäËûºÃ´¦£¬´Ë´¦¾Í²»Õ¹¿ªÌ¸ÁË¡£½Å±¾ÓïÑÔÓкܶ࣬ÖÁÓÚΪʲô²»²ÉÓÃÆäËûµÄ£¨ÈçLua¡¢RubyµÈ£©£¬ÕâÀïÒ²²»¿¼ÂÇ¡£½Å±¾ÓïÑԵIJÉÓÃÖ÷ÒªÊǸöÈËϲºÃµÄÎÊÌâ¡£²ÉÓÃLua¿ÉÒԲ鵽ºÜ¶à×ÊÁÏ£¬ÒÔÇ°Ò²ÔøÓÃLuaBindʵÏÖ¹ý¡£
¶þ¡¢ÏµÍ³¼Ü¹¹
»ìºÏϵͳ¿ÉÒÔ¼ò»¯³ÉÈçÏÂÄ£ÐÍ£º
ϵͳµÄÔËÐйý³ÌΪ£º
Ê×ÏÈÔÚÓ¦ÓóÌÐòÖÐǶÈë½Å±¾ÓïÑÔ½âÎöÆ÷£¬È»ºóÓýű¾ÓïÑÔÌṩµÄC/C++ API·â×°ÒÑÓеÄC++¹¦Äܿ⣬ÔÙÓýű¾µ÷Ó÷â×°µÄ·þÎñ¡£´Ëºó£¬Ó¦Óòã±ã¿ÉÒÔÖ´Ðнű¾ÀïµÄÄÚÈÝ£¬ÆäЧ¹ûÓëÓ¦ÓòãÖ±½Óµ÷Ó÷þÎñ²ãÀàËÆ¡£
Èý¡¢ÊµÏÖ
±¾ÀýÖвÉÓýű¾ÓïÑÔPython£¬Òò´ËÖ÷Òª¹¤×÷ΪÔÚÓ¦ÓòãǶÈëPython½âÎöÆ÷£¬ÓÃPython·â×°·þÎñ²ã¡£ÎªÁË˵Ã÷ÎÊÌ⣬ӦÓòãµÄʵÏÖΪPythonConsole.ex£¬·þÎñ²ãµÄʵÏÖΪMythma.dll£¬·â×°²ãΪMythmaPy.dll¡£
1¡¢¼Ù¶¨Mythma.dllÖеÄÒ»¸öÀàΪCHelloWorld£º
class MythmaAPI CHelloWorld
{
public:
CHelloWorld(void);
~CHelloWorld(void);
void SetId(int nId) { m_Id = nId;}
int GetId() const { return m_Id; }
private:
int m_Id;
};
2¡¢ÏÖÔÚÓÃBoost.Python·â×°¸ÃÀࣺ
#include "HelloWorld.h"
#include <boost/python.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(My
Ïà¹ØÎĵµ£º
ÎÒÃÇÔÚ×öÈí¼þ¿ª·¢µÄʱºòºÜ¶àÒªÓõ½¶àÏ̼߳¼Êõ¡£ÀýÈçÈç¹û×öÒ»¸öÏÂÔØÈí¼þÏóflashget¾ÍÒªÓõ½¡¢ÏóÔÚÏßÊÓƵ¹¤¾ßrealplayerÒ²ÒªÓõ½ÒòΪҪͬʱÏÂÔØmedia stream»¹Òª²¥·Å¡£ÆäʵÀý×ÓÊǺܶàµÄ¡£
Ïß³ÌÏà¶Ô½ø³ÌÀ´ËµÊÇ“ÇáÁ¿¼¶”µÄ£¬²Ù×÷ϵͳÓýÏÉÙµÄ×ÊÔ´´´½¨ºÍ¹ÜÀíÏ̡߳£³ÌÐòÖеÄÏß³ÌÔÚÏàͬµÄÄÚ´æ¿Õ¼äÖÐÖ´ÐУ¬²¢¹²ÏíÐí¶àÏà ......
http://hi.baidu.com/guzhilei1986/blog/item/8969b4debe99e150ccbf1ae7.html
º¯Êý ÃèÊö
int(x [,base ]) ......
ÓÃpythonдÁ˸ö×î¼òµ¥µÄ¶Á´®¿ÚµÄ³ÌÐò£¬ÒòΪ¹¤×÷Öо³£ÐèÒª¶Á´®¿Ú
·ÅÔʼ´úÂë
import serial
ser = serial.Serial('com3',baudrate=115200, bytesize=8,parity='N', stopbits=1,xonxoff=0, timeout=1)
while( True ):
a = ser.read(100)
print a
ÓÃÍêÐèÒªser.close()£¬·ñÔòÆäË ......
pythonʹÓÃSocketServers
SocketServersÄ£¿éΪһ×ésocket·þÎñÀඨÒåÁËÒ»¸ö»ùÀ࣬Õâ×éÀàѹËõºÍÒþ²ØÁ˼àÌý¡¢½ÓÊܺʹ¦Àí½øÈëµÄsocketÁ¬½ÓµÄϸ½Ú¡£
1¡¢SocketServers¼Ò×å
TCPServerºÍUDPServer¶¼ÊÇSocketServerµÄ×ÓÀ࣬ËüÃÇ·Ö±ð´¦ÀíTCPºÍUDPÐÅÏ¢¡£
×¢Ò⣺SocketServerÒ²ÌṩUnixStreamServer(TCPServerµÄ×ÓÀà)ºÍUNIXdatag ......
¡¡¡¡ÉÏ´Îѧϰ¹ýmarshalÄ£¿éÓÃÓÚÐòÁл¯ºÍ·´ÐòÁл¯£¬µ«marshalµÄ¹¦ÄܱȽϱ¡Èõ£¬Ö»Ö§³Ö²¿·ÖÄÚÖÃÊý¾ÝÀàÐ͵ÄÐòÁл¯/·´ÐòÁл¯£¬¶ÔÓÚÓû§×Ô¶¨ÒåµÄÀàÐ;ÍÎÞÄÜΪÁ¦£¬Í¬Ê±marshal²»Ö§³Ö×ÔÒýÓÃ(µÝ¹éÒýÓÃ)µÄ¶ÔÏóµÄÐòÁл¯¡£ËùÒÔÖ±½ÓʹÓÃmarshalÀ´ÐòÁл¯/·´ÐòÁл¯¿ÉÄܲ»ÊǺܷ½±ã¡£»¹ºÃ£¬python±ê×¼¿âÌṩÁ˹¦Äܸü¼ÓÇ¿´óÇÒ¸ü¼Ó°²È«µÄpickle ......