-5

Me and my friend is trying to implement an Arduinoboard controller into Maya. We did not write the code ourselves, and we cannot get hold of the person who wrote it. We're not programmers but we know how to read and edit Python code. Our problem is probably really simple, but we can't figure out how to solve it. We have Googled it and read on multiple forums without any luck. Basically we don't have knowledge enough to know how other peoples problems/solutions would be applicable to our specific code.

Error message:

Error message can be seen here

This is the code:

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.')
gre_gor
  • 6,669
  • 9
  • 47
  • 52
  • 2
    Welcome to Stack Overflow. This is not a code/SQL/regex writing service, where you post a list of your requirements and language of choice and a code monkey churns out code for you. We're more than happy to help, but we expect you to make an effort to solve the problem yourself first. Once you've done so, you can explain the problem you're having, include the **relevant** portions of your work, and ask a specific question, and we'll try to help. Good luck. – Ken White Feb 20 '18 at 13:37
  • As I said, we've been trying to solve it. That's why we asked for help, can't you read? – David Löfqvist Feb 20 '18 at 13:40
  • 2
    I read fine. Can you? See the [help/on-topic], particularly the section with the numbered list. Better yet, spend some time taking the [tour] first, and then go on to read the [help] pages. – Ken White Feb 20 '18 at 13:41
  • Our problem is: We can't solve the error message? We've tried multiple ways. But we don't know how to do it. That's why we ask people on the forum for help – David Löfqvist Feb 20 '18 at 13:41
  • 1
    This site is not a forum. It's on of the first things mentioned in the [tour]. This site is also not a free debugging service. – gre_gor Feb 20 '18 at 14:38
  • For these types of questions, the maya programming forum at the autodesk area website can be quite helpful. – haggi krey Feb 20 '18 at 14:47
  • seems that v is a byte type and not a string : https://stackoverflow.com/questions/606191/convert-bytes-to-a-string – DrWeeny Feb 20 '18 at 18:33

1 Answers1

0

It seems that your program used to work fine on Python 2 and now you use Python 3. You can either use Python 2 or to fix this error in Python 3 you should change the corresponding line to

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

(convert bytes to string)

ababak
  • 1,685
  • 1
  • 11
  • 23