OpenERP RFID终端模块错误

时间:2013-11-30 15:15:12

标签: python-2.7 openerp

在新的OpenERP 7数据库上成功安装RFID Terminal module以从ZKTeco DS100机器中提取出勤日志后,我尝试在模块中添加用户(将机器上的ID与OpenERP中的员工ID相关联) 。我收到错误:

    File "C:\Program Files (x86)\OpenERP 7.0-20130610-231029\Server\server\openerp\addons\hr_attendance_terminal\hr_attendance_terminal.py", line 230, in create_terminal_users
    UnboundLocalError: local variable 's' referenced before assignment

代码块:

def create_terminal_users(self, cr, uid, automatic=False, use_new_cursor=False, context=None):
            if context is None:
            context = {}

        terminal_ids = self.pool.get('hr.attendance.terminal').search(cr, uid, [])

        for t_id in terminal_ids:
            terminal = self.pool.get('hr.attendance.terminal').browse(cr, uid, t_id, context=context)
            #print "CREATE USER ON Terminal: %s | %s" % (terminal.tnr, terminal.ip)

            TerminalNr = terminal.tnr # zweistelling in Hex         
            host = terminal.ip # Terminaladresse

            port = 8000 # Terminaldatenport
            STX = '\x02' # Startbit
            ETX = '\x03' # Stopbit

            emp_ids = self.pool.get('hr.employee').search(cr, uid, [('rfid_key', '!=', '')])
            if emp_ids:

                #Verbindung herstellen
                s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                try:
                    s.connect((host,port))
                except socket.error, msg:
                    print 'Socket Error: %s' % msg
                    break

                for emp_id in emp_ids:
                    employee = self.pool.get('hr.employee').browse(cr, uid, emp_id, context=context)

                    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                    rfid_key = employee.rfid_key
                    employee_name = employee.name
                    pin = '0000'
                    pinabfrage = '0' # bei 1 wird pin abgefragt
                    infotext1 = '                ' # 16 Zeichen Infotext
                    infotext2 = employee_name.center(16) # 16 Zeichen Infotext
                    infotext3 = '                ' # 16 Zeichen Infotext
                    infotext4 = '                ' # 16 Zeichen Infotext

                    #Paket / Telegram erstellen
                    #Schema: <STX>SS<Kommando><Daten><BCC><ETX>

                    bccstring = self.create_bcc(TerminalNr + 'SPSTA' + rfid_key + pin + pinabfrage + infotext1 + infotext2 + infotext3 + infotext4)
                    message = STX + TerminalNr + 'SPSTA' + rfid_key + pin + pinabfrage + infotext1 + infotext2 + infotext3 + infotext4 + bccstring + ETX
                    #print "Employee: %s" % employee.name
                    #Paket / Telegram senden
                    try:
                        s.sendall(message)
                    except socket.error, msg:
                        print 'Socket Error: %s' % msg
                        break
                    while 1:
                        reply = s.recv(8192)
                        if str(reply) != '':
                            r_message = re.sub(r'\x02|\x03','',str(reply))
                            r_terminal = r_message[0:2]
                            if r_message[2:7] == 'SPSTA':
                                #print "Stammsatz gespeichert!"
                                break

        s.close()
        return True

备注:

  • 虽然模块是为OERP 6构建的,但模块正常安装。
  • 进行微小更改以匹配OERP 7 import功能。
  • Python 2.7

2 个答案:

答案 0 :(得分:0)

s.close()应该进入for循环。

答案 1 :(得分:0)

我想对此添加评论,因为我们是模块的创建者。 您安装的模块仅适用于此特定设备:来自ADC GmbH的Officetimer II,而不是任何其他RFID考勤设备!

请注意,公开提供的模块仅是2011年中期OpenERP版本6.0的第一个版本,实际上您可以将其称为草稿,错误修正和增强功能尚未应用于启动板分支!由于处理终端通信和时区管理,本模块实际上不应与OpenERP的6.1或7.0版一起使用!

当然,我们已将模块移植到6.1和7.0,但由于多种原因,我们尚未公开这些模块。