Announcement

Collapse
No announcement yet.

RFiD reader serial communication

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Hi,

    I noticed an error in your MagicTouch code where one of the chars you are trying to add to the buffer may not work.

    In MagicTouch
    if (ImageTouched == iWinbutton0)
    to(outbufstring) ; putch (char);
    to(APPEND) ; putch (",");
    to(APPEND) ; putch ("1");
    to (COM2); print([STR] outbufstring);
    n:=sizeof(combuf1);
    while(n--)combuf1[n]:=0;
    n:=sizeof(outbufstring);
    while(n--)outbufstring [n]:=0;

    else if (ImageTouched == iWinbutton1)
    to(outbufstring) ; putch (char);
    to(APPEND) ; putch (",");
    to(APPEND) ; putch ("2");
    to (COM2); print([STR] outbufstring);
    n:=sizeof(combuf1);
    while(n--)combuf1[n]:=0;
    n:=sizeof(outbufstring);
    while(n--)outbufstring [n]:=0;

    endif

    or

    In MagicTouch
    if (ImageTouched == iWinbutton0)
    to(outbufstring) ; putch (char);
    to(APPEND) ; print (",1");
    to (COM2); print([STR] outbufstring);
    n:=sizeof(combuf1);
    while(n--)combuf1[n]:=0;
    n:=sizeof(outbufstring);
    while(n--)outbufstring [n]:=0;

    else if (ImageTouched == iWinbutton1)
    to(outbufstring) ; putch (char);
    to(APPEND) ; print (",2");
    to (COM2); print([STR] outbufstring);
    n:=sizeof(combuf1);
    while(n--)combuf1[n]:=0;
    n:=sizeof(outbufstring);
    while(n--)outbufstring [n]:=0;

    endif

    Best regards

    Paul

    Comment


    • #17
      Hi Paul,

      made a variable with fix content tag id A3F1275A for better testing.
      Both commands "putch" and "print" doesn´t output the expected result.


      In Constant/Global/Data
      var fs ; fs:= "A3F1275A" ;


      In MagicTouch
      if (ImageTouched == iWinbutton0)
      to(outbufstring) ; putch (fs);
      to(APPEND) ; putch (",");
      to(APPEND) ; putch ("1");
      to (COM2); print([STR] outbufstring);
      n:=sizeof(combuf1);
      while(n--)combuf1[n]:=0;
      n:=sizeof(outbufstring);
      while(n--)outbufstring [n]:=0;

      else if (ImageTouched == iWinbutton1)
      to(outbufstring) ; print (fs);
      to(APPEND) ; print (",2");
      to (COM2); print([STR] outbufstring);
      n:=sizeof(combuf1);
      while(n--)combuf1[n]:=0;
      n:=sizeof(outbufstring);
      while(n--)outbufstring [n]:=0;

      endif

      With "putch" no output in sniffer on COM2
      With "print" output 0,2 in sniffer on COM2

      Thank you in advance

      Doms

      Comment


      • #18
        Hi,

        This line,

        In Constant/Global/Data
        var fs ; fs:= "A3F1275A" ;

        Would be better like,

        var fs[5];

        to(fs);
        print("A3F1275A");

        and then

        In MagicTouch
        if (ImageTouched == iWinbutton0)
        to(outbufstring) ; putstr(fs);
        to(APPEND) ; print(",1");
        to (COM2); print([STR] outbufstring);
        n:=sizeof(combuf1);
        while(n--)combuf1[n]:=0;
        n:=sizeof(outbufstring);
        while(n--)outbufstring [n]:=0;

        else if (ImageTouched == iWinbutton1)
        to(outbufstring) ; putstr(fs);
        to(APPEND) ; print (",2");
        to (COM2); print([STR] outbufstring);
        n:=sizeof(combuf1);
        while(n--)combuf1[n]:=0;
        n:=sizeof(outbufstring);
        while(n--)outbufstring [n]:=0;

        endif

        Best regards

        Paul

        Comment


        • #19
          Hi Paul,

          i have changed my code a bit and it works, thank you.

          Now one more (hope the last) problem i have.

          From RFiD Reader the origin output in sniffer on com2 is:
          <STX>A3F1275A<CR><LF><ETX>

          I want to add 1, at the beginning of tag id when winbutton0 touched and 2, when winbutton1 touched.
          <STX>1,A3F1275A<CR><LF><ETX>
          <STX>2,A3F1275A<CR><LF><ETX>

          My code replace caracter instead of adding.
          <STX>1,F1275A<CR><LF><ETX>
          <STX>A32,275A<CR><LF><ETX>

          Best Regards

          Doms



          My code:

          In MainLoop
          fs := str_Ptr(outbufstring) ;

          In Constant/Global/Data
          var fs;

          In MagicTouch
          if (ImageTouched == iWinbutton0)
          to(outbufstring) ; print([ STR] combuf1);
          to(APPEND) ; str_PutByte (fs + 1, '1');
          to(APPEND) ; str_PutByte (fs + 2, ',');
          to (COM2); print([STR] outbufstring);
          n:=sizeof(combuf1);
          while(n--)combuf1[n]:=0;
          n:=sizeof(outbufstring);
          while(n--)outbufstring [n]:=0;
          com1_Init(combuf1,40,0) ;


          else if (ImageTouched == iWinbutton1)
          to(outbufstring) ; print([ STR] combuf1);
          to(APPEND) ; str_PutByte (fs + 3, '2');
          to(APPEND) ; str_PutByte (fs + 4, ',');
          to (COM2); print([STR] outbufstring);
          n:=sizeof(combuf1);
          while(n--)combuf1[n]:=0;
          n:=sizeof(outbufstring);
          while(n--)outbufstring [n]:=0;
          com1_Init(combuf1,40,0) ;

          endif

          Comment


          • #20
            Hi,

            You might be able to do this by creating a temporary string.



            In MagicTouch
            var tempString[20];

            if (ImageTouched == iWinbutton0)
            to(outbufstring) ; print([ STR] combuf1);
            to(tempString) ; print("1,");
            to(APPEND) ; print([STR] outbufstring);
            to (COM2); print([STR] tempString);
            n:=sizeof(combuf1);
            while(n--)combuf1[n]:=0;
            n:=sizeof(outbufstring);
            while(n--)outbufstring [n]:=0;
            com1_Init(combuf1,40,0) ;


            else if (ImageTouched == iWinbutton1)
            to(outbufstring) ; print([ STR] combuf1);
            to(tempString) ; print("2,");
            to(APPEND) ; print([STR] outbufstring);
            to (COM2); print([STR] tempString);
            n:=sizeof(combuf1);
            while(n--)combuf1[n]:=0;
            n:=sizeof(outbufstring);
            while(n--)outbufstring [n]:=0;
            com1_Init(combuf1,40,0) ;

            endif


            This should join the "1," and your string together.

            Best regards

            Paul

            Comment


            • #21
              Hi Paul,

              solution with temporary string works fine but output in sniffer on COM2 is:
              1,<STX>A3F1275A<CR><LF><ETX>
              2,<STX>A3F1275A<CR><LF><ETX>

              but i need:

              <STX>1,A3F1275A<CR><LF><ETX>
              <STX>2,A3F1275A<CR><LF><ETX>


              Best Regards

              Doms

              Comment


              • #22
                Hi,

                Yes the previous example was adding it to the front and not in between. Could you please try the following example

                var tempString[20];
                var char;
                var p;

                if (ImageTouched == iWinbutton0
                to(outbufstring) ; print([ STR] combuf1);
                p := str_Ptr(outbufstring);
                char := str_GetByte(p);
                to(tempString);
                print([CHR] char);
                while(char != 3)
                char := str_GetByte(p);
                if(char == 2)
                to(APPEND);
                print("1,");
                else
                to(APPEND);
                print([CHR] char);
                endif
                p++;
                wend
                to (COM2); print([STR] tempString);
                n:=sizeof(combuf1);
                while(n--)combuf1[n]:=0;
                n:=sizeof(outbufstring);
                while(n--)outbufstring [n]:=0;
                com1_Init(combuf1,40,0) ;

                else if (ImageTouched == iWinbutton1)
                p := str_Ptr(outbufstring);
                char := str_GetByte(p);
                to(tempString);
                print([CHR] char);
                while(char != 3)
                char := str_GetByte(p);
                if(char == 2)
                to(APPEND);
                print("2,");
                else
                to(APPEND);
                print([CHR] char);
                endif
                p++;
                wend
                to (COM2); print([STR] tempString);
                n:=sizeof(combuf1);
                while(n--)combuf1[n]:=0;
                n:=sizeof(outbufstring);
                while(n--)outbufstring [n]:=0;
                com1_Init(combuf1,40,0) ;

                endif



                Best regards

                Paul

                Comment


                • #23
                  Works fine

                  Thanks a lot , Paul

                  Comment


                  • #24
                    Hi Paul,

                    me again. I added some code to expand the function.

                    Reading Tag ID on COM1->
                    when winButton pressed:
                    1. add diggit to Tag ID and send to Server on COM2
                    2. disable Touch, switch to Form1 with Confimation gif and start 3sec timer->
                    Switch to Form2 with hold your key in front of the reader gif and set contrast to 8 after 10sec.
                    Works fine.

                    When holding Tag in front of the Reader and Tag ID is read on COM1 ->switch to Form0, enable Touch and set contrast to 15.
                    I put this code in the MainLoop but it seems that in this case touch_Set(TOUCH_ENABLE); gfx_Contrast (15); andWriteObject(tForm, 0, 0) ;
                    are executed as many times as number of characters in buffer.

                    How to execute only once?

                    Best Regards
                    Doms


                    In PreGenieInit
                    sys_SetTimerEvent(TIMER0,gebucht);


                    In MainLoop
                    rec := serin1();
                    if (rec>0)
                    touch_Set(TOUCH_ENABLE);
                    gfx_Contrast (15);
                    WriteObject(tForm, 0, 0) ;
                    endif


                    In Magic Event
                    func gebucht()
                    WriteObject(tForm, 2, 0) ;
                    pause (10000) ;
                    gfx_Contrast (8);
                    endfunc


                    In MagicTouch
                    if(ImageTouched == iWinbutton0)
                    to(outbufstring) ; print([ STR] combuf1);
                    p := str_Ptr(outbufstring);
                    char := str_GetByte(p);
                    to(tempString); print([CHR] char);
                    while(char != 3)
                    char := str_GetByte(p);
                    if(char == 2)
                    to(APPEND); print("01");
                    else
                    to(APPEND); print([CHR] char);
                    endif
                    p++;
                    wend
                    to (COM2); print([STR] tempString);
                    n:=sizeof(combuf1);
                    while(n--)combuf1[n]:=0;
                    n:=sizeof(outbufstring);
                    while(n--)outbufstring [n]:=0;
                    n:=sizeof(tempString);
                    while(n--)tempString [n]:=0;
                    com1_Init(combuf1,30,0) ;
                    touch_Set(TOUCH_DISABLE) ;
                    WriteObject(tForm, 1, 0) ;
                    sys_SetTimer(TIMER0,3000);

                    else if (ImageTouched == iWinbutton1)
                    to(outbufstring) ; print([ STR] combuf1);
                    p := str_Ptr(outbufstring);
                    char := str_GetByte(p);
                    to(tempString); print([CHR] char);
                    while(char != 3)
                    char := str_GetByte(p);
                    if(char == 2)
                    to(APPEND); print("02");
                    else
                    to(APPEND); print([CHR] char);
                    endif
                    p++;
                    wend
                    to (COM2); print([STR] tempString);
                    n:=sizeof(combuf1);
                    while(n--)combuf1[n]:=0;
                    n:=sizeof(outbufstring);
                    while(n--)outbufstring [n]:=0;
                    n:=sizeof(tempString);
                    while(n--)tempString [n]:=0;
                    com1_Init(combuf1,30,0) ;
                    touch_Set(TOUCH_DISABLE) ;
                    WriteObject(tForm, 1, 0) ;
                    sys_SetTimer(TIMER0,3000);

                    endif

                    Comment


                    • #25
                      Hi,

                      You could set a flag when this has been entered, eg a global var called busy,

                      var busy;

                      In MainLoop
                      rec := serin1();
                      if (rec>0 && busy == 0)
                      busy := 1;
                      touch_Set(TOUCH_ENABLE);
                      gfx_Contrast (15);
                      WriteObject(tForm, 0, 0) ;
                      endif

                      And then when the tag has been read completely or if the buffer is empty you can set the flag busy to 0 eg,

                      busy := 0;

                      I hope this helps

                      Best regards

                      Paul

                      Comment


                      • #26
                        Thanks a lot Paul

                        Best Regards
                        Doms

                        Comment

                        Working...
                        X