Im . Bir saniyelik zaman taradığımda bir hata alıyorum.Ekran SQLite çıkışı bir kart için satır gösterir 0.</p> <p>var bugüne kadar kod eğer 1 ise tk metin aletinin üzerinde görüntülemek ve ekrana kaldırmak benim db bir satır almaya çalışırken
import sqlite3 as db
import os
from prettytable import from_db_cursor
from smartcard.scard import *
from smartcard.util import toHexString
from prettytable import from_db_cursor
from smartcard.CardMonitoring import CardMonitor, CardObserver
import time
from Tkinter import Tk, BOTH, INSERT, Text
def main(tag):
q = "SELECT * FROM CARDS WHERE TAG=?"
up = "UPDATE CARDS SET FLAG = (CASE WHEN FLAG=0 THEN 1 ELSE 0 END) WHERE TAG=?"
id = "SELECT * FROM CARDS WHERE TAG=?"
cursor.execute(q, (tag,))
cursor.execute(up, (tag,))
conn.commit()
for row in cursor.execute(id, (tag,)):
print row [1] + row[2] #debugging to console
r1 = str(row[1])
r2 = str(row[2])
msg = str(r1 + r2)
text_widget = Text(root, font='times 40 bold', bg='Green')
text_widget.pack(fill=BOTH, expand=0)
text_widget.tag_configure('tag-center', wrap='word', justify='center')
text_widget.insert(INSERT, msg, 'tag-center')
root.mainloop()
class printobserver(CardObserver):
def update(self, observable, (addedcards, removedcards)):
previousIdString = ""
idString = ""
for card in addedcards:
if addedcards:
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
assert hresult==SCARD_S_SUCCESS
hresult, readers = SCardListReaders(hcontext, [])
assert len(readers)>0
reader = readers[0]
hresult, hcard, dwActiveProtocol = SCardConnect(
hcontext,
reader,
SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)
hresult, response = SCardTransmit(hcard,dwActiveProtocol,[0xFF,0xCA,0x00,0x00,0x04])
v = toHexString(response, format=0)
tag = str(v)
main(tag)
conn = db.connect('cards3.db')
root = Tk()
while True:
cursor = conn.cursor()
cardmonitor = CardMonitor()
cardobserver = printobserver()
cardmonitor.addObserver(cardobserver)
cardmonitor.deleteObserver(cardobserver)
time.sleep(2)
güncelleme altına
SQLite objects created in a thread can be used in that same thread.The object was created in thread id 6740 and this is thread id 6320
<traceback object at 0x02AAC418>
<class 'sqlite3.ProgrammingError'>
Traceback (most recent call last):
File "C:\rfid\main2.py", line 66, in <module>
cardmonitor.addObserver(cardobserver)
File "C:\Python27\lib\site-packages\smartcard\CardMonitoring.py", line 105, in addObserver
observer.update(self, (self.rmthread.cards, []))
File "C:\rfid\main2.py", line 56, in update
a(tag)
File "C:\rfid\main2.py", line 25, in a
root.mainloop()
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1017, in mainloop
self.tk.mainloop(n)
KeyboardInterrupt
Ana kodu: i aşağıdaki yanıtları itibaren şu anda yorgun var.
Taşınmış conn.cursor, ancak aynı sınıf içine. Farklı hata i tüm TK şeyler kaldırmak ve ben hiçbir sorunları ile tarama kartlarını tutabilir while True:
yukarıda cursor = conn.cursor
koyarsanız Coursor is not defined
import sqlite3 as db
import os
from prettytable import from_db_cursor
from smartcard.scard import *
from smartcard.util import toHexString
from prettytable import from_db_cursor
from smartcard.CardMonitoring import CardMonitor, CardObserver
import time
from Tkinter import Tk, BOTH, INSERT, Text
def main(tag):
q = "SELECT * FROM CARDS WHERE TAG=?"
up = "UPDATE CARDS SET FLAG = (CASE WHEN FLAG=0 THEN 1 ELSE 0 END) WHERE TAG=?"
id = "SELECT * FROM CARDS WHERE TAG=?"
cursor.execute(q, (tag,))
cursor.execute(up, (tag,))
conn.commit()
for row in cursor.execute(id, (tag,)):
print row [1] + " has been checked " + ('in' if row[2] else 'out')
r1 = str(row[1])
r2 = str(row[2])
mseg = str(r1 + r2)
text_widget = Text(root, font='times 40 bold', bg='Green')
text_widget.pack(fill=BOTH, expand=0)
text_widget.tag_configure('tag-center', wrap='word', justify='center')
text_widget.insert(INSERT, r1 + r2, 'tag-center')
root.mainloop()
class printobserver(CardObserver):
cursor = conn.cursor()
def update(self, observable, (addedcards, removedcards)):
previousIdString = ""
idString = ""
for card in addedcards:
if addedcards:
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
assert hresult==SCARD_S_SUCCESS
hresult, readers = SCardListReaders(hcontext, [])
assert len(readers)>0
reader = readers[0]
hresult, hcard, dwActiveProtocol = SCardConnect(
hcontext,
reader,
SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)
hresult, response = SCardTransmit(hcard,dwActiveProtocol,[0xFF,0xCA,0x00,0x00,0x04])
v = toHexString(response, format=0)
tag = str(v)
main(tag)
conn = db.connect('cards3.db')
root = Tk()
while True:
cardmonitor = CardMonitor()
cardobserver = printobserver()
cardmonitor.addObserver(cardobserver)
cardmonitor.deleteObserver(cardobserver)
time.sleep(2)
da hata
def main(tag):
cursor = conn.cursor
q = "SELECT * FROM CARDS WHERE TAG=?"
up = "UPDATE CARDS SET FLAG = (CASE WHEN FLAG=0 THEN 1 ELSE 0 END) WHERE TAG=?"
id = "SELECT * FROM CARDS WHERE TAG=?"
cursor.execute(q, (tag,))
cursor.execute(up, (tag,))
conn.commit()
for row in cursor.execute(id, (tag,)):
print row [1] + " has been checked " + ('in' if row[2] else 'out')
r1 = str(row[1])
r2 = str(row[2])
mseg = str(r1 + r2)
text_widget = Text(root, font='times 40 bold', bg='Green')
text_widget.pack(fill=BOTH, expand=0)
text_widget.tag_configure('tag-center', wrap='word', justify='center')
text_widget.insert(INSERT, r1 + r2, 'tag-center')
root.mainloop()
def update(self, observable, (addedcards, removedcards)):
previousIdString = ""
idString = ""
for card in addedcards:
if addedcards:
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
assert hresult==SCARD_S_SUCCESS
hresult, readers = SCardListReaders(hcontext, [])
assert len(readers)>0
reader = readers[0]
hresult, hcard, dwActiveProtocol = SCardConnect(
hcontext,
reader,
SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)
hresult, response = SCardTransmit(hcard,dwActiveProtocol,[0xFF,0xCA,0x00,0x00,0x04])
v = toHexString(response, format=0)
tag = str(v)
main(tag)
cursor = conn.cursor
ana ve güncelleme ama hala aynı koyarak yorgun mı olmak
def main(tag):
cursor = conn.cursor
q = "SELECT * FROM CARDS WHERE TAG=?"
up = "UPDATE CARDS SET FLAG = (CASE WHEN FLAG=0 THEN 1 ELSE 0 END) WHERE TAG=?"
id = "SELECT * FROM CARDS WHERE TAG=?"
cursor.execute(q, (tag,))
cursor.execute(up, (tag,))
conn.commit()
for row in cursor.execute(id, (tag,)):
print row [1] + " has been checked " + ('in' if row[2] else 'out')
'Bir iş parçacığı içinde oluşturulan SQLite nesneleri aynı iş parçacığı içinde kullanılabilir. 'Grab çıktı değişken değil! – dsgdfg
Bir txt dosyasına koyduktan sonra okuyabilirsiniz? – shaggs
Birden çok kez 'mainloop' çağırıyor gibi görünüyorsunuz. Niçin 'ana' çağrıldığında onu çağırıyorsun? Programınızın ömrü için tam olarak bir kez çağrılmalıdır.Bu belirli sorunun nedeni olmayabilir, ama kesinlikle bir problem. –