Iron Python Error: expected <type 'bytes'> or bytearray, got <type 'str'> for Serial comm

梦想的初衷 提交于 2019-12-25 01:13:50

问题


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")

回答1:


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')))


来源:https://stackoverflow.com/questions/24620217/iron-python-error-expected-type-bytes-or-bytearray-got-type-str-for-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!