1

我的程序需要一些帮助。不知何故,它进入异常并打印 EROR1 和 EROR2。我正在寻找一种方法如何解决

nxt.error.DirProtError

但我什么也找不到。

import nxt, nxt.bluesock, time
from nxt.error import I2CError, I2CPendingError, DirProtError
from time import sleep, time
import struct

 
GINGI = '00:16:53:0A:B3:9C'
TESTING = '00:16:53:06:AE:3D'
TESTING1='00:16:53:0A:B3:95'
ABC='00:16:53:06:B4:CB'
TEST2='00:16:53:06:B1:E0'
#evry ofset is on secends

y_OFFSET=7
x_floor=6.85
y_floor=2
 
def CheckArr(arr):
    for x in range(len(arr)):
        for y in range(len(arr[x])):
            if arr[x][y] == 0:
                arr[x][y]=1
                print str(x)
                print str(y)
                return (x, y)
    raise Exception("sorry threre is no palce")#throw exception if threre is no place
    
def admin_check(arr):
    for x in range(len(arr)):
        for y in range(len(arr[x])):
            if arr[x][y] == 1:
             return True
    return False

def output(x,y,arr,code):
    if arr[x][y]==1 and code==(pow(x,2)+pow(y,2)):
        print 'the car is on the way'
        arr[x][y]==0
        return(x,y)
        time.sleep(3)
    else:
         print 'wrong values'
         print 'would you like to try agin'
         print 'if you want to try again write yes else no'
         string1=raw_input()
         if string1=='yes':
             output(x,y,arr,code)
         else:
            print 'goodbye'
def admin(arr):
    print 'hello admin enter to the cumpter the line of the car'
    x_temp=raw_input()
    while x_temp<0:
        print 'cannot be under 0! enter again'
#must be done becuse negetive number 2 in power of num(acording to the code)is positive so the value will be currect but in the nxt proram it wont work properly becuse the value of x and y are indicats to the system how much they can move
        x_temp=raw_input()
    print 'enter to the computer the column of the car'
    y_temp=raw_input()
    while y_temp<0:
        print 'cannot be under 0! enter again'
#must be done because negative number 2 in power of num (according to the code) is positive so the value will be correct but in the next program it won't work properly because the values of x and y are indicates to the system how much they can move
        y_temp=raw_input()
    print'would you like to input car or output'
    string=raw_input()
    while string!='input' and string!='output':
        print'give a write order'
        string=raw_input()
    if string=='input': 
        brick.message_write(0, str(1))
        brick.message_write(0,str(x))
        brick.message_write(0,str(y))
    else :
        brick.message_write(0, str(2))
        brick.message_write(0,str(x))
        brick.message_write(0,str(y))
    

 
if __name__ == "__main__":
    message1='fine'
    admin_code='pinokio208'
    pre_admin_code='shokoboko123'
    print 'entered to the program'
    brick = nxt.bluesock.BlueSock(TEST2).connect()
    brick1 = nxt.bluesock.BlueSock(ABC).connect()
    print 'Connected'
    arr2 = [[0 for i in range(5)] for j in range(8)] 
    while  True:
        catch=False
        print 'to enter a car press 1'
        print 'to get out a car press 2'
        ans=raw_input()
        if ans==str(1):
            try:
                x, y  = CheckArr(arr2)
            except NameError as e :
                print e
                catch=True
            if(not catch) :
                brick.message_write(0, str(1))#send throw bluetooth to the controler
                print 'the loction is {0} {1}'.format(str(x),str(y))
                print 'the code is {0}'.format(pow(x,2)+pow(y,2))
                x=x*x_floor
                brick.message_write(0, str(x))#send the time that the macine must work on the x line
                y=y_floor
                try: 
                    inbox,catcher=brick.message_read(10,1,True)
                    message1=catcher
                except nxt.error.DirProtError, e:
                    print 'EROR1'
                brick1.message_write(0, str(y))#send the time that the macine must work on the y line to the secound controller
                brick1.message_write(0,str(message1))
                try:
                    inbox,message1=brick1.message_read(11,2,True)
                except nxt.error.DirProtError, e:
                    print 'EROR2'
                brick1.message_write(0, str(0))
        elif ans==str(2):
            print 'enter  your code'
            code=raw_input()
            print 'enter to the cumpter the line of the car'
            x_temp=raw_input()
            while x_temp<0:
                print 'cannot be under 0! enter again'
#must be done becuse negetive number 2 in power of num(acording to the code)is positive so the value will be currect but in the nxt proram it wont work properly becuse the value of x and y are indicats to the system how much they can move
                x_temp=raw_input()
            print 'enter to the computer the column of the car'
            y_temp=raw_input()
            while y_temp<0:
                print 'cannot be under 0! enter again'
#must be done because negative number 2 in power of num (according to the code) is positive so the value will be correct but in the next program it won't work properly because the value of x and y are indicates to the system how much they can move
                y_temp=raw_input()
            x,y=output(int(x_temp),int(y_temp),arr2,int(code))
            brick.message_write(0, str(2))
            brick.message_write(0,str(x))
            brick.message_write(0,str(y))
        elif ans==str(207):
            print'give the pre admin code'
            pre_admin_code_temp=raw_input()
            if pre_admin_code_temp!=pre_admin_code :
                print'wrong code!'
            else:
                print'give your admin code wrong code will shut the system for 20 min'
                admin_code=raw_input()
                if admin_code!=temp_admin_code:
                    time.sleep(1200) #wait 20 min before somthing else can be happening
                else:
                    brick.message_write(0, str(3))
                    exit()
        elif ans==str(208):
            print'give the pre admin code'
            pre_admin_code_temp=raw_input()
            if pre_admin_code_temp!=pre_admin_code :
                print'wrong code!'
            else:
                print'give your admin code wrong code will shut the system for 20 min'
                admin_code=raw_input()
                if admin_code!=temp_admin_code:
                    time.sleep(1200) #wait 20 min before somthing else can be happening
                else:
                    if admin_check(arr2):
                        admin(arr2)
                    else:
                        print'now allowd still have cars'
        elif ans==str(209):
            print'give the pre admin code'
            pre_admin_code_temp=raw_input()
            if pre_admin_code_temp ==pre_admin_code :
                print'wrong code!'
            else:
                print'give your admin code wrong code will shut the system for 20 min'
                admin_code=raw_input()
                if admin_code != temp_admin_code:
                    time.sleep(1200) #wait 20 min before somthing else can be happening
                else:
                    print'give the cell x than y'
            
        else:
            print'wrong number'
            
        
        
            






    
    

该程序适用于 2 个控制器。我这里不能上传,所以如果有人可以帮助我,请索取代码,我会在私信中发送。感谢所有可以提供帮助的人。

4

0 回答 0