Jump to content

NFC/RFID Bricklet


Nel Zur

Recommended Posts

Programmiersprache: Java

public static void analyse() {



	nr.addStateChangedListener(new BrickletNFCRFID.StateChangedListener() {
		public void stateChanged(short state, boolean idle) {
			try {
				nr.requestPage(5);
			} catch (TimeoutException | NotConnectedException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			if (state == BrickletNFCRFID.STATE_REQUEST_PAGE_READY) {
				// Get and print pages
				short[] data;
				try {
					data = nr.getPage();

					bochPos = data[0];
					jusPos = data[1];
					cerealesPos = data[2];
					painPos = data[3];
					co1Pos = data[4];
					co2Pos = data[5];
				} catch (TimeoutException | NotConnectedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				System.out.println(bochTableau[bochPos].getDescription() + " " + jusTableau[jusPos].getDescription()
						+ " " + cerealesTableau[cerealesPos].getDescription() + " "
						+ painTableau[painPos].getDescription() + " " + confitureTableau[co1Pos].getDescription()
						+ " " + confitureTableau[co2Pos].getDescription());

				WindowController.getInstance().nextNFC(bochTableau[bochPos], jusTableau[jusPos],
						cerealesTableau[cerealesPos], painTableau[painPos], confitureTableau[co1Pos],
						confitureTableau[co2Pos]);

				try {
					ipcon.disconnect();
				} catch (NotConnectedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			System.out.println("State " + state);
		}
	});

	try {
		nr.requestTagID(BrickletNFCRFID.TAG_TYPE_TYPE2);
	} catch (TimeoutException | NotConnectedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	// Select NFC Forum Type 2 tag

}

 

und das ist mein Programm

Link to comment
Share on other sites

  • 2 weeks later...

Du rufst nur einmal "nr.requestTagID(BrickletNFCRFID.TAG_TYPE_TYPE2);" auf. Du musst innerhalb deiner stateChanged Methode am Ende wieder "nr.requestTagID(BrickletNFCRFID.TAG_TYPE_TYPE2);" aufrufen, wenn du mit dem Auslesen des Tags fertig bist. Das stößt dann die Suche nach dem nächsten Tag an.

 

Schau dir auch mal das "Scan for Tags" Beispiel an:

 

https://www.tinkerforge.com/de/doc/Software/Bricklets/NFCRFID_Bricklet_Java.html#scan-for-tags

Link to comment
Share on other sites

	nr.addStateChangedListener(new BrickletNFCRFID.StateChangedListener() {
		public void stateChanged(short state, boolean idle) {
			try {
				nr.requestPage(5);
			} catch (TimeoutException | NotConnectedException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			if (state == BrickletNFCRFID.STATE_REQUEST_PAGE_READY) {
				// Get and print pages
				short[] data;
				try {
					data = nr.getPage();

					bochPos = data[0];
					jusPos = data[1];
					cerealesPos = data[2];
					painPos = data[3];
					co1Pos = data[4];
					co2Pos = data[5];
					vidangePos = data[6];
				} catch (TimeoutException | NotConnectedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				try {
					ipcon.disconnect();
				} catch (NotConnectedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				System.out.println(bochTableau[bochPos].getDescription() + " " + jusTableau[jusPos].getDescription()
						+ " " + cerealesTableau[cerealesPos].getDescription() + " "
						+ painTableau[painPos].getDescription() + " " + confitureTableau[co1Pos].getDescription()
						+ " " + confitureTableau[co2Pos].getDescription() + " vidange: "
						+ vidangeTableau[vidangePos].getDescription());

				WindowController.getInstance().nextNFC(bochTableau[bochPos], jusTableau[jusPos],
						cerealesTableau[cerealesPos], painTableau[painPos], confitureTableau[co1Pos],
						confitureTableau[co2Pos], vidangeTableau[vidangePos]);

			}
			else if((state & (1 << 6)) == (1 << 6)) {
			System.out.println("State " + state);


			}
			try {
				nr.requestTagID(BrickletNFCRFID.TAG_TYPE_TYPE2);
			} catch (TimeoutException | NotConnectedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}


	});

	try {
		nr.requestTagID(BrickletNFCRFID.TAG_TYPE_TYPE2);
	} catch (TimeoutException | NotConnectedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

 

So klappt es immer noch nicht :-\

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...