Iron Python错误:预期< type'bytes'>或字节数组,得到< type'str'>用于串行通讯 [英] Iron Python Error: expected <type 'bytes'> or bytearray, got <type 'str'> for Serial comm

查看:75
本文介绍了Iron Python错误:预期< type'bytes'>或字节数组,得到< type'str'>用于串行通讯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法理解这一点:当我使用python shell运行时,它可以运行,但不能:当使用Iron python进行调用时.抛出以上错误

Unable to understand this: When I run using python shell it works but doesn't: when invoked using Iron python. It throws above error

C#:

scriptEngine.ExecuteFile(path);
var testFn = scriptScope.GetVariable("InputSelection");
var stream = new MemoryStream();
scriptEngine.Runtime.IO.SetOutput(stream, Encoding.Default);
scriptEngine.Operations.Invoke(testFn);

Python:

def send_data(message,check):
    if message:
        ser.write(message.encode('utf-8'))

    time.sleep(2)
    response = ser.read(1024)

def InputSelection():
    send_data("Hello","Hello")

推荐答案

看起来就像您遇到了一个错误在IronPython中.同时,您可以使用以下方法解决此问题:

Looks like you're hitting a bug in IronPython. In the meantime you can workaround it by using:

ser.write(bytes(message.encode('utf-8')))

这篇关于Iron Python错误:预期< type'bytes'>或字节数组,得到< type'str'>用于串行通讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆