python dll调用 结果差异_同一个 DLL 用 C 调用其中一个函数和用 PYTHON 调用同一个函数,返回的结果不同...

python 代码如下

import ctypes

import time

dll = ctypes.cdll.LoadLibrary('thinkgear')#cdll different windll

dllVersion = dll.TG_GetDriverVersion();

print(dllVersion)

connectionId = dll.TG_GetNewConnectionId();

print(connectionId)

errCode = dll.TG_SetStreamLog(connectionId, "streamLog2.txt" );

#print(errCode)

errCode = dll.TG_SetDataLog(connectionId,"dataLog2.txt" );

comPortName = ctypes.c_char_p()

comPortName = "\\\\.\\COM5";

errCode = dll.TG_Connect(connectionId,comPortName,9600,0);

print errCode,'connection susser'

packersRead = 0

while 1:

errCode = dll.TG_ReadPackets(connectionId,1)

if errCode ==1 and dll.TG_GetValueStatus(connectionId,2)!=0:

print dll.TG_GetValue(connectionId, 5),dll.TG_GetValue(connectionId, 6),dll.TG_GetValue(connectionId, 9)

packersRead = packersRead + 1

if packersRead>50:

break

dll.TG_Disconnect(connectionId)

dll.TG_FreeConnection(connectionId)

C 代码如下

#include

#include

#include "thinkgear.h"

void wait()

{

system("pause");

}

int main()

{

char *comPortName = NULL;

int dllVersion = 0; // 动态库版本

int connectionId = 0; // 连接 ID

int packetsRead = 0; // 包数量

int errCode = 0; // 错误码

/* 获取动态库版本 */

dllVersion = TG_GetDriverVersion();

printf( "ThinkGear DLL version: %d\n", dllVersion );

/* 获取连接 ID */

connectionId = TG_GetNewConnectionId();

if( connectionId < 0 )

{

printf("ERROR: TG_GetNewConnectionId() returned %d.\n",

connectionId );

wait();

exit( EXIT_FAILURE );

}

/* 原始数据日志 */

errCode = TG_SetStreamLog( connectionId, "streamLog.txt" );

if( errCode < 0 ) {

printf("ERROR: TG_SetStreamLog() returned %d.\n", errCode );

wait();

exit( EXIT_FAILURE );

}

/* ThinkGear 数据日志 */

errCode = TG_SetDataLog( connectionId, "dataLog.txt" );

if( errCode < 0 ) {

printf("ERROR: TG_SetDataLog() returned %d.\n", errCode );

wait();

exit( EXIT_FAILURE );

}

/* 准备连接的 COM 口 */

comPortName = "\\\\.\\COM5"; // \\.\COM3

errCode = TG_Connect( connectionId,

comPortName,

TG_BAUD_9600,

TG_STREAM_PACKETS );

if( errCode < 0 ) {

printf("ERROR: TG_Connect() returned %d.\n", errCode );

wait();

exit( EXIT_FAILURE );

}

/* 不停的读取数据 */

packetsRead = 0;

while(1/* packetsRead < 10*/ )

{

//Sleep(50);

/* 读一个报文 */

errCode = TG_ReadPackets( connectionId, 1 );

/* 如果这个报文读取成功 */

if( errCode == 1 )

{

int detla,theta,beta1;

if(( errCode = TG_GetValueStatus(connectionId, TG_DATA_ATTENTION)) != 0 )

{

detla = TG_GetValue(connectionId, TG_DATA_DELTA);

theta = TG_GetValue(connectionId, TG_DATA_THETA);

beta1 = TG_GetValue(connectionId, TG_DATA_BETA1);

printf("delta = %d, theta=%d, beta1=%d\n", detla, theta, beta1);

}

}

else

{

printf("ReadPackets:errcode=%d\n", errCode);

Sleep(1000);

}

}

/* 释放连接 */

TG_FreeConnection( connectionId );

/* End program */

system("pause");

return( EXIT_SUCCESS );

}

我觉得可能是 python 的问题,但是就是不知道问题在哪。。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值