Arduino Maya Pythoncode

时间:2018-02-20 13:36:16

标签: python arduino maya

我和我的朋友正试图在Maya中实施一个Arduinoboard控制器。我们自己没有编写代码,也无法掌握编写代码的人。我们不是程序员,但我们知道如何阅读和编辑Python代码。我们的问题可能很简单,但我们无法弄清楚如何解决它。我们用Google搜索并在多个论坛上阅读,没有任何运气。基本上我们没有足够的知识来了解其他人的问题/解决方案如何适用于我们的特定代码。

错误讯息:

Error message can be seen here

这是代码:

import socket
import serial
import time

MAYA_ADDR = ('127.0.0.1', 1923)
ARDUINO_PORT = 'COM3'

if __name__ == '__main__':
    print('Welcome to the arduino-maya serial driver.')
    print('Press CTRL-C to exit.')
    print('')
    print('[INFO] Maya address: {0}:{1}'.format(*MAYA_ADDR))
    print('[INFO] Arduino port: {0}'.format(ARDUINO_PORT))

mayaconn = None
while mayaconn is None:
    try:
        mayaconn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        mayaconn.connect(MAYA_ADDR)
    except:
        mayaconn = None
        print('[ERROR] Maya connection refused.')
        print('[ERROR] (Maybe you didn\'t load the plugin in Maya?)')
        print('[INFO] Trying again in 5 seconds...')
        time.sleep(5)

print('[INFO] Maya connection established.')

arduinoconn = serial.Serial(ARDUINO_PORT)
print('[INFO] Arduino connection established.')

oldValues = [-1]*3
print("Hellu")
while True:
    values = arduinoconn.readline().split()
    for i, v in enumerate(values):
        vInt = 0
        try:
            vInt = int(v)
        except:
            pass
        else:
            if oldValues[i] != vInt:
                cmd = 'arduinoUpdateChannel ' + str(i) + ' ' + v
                mayaconn.send(cmd)
                time.sleep(.002)
            oldValues[i] = vInt
arduinoconn.close()
print('[INFO] Arduino connection closed.')

mayaconn.close()
print('[INFO] Maya connection closed.')

1 个答案:

答案 0 :(得分:0)

似乎您的程序曾经在Python 2上运行良好,现在您使用的是Python 3.您可以使用Python 2或在Python 3中修复此错误,您应该将相应的行更改为

cmd = 'arduinoUpdateChannel ' + str(i) + ' ' + str(v)

(将字节转换为字符串)