import usb.core import usb.util import csv import logging import socket import time logging.basicConfig(filename='maquette.log',level=logging.DEBUG) class EthernetRelayBoard(object): def __init__(ptcpIpAdress,ptcpPort): self.tcpIpAdress = ptcpIpAdress self.tcpPort = ptcpPort self.connected= true def connect(): self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.connect((self.tcpIpAdress, self.tcpIpport)) self.connected = true def disconnect(): if self.connected : self.socket.close() def openRelay(prelay): self.connect() if self.connected : if prelay = 1 : SendCommandToRelays ( b'\x21\x01\x00' ) else if prelay = 2 : SendCommandToRelays ( b'\x21\x02\x00' ) else if prelay = 3 : SendCommandToRelays ( b'\x21\x02\x00' ) else if prelay = 4 : SendCommandToRelays ( b'\x21\x02\x00' ) else if prelay = 5 : SendCommandToRelays ( b'\x21\x02\x00' ) else if prelay = 6 : SendCommandToRelays ( b'\x21\x02\x00' ) else if prelay = 7 : SendCommandToRelays ( b'\x21\x02\x00' ) else if prelay = 8 : SendCommandToRelays ( b'\x21\x02\x00' ) else if prelay = 9 : SendCommandToRelays ( b'\x21\x02\x00' ) else if prelay = 10 : SendCommandToRelays ( b'\x21\x02\x00' ) self.disconnect() def closeRelay(prelay): self.connect() if self.connected : if prelay = 1 : SendCommandToRelays ( b'\x20\x01\x00' ) else if prelay = 2 : SendCommandToRelays ( b'\x20\x02\x00' ) else if prelay = 3 : SendCommandToRelays ( b'\x20\x02\x00' ) else if prelay = 4 : SendCommandToRelays ( b'\x20\x02\x00' ) else if prelay = 5 : SendCommandToRelays ( b'\x20\x02\x00' ) else if prelay = 6 : SendCommandToRelays ( b'\x20\x02\x00' ) else if prelay = 7 : SendCommandToRelays ( b'\x20\x02\x00' ) else if prelay = 8 : SendCommandToRelays ( b'\x20\x02\x00' ) else if prelay = 9 : SendCommandToRelays ( b'\x20\x02\x00' ) else if prelay = 10 : SendCommandToRelays ( b'\x20\x02\x00' ) seld.disconnect() def sendCommandToRelays (MESSAGE): self.socket.send(MESSAGE) data = s.recv(BUFFER_SIZE) #Response from Relays #if data != b'\x00' echec ! class NfcArea(object): def __init__(self,pidVendor,pidProduct,pidRelay,pname,pfilename): self.nfcReader=none self.idVendor = pidVendor self.idProduct = pidProduct self.idrelay = pidrelay self.activated = false self.name = pname self.filename = pfilename def OpenUsb(): self.nfcReader = usb.core.find(self.idVendor, self.idProduct) def isOpen(): self.nfcReader != none def Activate(): self.activated = true def Release(): self.activated = false def isActivated(): return self.activated == true def check(): return false def getFile(): return self.filename def getId(): return self.idRelay class Tests(object): def __init__(): Self.TestBoardResult = false; def testrelayBoard(): relayBoard = EthernetRelayBoard('192.168.2.115',17494) for i in range(0,100): relayBoard.Open(i) time.sleep(0.250) nfcReaders=[] idPelerin = 0 idMoine = 0 #fichier csv de la forme #name,id #pelerin, 1234 #moine,5678 with open('maquette_tag_config.csv') as csvfile: reader = csv.DictReader(csvfile) for row in reader: statue = row['name'] if statue == "pelerin": idPelerin = row['id']) elif statue == "moine": idMoine = statue #fichier csv de la forme #idVendor,idProduct,idRelay,zone1,/home/pi/Videos/intro.mp4 #pelerin,1234,54546,1,cloître,/home/pi/Videos/cloître.mp4 #moine,5678, with open('maquette_reader_config.csv') as csvfile: reader = csv.DictReader(csvfile) for row in reader: nfcReaders.appends( NfcReader(row['idVendor'],row['idProduct'],row['idRelay'],row['zone'],row['file'])) i=i+1 tests = Tests() tests.testRelayBoard()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question