python 调用c函数unsigned char数组_char数组到unsigned char python

我试图将这段c代码转换成python,但是我在char*到{}的转换中遇到问题:void sendAsciiCommand(string command) {

unsigned int nchars = command.length() + 1; // Char count of command string

unsigned int nshorts = ceil(nchars / 2); // Number of shorts to store the string

std::vector regs(nshorts); // Vector of short registers

// Transform char array to short array with endianness conversion

unsigned short *ascii_short_ptr = (unsigned short *)(command.c_str());

for (unsigned int i = 0; i < nshorts; i++)

regs[i] = htons(ascii_short_ptr[i]);

return std::string((char *)regs.data());

}

我在Python2.7中尝试过以下代码:

^{pr2}$

但它给了我一个错误:ValueError: string length not a multiple of item size

有什么帮助吗?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值