Serial V1.2 CTSHandshaking

Discussion in 'Questions (Windows Mobile)' started by mattsaintdev, May 5, 2009.

  1. mattsaintdev

    mattsaintdev Member Licensed User

    Hi im using the serial port to poll a RFID reader on the rs232 port of the pda.
    The RDIF reader uses the CTS to indicate its ready status. I noticed in my code that i had not set CTSHandshaking to TRUE which explained the varied results i was getting. However, when i enabled this feature all i get is an exception when i try to transmit any data;

    my serial setup code is;
    If serial.PortOpen = False Then
    serial.CommPort = 1
    serial.StopBits = 17
    serial.dataBits = 8
    serial.BitRate = 9600
    serial.Parity="N"
    Serial.Timeout = 220
    serial.PortOpen = True
    serial.EnableOnComm = False
    serial.XonXoffHandshaking = False
    serial.CTSHandshaking = True
    Sleep(500)
    End If


    then on a timer to poll for RFID tags i send a byte, wait for the RFID to work and then read back the data

    If serial.CTS = False Then
    serial.Output( "U" ) ' !!! EXCEPTION HERE !!!
    ''
    Sleep(100)
    '' wait for 8 bytes of data
    cnt=serial.InBufferCount
    timeout=120
    Do While (cnt<8) AND (timeout>0)
    cnt=serial.InBufferCount
    timeout=timeout-1
    Sleep(1)
    Loop
    '' process the 8 bytes etc ....
    End If



    If i dont set CTSHandshaking to true it all works - well without propper device timing.


    Any thoughts / help appreciated !
     
  2. agraham

    agraham Expert Licensed User

    I assume you mean the Serial2 library. You don't say what the exception message is which might help :(

    If your reader only uses CTS as an indicator that it is ready then you probably don't want CTShandshaking at all as this is not proper handshaking which involves RTS/CTS interaction in both directions.

    If your code really does look like this

    If serial.CTS = False Then
    serial.Output( "U" ) ' !!! EXCEPTION HERE !!!

    Then I suspect you are getting a timeout exception because the serial port won't send the data when CTShandshaking if CTS is not asserted which appears to be the condition you are checking for :confused:
     
  3. Zenerdiode

    Zenerdiode Active Member Licensed User

    You're going to have to elaborate a little more as to how your RFID device works. :(

    Do you have to ask it to prepare to read the RFID chip?
    If so, how do you do this?
    Raise RTS?
    Send a control byte/string?

    If you read the RFID chip and the data is there, does it wait for RTS to be asserted and then raise its CTS and send data?
    If so, you may have to use RTS/CTS handshaking.

    Does it raise CTS and then just transmit its data anyway?
    If so, use a Serial_OnCom event sub and ignore the fact that CTS is asserted.

    Does it raise CTS, when data is ready, wait until RTS is raised by you then transmit its data?
    If so, use Agraham's SerialEx library (although did you alude to this with your Serial V1.2 title?) and use the SerialEx_OnPinChanged event, look for OnPinChangedReason=1 (CTS Changed) check it has been asserted and then raise RTS or whatever and capture the returned string.

    Code:
    serial.StopBits = [COLOR="Red"]17[/COLOR]
    I hope this was a typo :)
     
  4. mattsaintdev

    mattsaintdev Member Licensed User

    More Info

    Hi thanks for the two replies;

    yes its Serial2 lib.

    The execption generated is not displayed on screen, just an error message about a missing file (that contains the error message definition). No numeric is provided.

    The docs say that the RFID controller drops the CTS to indicate its ready for a command (from the PDA) then after 10ms will raise it again to indicate its busy e.g. pushing power to any RFID cards etc. So i get a 10ms window. Th e window extends itself ifi sart sending data.

    I dont have to do anything with the RTS line as its not connected to the device.

    I can communicate with the RFID controller without the CTS handshaking, its just it would be more smooth doing it properly.


    Ill have a go with the serialEx lib and give it a bit more thought..
     
  5. agraham

    agraham Expert Licensed User

    I don't understand what you mean by "properly". As your controller doesn't support it CTSHandshaking is just not relevant here.

    That window of 10mS is terribly short, is it really that short? That is one character time at 9600 bauds so basically you have only 9mS to get the first character out. I assume that the controller does this repeatedly so your code should deal with the possibility that when you see CTS do down and transmit to the controller you might not get a response because it could have missed it.

    You could try using the SerialEx OnPinChanged event but even then you may miss the controllers' window as Basic4ppc events are not interrupts but are messages on the applications' message loop to run the required event code on the main thread.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice