Kannst von mir aus denken das ich noch nie ein Programm auf die beine hgestellt habe dass nicht stimmt nur habe ich halt auch meine schwächen und mir fällt es schwer das Python script in java nachzubauen da ich mich kaum auskenne in dem bereich(Um ein Python Script in java nachzubauen mus ich Python können kann ich aber net) !
Beiträge von Elias177
-
-
Alos ich kann da so jetzt nichts herauslesen
-
dreamshader Wie meinst du mit "nur" übernehmen
-
Ja ist nur die Frage was ist der Passende File denn genau das habe ich auf den Raspberry Pi installiert und daher ist ja auch mein Quellcode
-
Ja aber ich kenne mich kaum mit Python aus heißt ich weiß nicht wo es steht.
Code
Alles anzeigen#!/usr/bin/env python # -*- coding: utf8 -*- # # Copyright 2014,2018 Mario Gomez <mario.gomez@teubi.co> # # This file is part of MFRC522-Python # MFRC522-Python is a simple Python implementation for # the MFRC522 NFC Card Reader for the Raspberry Pi. # # MFRC522-Python is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # MFRC522-Python is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with MFRC522-Python. If not, see <http://www.gnu.org/licenses/>. # import RPi.GPIO as GPIO import MFRC522 import signal continue_reading = True # Capture SIGINT for cleanup when the script is aborted def end_read(signal,frame): global continue_reading print "Ctrl+C captured, ending read." continue_reading = False GPIO.cleanup() # Hook the SIGINT signal.signal(signal.SIGINT, end_read) # Create an object of the class MFRC522 MIFAREReader = MFRC522.MFRC522() # Welcome message print "Welcome to the MFRC522 data read example" print "Press Ctrl-C to stop." # This loop keeps checking for chips. If one is near it will get the UID and authenticate while continue_reading: # Scan for cards (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL) # If a card is found if status == MIFAREReader.MI_OK: print "Card detected" # Get the UID of the card (status,uid) = MIFAREReader.MFRC522_Anticoll() # If we have the UID, continue if status == MIFAREReader.MI_OK: # Print UID print "Card read UID: %s,%s,%s,%s" % (uid[0], uid[1], uid[2], uid[3]) # This is the default key for authentication key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF] # Select the scanned tag MIFAREReader.MFRC522_SelectTag(uid) # Authenticate status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 8, key, uid) # Check if authenticated if status == MIFAREReader.MI_OK: MIFAREReader.MFRC522_Read(8) MIFAREReader.MFRC522_StopCrypto1() else: print "Authentication error"
-
String portName = "4223";
Doch habe ich hier einen portNamen den ich benötige und ich habe es schon mit Com versucht aber es geht nicht weiß jemand was da rein muss ?
-
Okay nochmal ich habe mir für den Raspberry Pi 3 RFID-MC522 module gekauft die ich gerne benutzen möchte. mit Python funktionieren sie auch sehr gut nun möchte ich aber das diesee Module mit java angesteuert werden und nicht mit Python da ich dies für meine Software benötige. Ich habe bissher auf Google einen Quellcode gefunden:
Java
Alles anzeigenpackage de.elias.viki.manager; import java.io.*; import java.util.*; import javax.comm.*; public class RFID implements Runnable { public static void main(String[] args) { Runnable runnable = new RFID(); new Thread(runnable).start(); System.out.println("main finished"); } CommPortIdentifier serialPortId; Enumeration enumComm; SerialPort serialPort; // OutputStream outputStream; InputStream inputStream; Boolean serialPortGeoeffnet = false; int baudrate = 9600; int dataBits = SerialPort.DATABITS_8; int stopBits = SerialPort.STOPBITS_1; int parity = SerialPort.PARITY_NONE; String portName = "4223"; int secondsRuntime = 30; public RFID() { System.out.println("Konstruktor: EinfachSenden"); } public void run() { Integer secondsRemaining = secondsRuntime; if (oeffneSerialPort(portName) != true) return; while (secondsRemaining > 0) { System.out.println("Sekunden verbleiben: " + secondsRemaining.toString()); secondsRemaining--; try { Thread.sleep(1000); } catch (InterruptedException e) { } } schliesseSerialPort(); } boolean oeffneSerialPort(String portName) { Boolean foundPort = false; if (serialPortGeoeffnet != false) { System.out.println("Serialport bereits geöffnet"); return false; } System.out.println("Öffne Serialport"); enumComm = CommPortIdentifier.getPortIdentifiers(); while (enumComm.hasMoreElements()) { serialPortId = (CommPortIdentifier) enumComm.nextElement(); if (portName.contentEquals(serialPortId.getName())) { foundPort = true; break; } } if (foundPort != true) { System.out.println("Serialport nicht gefunden: " + portName); return false; } try { serialPort = (SerialPort) serialPortId.open("Öffnen und Senden", 500); } catch (PortInUseException e) { System.out.println("Port belegt"); } /* * try { outputStream = serialPort.getOutputStream(); } catch * (IOException e) { * System.out.println("Keinen Zugriff auf OutputStream"); } */ try { inputStream = serialPort.getInputStream(); } catch (IOException e) { System.out.println("Keinen Zugriff auf InputStream"); } try { serialPort.addEventListener(new serialPortEventListener()); } catch (TooManyListenersException e) { System.out.println("TooManyListenersException für Serialport"); } serialPort.notifyOnDataAvailable(true); try { serialPort.setSerialPortParams(baudrate, dataBits, stopBits, parity); } catch (UnsupportedCommOperationException e) { System.out.println("Konnte Schnittstellen-Paramter nicht setzen"); } serialPortGeoeffnet = true; return true; } void schliesseSerialPort() { if (serialPortGeoeffnet == true) { System.out.println("Schließe Serialport"); serialPort.close(); serialPortGeoeffnet = false; } else { System.out.println("Serialport bereits geschlossen"); } } void serialPortDatenVerfuegbar() { try { byte[] data = new byte[150]; int num; while (inputStream.available() > 0) { num = inputStream.read(data, 0, data.length); System.out.println("Empfange: " + new String(data, 0, num)); } } catch (IOException e) { System.out.println("Fehler beim Lesen empfangener Daten"); } } class serialPortEventListener implements SerialPortEventListener { public void serialEvent(SerialPortEvent event) { System.out.println("serialPortEventlistener"); switch (event.getEventType()) { case SerialPortEvent.DATA_AVAILABLE: serialPortDatenVerfuegbar(); break; case SerialPortEvent.BI: case SerialPortEvent.CD: case SerialPortEvent.CTS: case SerialPortEvent.DSR: case SerialPortEvent.FE: case SerialPortEvent.OUTPUT_BUFFER_EMPTY: case SerialPortEvent.PE: case SerialPortEvent.RI: default: } } } }
doch fehlt mir der SerialPort von den Modulen. Diese SerialPort habe ich nirgendswo gefunden. Daher meine Frage kennen sie diesen SerialPort oder ist was am Quellcode falsch und sie würden ihn verändern oder einen neuen schreiben.
-
Habe mitlerweile einen Code gefunden doch leider gehlt mir der portName vom RFID-RC522 reader
Java
Alles anzeigenpackage de.elias.viki.manager; import java.io.*; import java.util.*; import javax.comm.*; public class RFID implements Runnable { public static void main(String[] args) { Runnable runnable = new RFID(); new Thread(runnable).start(); System.out.println("main finished"); } CommPortIdentifier serialPortId; Enumeration enumComm; SerialPort serialPort; // OutputStream outputStream; InputStream inputStream; Boolean serialPortGeoeffnet = false; int baudrate = 9600; int dataBits = SerialPort.DATABITS_8; int stopBits = SerialPort.STOPBITS_1; int parity = SerialPort.PARITY_NONE; String portName = "4223"; int secondsRuntime = 30; public RFID() { System.out.println("Konstruktor: EinfachSenden"); } public void run() { Integer secondsRemaining = secondsRuntime; if (oeffneSerialPort(portName) != true) return; while (secondsRemaining > 0) { System.out.println("Sekunden verbleiben: " + secondsRemaining.toString()); secondsRemaining--; try { Thread.sleep(1000); } catch (InterruptedException e) { } } schliesseSerialPort(); } boolean oeffneSerialPort(String portName) { Boolean foundPort = false; if (serialPortGeoeffnet != false) { System.out.println("Serialport bereits geöffnet"); return false; } System.out.println("Öffne Serialport"); enumComm = CommPortIdentifier.getPortIdentifiers(); while (enumComm.hasMoreElements()) { serialPortId = (CommPortIdentifier) enumComm.nextElement(); if (portName.contentEquals(serialPortId.getName())) { foundPort = true; break; } } if (foundPort != true) { System.out.println("Serialport nicht gefunden: " + portName); return false; } try { serialPort = (SerialPort) serialPortId.open("Öffnen und Senden", 500); } catch (PortInUseException e) { System.out.println("Port belegt"); } /* * try { outputStream = serialPort.getOutputStream(); } catch * (IOException e) { * System.out.println("Keinen Zugriff auf OutputStream"); } */ try { inputStream = serialPort.getInputStream(); } catch (IOException e) { System.out.println("Keinen Zugriff auf InputStream"); } try { serialPort.addEventListener(new serialPortEventListener()); } catch (TooManyListenersException e) { System.out.println("TooManyListenersException für Serialport"); } serialPort.notifyOnDataAvailable(true); try { serialPort.setSerialPortParams(baudrate, dataBits, stopBits, parity); } catch (UnsupportedCommOperationException e) { System.out.println("Konnte Schnittstellen-Paramter nicht setzen"); } serialPortGeoeffnet = true; return true; } void schliesseSerialPort() { if (serialPortGeoeffnet == true) { System.out.println("Schließe Serialport"); serialPort.close(); serialPortGeoeffnet = false; } else { System.out.println("Serialport bereits geschlossen"); } } void serialPortDatenVerfuegbar() { try { byte[] data = new byte[150]; int num; while (inputStream.available() > 0) { num = inputStream.read(data, 0, data.length); System.out.println("Empfange: " + new String(data, 0, num)); } } catch (IOException e) { System.out.println("Fehler beim Lesen empfangener Daten"); } } class serialPortEventListener implements SerialPortEventListener { public void serialEvent(SerialPortEvent event) { System.out.println("serialPortEventlistener"); switch (event.getEventType()) { case SerialPortEvent.DATA_AVAILABLE: serialPortDatenVerfuegbar(); break; case SerialPortEvent.BI: case SerialPortEvent.CD: case SerialPortEvent.CTS: case SerialPortEvent.DSR: case SerialPortEvent.FE: case SerialPortEvent.OUTPUT_BUFFER_EMPTY: case SerialPortEvent.PE: case SerialPortEvent.RI: default: } } } }
-
Hallo zusammen,
heute sind meine RFID-RC522 Module gekommen und ich habe sie sofort verlötet und an den RPI angeschlossen und alles hat auch funktioniert(Beschreiben und auslesen von Karten). Nun möchte ich das es alles über Java läuft da ich eine Software programmiert habe mit Java die damit arbeiten soll. Leider habe ich nichts auf Google gefunden daher seid ihr meine letzte Hoffnung, ich hoffe ihr versteht was ich meine und könnt mir helfen.
MFG
Elias177
Verkabelung im anhang: