0

我正在尝试使用 ctypes 在 python2.5 中创建蓝牙套接字(实际上是 PythonCE,没有更高的版本可用)。我不确定如何socket (AF_BT, SOCK_STREAM, BTHPROTO_RFCOMM)在 ctypes 中定义返回的 SOCKET 结构。

winsock2.h
#define WSAAPI                  FAR PASCAL
...
#if INCL_WINSOCK_API_TYPEDEFS
typedef
SOCKET
(WSAAPI * LPFN_SOCKET)(
    IN int af,
    IN int type,
    IN int protocol
    );
#endif /* INCL_WINSOCK_API_TYPEDEFS */

我也定义了 WSDATA 如下。作为 C++ 和 ctypes 的新手,我不确定它是否正确。

#typedef struct WSAData {
class WSADATA( Structure ):
    __fields__ = [
        ( 'wVersion', w.WORD),      #  WORD wVersion;
        ('wHighVersion', w.WORD),   #  WORD wHighVersion;
        ('szDescription', w.CHAR * 10 ),   # char szDescription[WSADESCRIPTION_LEN+1]; Null-terminated ASCII string into which the Ws2_32.dll copies a description of the Windows Sockets implementation. The text (up to 256 characters in length) 
        ('szSystemStatus', w.CHAR * 10 ),  # char  szSystemStatus[WSASYS_STATUS_LEN+1]; Null-terminated ASCII string into which the WSs2_32.dll copies relevant status or configuration information.
        ('iMaxSockets', w.USHORT),   #  unsigned short iMaxSockets;  Ignored for Winsock 2.0 
        ('iMaxUdpDg', w.USHORT),     #  unsigned short iMaxUdpDg; Ignored for Winsock 2.0 and later
        ('lpVendorInfo', w.CHAR)     #  char FAR* lpVendorInfo;  ignored for winsock v2 
    ]
#} WSADATA, *LPWSADATA; 

我想使用socket接口,它似乎比vcom方式更容易控制(我怀疑虚拟com端口是否可以在我的掌上电脑上工作。)但是winsock结构如此复杂......有什么办法可以包装将它们向上传递并像黑匣子一样传递它们。无论如何,这些描述符不应该在 python 中操作。

4

0 回答 0