铁Python错误:预期<type'bytes'=“”>或bytearray,得到<type'str'=“”>用于串行通信</type> </type>

时间:2014-07-07 21:30:33

标签: python-2.7 ironpython

无法理解这一点:当我使用python shell运行时,它可以工作,但不会:使用Iron python调用时。它抛出错误

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 个答案:

答案 0 :(得分:0)

您似乎在IronPython中点击了a bug。在此期间,您可以使用以下方法解决此问题:

ser.write(bytes(message.encode('utf-8')))
相关问题