Announcement

Collapse
No announcement yet.

RFiD reader serial communication

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

  • Doms
    replied
    Ahhh yes, sure ... I have read gen4-uLCD-32D Datasheet several times ...... with eyes closed

    Thank you

    Leave a comment:


  • pauleilio
    replied
    Hi,

    Yes you will have to change COM1 to another set of pins, PA12 & PA13 are used by the capacitive touch controller on a DCT display. You don't seem to have another pins set for anything else so you should be good to use pins lower than 12.

    I hope this helps

    Best regards

    Paul

    Leave a comment:


  • Doms
    replied
    Hi Paul

    i added some code to expand the function and make an Intro with rotating gears.
    Works fine on Gen4-uLCD-32DT.
    Bought Gen4-uLCD-32DCT-CLB, change Display Typ in Projekt settings and Build Copy/load.
    Works till intro is finished. When reading RFiD Tag it seems COM1 doesn't work, Buffer is empty..
    Is there anything to change in the code for using Gen4-uLCD-32DCT-CLB?

    Best Regards
    Doms


    In PreGenieInit:
    COM1_RX_pin(PA13) ;
    COM1_TX_pin(PA12) ;
    COM2_RX_pin(PA6) ;
    COM2_TX_pin(PA7) ;
    com_SetBaud(COM1, 960) ;
    com_SetBaud(COM2, 960) ;
    com1_Init(combuf1,18,0) ;
    serin1() ;
    serout2(rec);
    com1_Count() ;
    com1_Full () ;
    com1_Error() ;
    com2_Error() ;
    sys_SetTimerEvent(TIMER0,gebucht);
    sys_SetTimerEvent(TIMER1,dimm);
    sys_SetTimerEvent(TIMER2,intro);
    sys_SetTimerEvent(TIMER3,timeout);

    In PostGenieInit
    WriteObject(tForm, 3, 0) ;
    sys_SetTimer(TIMER2,100) ;
    busy := 1;

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

    In PreActivateForm
    abpos := 0 ;

    In Constant/Global/Data
    var port1 ;
    var port2 ;
    var char ;
    var bufnum ;
    var combuf1[10] ;
    var outbufstring[10] ;
    var outbufPtr ;
    var cero1 ;
    var cero2 ;
    var n ;
    var rec ;
    var p;
    var tempString[10];
    var busy;
    var abpos ;

    func intro()

    if (abpos == 9)
    pause(1500) ;
    abpos++ ;
    sys_SetTimer(TIMER2,100) ;
    else if (abpos == 30)
    pause(3000) ;
    ActivateForm(2) ;
    busy := 0;
    sys_SetTimer(TIMER2,0) ;
    else
    abpos++ ;
    sys_SetTimer(TIMER2,100) ;
    endif


    img_SetWord(hndl, iUserbutton0, IMAGE_INDEX, abpos);
    img_Show(hndl, iUserbutton0) ;
    sys_SetTimer(TIMER1,10000);
    endfunc


    func busyflag()
    n:=sizeof(outbufstring);
    while(n--)outbufstring [n]:=0;
    (tempString);
    (n--)tempString [n]:=0;
    sys_SetTimer(TIMER3,0) ;
    WriteObject(tForm, 1, 0) ;
    sys_SetTimer(TIMER0,2500);
    touch_Set(TOUCH_DISABLE) ;
    busy := 1;
    endfunc

    In MagicEvent0
    func gebucht()
    WriteObject(tForm, 2, 0) ;
    sys_SetTimer(TIMER1,10000);
    busy := 0;
    sys_SetTimer(TIMER0,0) ;
    endfunc

    func dimm()
    gfx_Contrast (8);
    sys_SetTimer(TIMER0,0) ;
    sys_SetTimer(TIMER1,0) ;
    sys_SetTimer(TIMER2,0);
    endfunc

    func timeout()
    gebucht();
    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);
    busyflag() ;

    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);
    busyflag() ;

    else if (ImageTouched == iWinbutton2)
    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("03");
    else
    to(APPEND); print([CHR] char);
    endif
    p++;
    wend
    to (COM2); print([STR] tempString);
    busyflag() ;

    else if (ImageTouched == iWinbutton3)
    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("04");
    else
    to(APPEND); print([CHR] char);
    endif
    p++;
    wend
    to (COM2); print([STR] tempString);
    busyflag();

    else if (ImageTouched == iWinbutton4)
    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("05");
    else
    to(APPEND); print([CHR] char);
    endif
    p++;
    wend
    to (COM2); print([STR] tempString);
    busyflag();
    endif

    Leave a comment:


  • Doms
    replied
    Thanks a lot Paul

    Best Regards
    Doms

    Leave a comment:


  • pauleilio
    replied
    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

    Leave a comment:


  • Doms
    replied
    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

    Leave a comment:


  • Doms
    replied
    Works fine

    Thanks a lot , Paul

    Leave a comment:


  • pauleilio
    replied
    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

    Leave a comment:


  • Doms
    replied
    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

    Leave a comment:


  • pauleilio
    replied
    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

    Leave a comment:


  • Doms
    replied
    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

    Leave a comment:


  • pauleilio
    replied
    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

    Leave a comment:


  • Doms
    replied
    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

    Leave a comment:


  • pauleilio
    replied
    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

    Leave a comment:


  • Doms
    replied
    Hi Paul,

    could solve the problem witk lost A.
    Now i've added two Winbutton and try following process:
    Scan Tag ID on Reader connected to COM1-> works
    Add ",1" to Tag ID and output all on COM2 when WinButton0 touched or add ",2" to Tag ID and output all on COM2 when WinButton1 touched -> doesn't work.

    I can output Tag ID to COM2 when WinButton touched but don't know how to add values to Tag ID..

    Best Regards

    Doms

    In Constant/Global/Data
    var port1 ;
    var port2 ;
    var char ;
    var bufnum ;
    var combuf1[20] ;
    var outbufstring[30] ;
    var cero1 ;
    var cero2 ;
    var n ;

    In PreGenieInit:
    COM1_RX_pin(PA13) ;
    COM1_TX_pin(PA12) ;
    COM2_RX_pin(PA6) ;
    COM2_TX_pin(PA7) ;
    com_SetBaud(COM1, 1920) ;
    com_SetBaud(COM2, 1920) ;
    com1_Init(combuf1,20,0) ;
    serin1() ;
    com1_Count() ;
    com1_Error() ;
    com2_Error() ;

    In MainLoop:
    cero1 := com1_Error() ;
    gfx_MoveTo(0,0);
    if (cero1)
    print("COM1 ERROR:", cero1, " ") ;
    endif

    cero2 := com1_Error() ;
    gfx_MoveTo(0,20);
    if (cero2)
    print("COM1 ERROR:", cero2, " ") ;
    endif

    gfx_MoveTo(0,40);
    port1 := com_SetBaud(COM1, 1920) ;
    if (port1)
    print("COM1 set to: ",port1, " ");
    endif

    gfx_MoveTo(0,60);
    port2 := com_SetBaud(COM1, 1920) ;
    if (port2)
    print("COM2 set to: ",port2, " ");
    endif

    gfx_MoveTo(0,80) ;
    bufnum := com1_Count();
    if (bufnum >= 0)
    print("In Buffer: ", bufnum, " ");
    endif


    gfx_MoveTo(0,100) ;
    char := serin1();
    if (char)
    print("char: ", char, " ");
    endif

    In MagicTouch
    if (ImageTouched == iWinbutton0)
    to(outbufstring) ; putch (char);
    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 (",2");
    to (COM2); print([STR] outbufstring);
    n:=sizeof(combuf1);
    while(n--)combuf1[n]:=0;
    n:=sizeof(outbufstring);
    while(n--)outbufstring [n]:=0;

    endif

    Leave a comment:

Working...
X