×

Discussion Board

Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    Registered User
    Join Date
    Feb 2009
    Location
    Hagenberg, Austria
    Posts
    121

    Re: NFC read mifare 1k with 6216 classic

    Hallo,

    Quote Originally Posted by Jorge Gil View Post
    I will put on the same targetDetected the part of read and the part of writ but...it works?
    Yes, that should work (depending on what you want to achieve).

    Quote Originally Posted by Jorge Gil View Post
    How can i do? using a switch? or must make with if?, or just put after the read section?
    Well, that clearly depends on what your program should do.

    If your program should read and write data to the same tag during the same connection, just use the read and write functions as you like.

    If you want to read from certain tags and want to write to certain (other) tags, you will want to use some form of branching (e.g. if, case). The conditions for these branches can be whatever you like (e.g. a certain UID, a certain flag, that you previously set in your user interface, ...)

    br,
    Michael

  2. #17
    Registered User
    Join Date
    May 2010
    Posts
    16

    Re: NFC read mifare 1k with 6216 classic

    Well, that clearly depends on what your program should do.
    I have a list to choice read or write
    then if choice read, must read the mifare 1k, but if choice write, must write on same tag. But dont do at same time, or same conection.

    If you want to read from certain tags and want to write to certain (other) tags, you will want to use some form of branching (e.g. if, case). The conditions for these branches can be whatever you like (e.g. a certain UID, a certain flag, that you previously set in your user interface, ...)
    On same tag wanna do both options, but not at same time, first select from the list, read or write.

    Just to know wath time is on Australia?

    Regards.

  3. #18
    Registered User
    Join Date
    Feb 2009
    Location
    Hagenberg, Austria
    Posts
    121

    Re: NFC read mifare 1k with 6216 classic

    Hallo,

    Quote Originally Posted by Jorge Gil View Post
    I have a list to choice read or write
    then if choice read, must read the mifare 1k, but if choice write, must write on same tag. But dont do at same time, or same conection.
    Then, in the targetDetected event you just need to query your list which choice was selected by the user.

    Quote Originally Posted by Jorge Gil View Post
    Just to know wath time is on Australia?
    Austria...mountains, skiing, Mozart, Red Bull, ... but no kangaroos outside of a zoo ;-) It's 10 AM here.

    br,
    Michael

  4. #19
    Registered User
    Join Date
    May 2010
    Posts
    16

    Re: NFC read mifare 1k with 6216 classic

    Quote Originally Posted by mroland View Post
    Hallo,



    Then, in the targetDetected event you just need to query your list which choice was selected by the user.


    Austria...mountains, skiing, Mozart, Red Bull, ... but no kangaroos outside of a zoo ;-) It's 10 AM here.

    br,
    Michael
    Im sorry Austria, im asleep, i know i know no kangaroos jumping there sorry, just read Aust and dont read more...sorry.

    RBR are doing great job make F1 funny again but hope dont win all because if they won all, make so bored :P

    About targetDetected, how can i do the query? i explain
    Code:
    public void targetDetected(TargetProperties[] properties) {
            try {
                TargetProperties target = properties[0]; // always at least one target
                //open connection
                MFStandardConnection conn = (MFStandardConnection) Connector.open(target.getUrl(MFStandardConnection.class));
                 MFSector mfsector = conn.getSector(sectorIndex);
                MFBlock mfblock = mfsector.getBlock(blockIndex);
                //name
                byte[] KEY_SECTOR = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
                byte[] blockdata = new byte[mfblock.size()];
                readcnt = mfblock.read(new MFKey.KeyA(KEY_SECTOR), blockdata, 0, 0, mfblock.size());
                textField1.setString(new String(blockdata));
                //passport
                sectorIndex=1;
                 mfsector = conn.getSector(sectorIndex);
                blockIndex=1;
                mfblock= mfsector.getBlock(blockIndex);
                 byte[] KEY_SECTOR2 = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
                byte[] blockdata2 = new byte[mfblock.size()];
                readcnt2 = mfblock.read(new MFKey.KeyA(KEY_SECTOR2), blockdata2, 0, 0, mfblock.size());
                textField2.setString(new String (blockdata2));
                //code
                sectorIndex=1;
                 mfsector = conn.getSector(sectorIndex);
                 blockIndex=2;
                 mfblock= mfsector.getBlock(blockIndex);
                 byte[] KEY_SECTOR3 = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
                byte[] blockdata3 = new byte[mfblock.size()];
                readcnt3 = mfblock.read(new MFKey.KeyA(KEY_SECTOR3), blockdata3, 0, 0, mfblock.size());
                textField3.setString(new String (blockdata3));
    
                //close connection
                conn.close();
            } catch (Exception e) {
                textField1.setString("Scan Tag again");
            } finally {
                //closeQuietly(conn);   //Importante: cerramos la conexion
            }
        }
    That is the event when target are detected.
    and this one is the list.
    Code:
      public void commandAction(Command arg0, Displayable arg1) {
            try {
                if (arg0.equals(cmdEnviar)) {  //when push Enviar
                    elige = new List("Que hacer?: ", Choice.IMPLICIT);
                    elige.append("Leer", null); //Read
                    elige.append("Grabar", null); //Write
                    elige.append("Modificar", null);
                    elige.addCommand(cmdExit2);
                    elige.setCommandListener(this);
                    Display display = Display.getDisplay(this);
                    display.setCurrent(elige);
                } else if (arg0.equals(cmdExit) || arg0.equals(cmdExit2)) {
                    this.notifyDestroyed();
                } else if (arg0.equals(List.SELECT_COMMAND)) {
                    form.deleteAll();
    
                    form = new Form("Piloto Gestion NFC");
                    Ticker t = new Ticker("Piloto Gestion Residuos NFC");
    
                    form.setTicker(t);
                    textField1 = new TextField("Name ", "", 255, TextField.UNEDITABLE);
                    form.append(textField1);
                    textField2 = new TextField("passport ", "", 255, TextField.UNEDITABLE);
                    form.append(textField2);
                    textField3 = new TextField("Code ", "", 255, TextField.UNEDITABLE);
                    form.append(textField3);
                    form.setTitle("Hello Michael :P");
                    form.addCommand(cmdEnviar);
                    form.addCommand(cmdExit);
                    Display display = Display.getDisplay(this);
                    display.setCurrent(form);
                }
    
            } catch (Exception ex) {
            }
    
        }
    So if i understand well, you said that for example put a flag (one integer (1-2)) that when the users, select write or read, change, then when targetDetected event trigger, ask for that integer, for example, not?

  5. #20
    Registered User
    Join Date
    Feb 2009
    Location
    Hagenberg, Austria
    Posts
    121

    Re: NFC read mifare 1k with 6216 classic

    Hallo,

    Quote Originally Posted by Jorge Gil View Post
    So if i understand well, you said that for example put a flag (one integer (1-2)) that when the users, select write or read, change, then when targetDetected event trigger, ask for that integer, for example, not?
    Right, that's one possibility.

    br,
    Michael

  6. #21
    Registered User
    Join Date
    May 2010
    Posts
    16

    Re: NFC read mifare 1k with 6216 classic

    Quote Originally Posted by mroland View Post
    Hallo,



    Right, that's one possibility.

    br,
    Michael
    Ok, Thank you again, i will do that.

  7. #22
    Registered User
    Join Date
    May 2010
    Posts
    16

    Re: NFC read mifare 1k with 6216 classic

    Code:
    if (hacer==2){
                     TargetProperties target = properties[0]; // always at least one target
                      MFStandardConnection conn = (MFStandardConnection) Connector.open(target.getUrl(MFStandardConnection.class));
                sectorIndex=1;
                 MFSector mfsector = conn.getSector(sectorIndex);
                 blockIndex=0;
                MFBlock mfblock = mfsector.getBlock(blockIndex);
                byte[] KEY_SECTOR = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
                byte[] blockdata = new byte[mfblock.size()];
                nombre=textField1.getString();
                byte[] res = nombre.getBytes();
                mfblock.write(new MFKey.KeyA(KEY_SECTOR),res, res.length);
    Its ok?
    on targetDetected...dont do nothing, throws me the exception e.

    Thanks

  8. #23
    Registered User
    Join Date
    Feb 2009
    Location
    Hagenberg, Austria
    Posts
    121

    Re: NFC read mifare 1k with 6216 classic

    Hallo,

    Quote Originally Posted by Jorge Gil View Post
    Its ok?
    It's okay if it does what you want. Although, I suggest you do some input and error checking (e.g. check that the value in textField1 is not too long for the block).


    Quote Originally Posted by Jorge Gil View Post
    on targetDetected...dont do nothing, throws me the exception e.
    Sorry, but I don't understand what you are trying to say here.

    br,
    Michael

  9. #24
    Registered User
    Join Date
    May 2010
    Posts
    16

    Re: NFC read mifare 1k with 6216 classic

    Quote Originally Posted by mroland View Post
    Hallo,

    It's okay if it does what you want. Although, I suggest you do some input and error checking (e.g. check that the value in textField1 is not too long for the block).

    Sorry, but I don't understand what you are trying to say here.

    br,
    Michael
    But, that will write on the tag, the characters on the textField1? or what?
    Code:
    byte[] KEY_SECTOR = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
                byte[] blockdata = new byte[mfblock.size()];
                nombre=textField1.getString();
                byte[] res = nombre.getBytes();
                mfblock.write(new MFKey.KeyA(KEY_SECTOR),res, res.length);
    I just wanna know how to write on my tag the characters on the textField1 (about the lenght or similar will make the control after when i learn to write).

    Thanks and have a good Friday¡¡¡¡

  10. #25
    Registered User
    Join Date
    May 2010
    Posts
    16

    Lightbulb Re: NFC read mifare 1k with 6216 classic

    Yeah it WRITE

    The problem was with that code

    Code:
    mfblock.write(new MFKey.KeyA(KEY_SECTOR),blockdata, 0, 0, blockdata.lenght());
    do not write, always give me the exception.

    But with that:

    Code:
    mfblock.write(new MFKey.KeyA(KEY_SECTOR), res, 0);
    WORKS.

    Really thanks for your help Michael

Similar Threads

  1. [moved, again] I get error messages when I try to write to Mifare 1k
    By andersljung in forum Near Field Communication
    Replies: 3
    Last Post: 2008-06-18, 12:10
  2. JSR 257 Read Mifare Ultra Light
    By Alex_Polt in forum Near Field Communication
    Replies: 9
    Last Post: 2007-08-17, 12:09
  3. Nokia 6131 NFC SDK 1.0 has been released
    By Nokia Ron in forum Near Field Communication
    Replies: 0
    Last Post: 2007-03-26, 22:28
  4. Can't read RFID Tag with NFC Shell
    By begermic in forum Mobile Java Tools & SDKs
    Replies: 5
    Last Post: 2007-01-31, 23:02
  5. socket read hangs until socket is closed
    By camroe in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-07-21, 09:44

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×