Shop OBEX P1 Docs P2 Docs Learn Events
Memory Stick Datalogger Demo V1.0 — Parallax Forums

Memory Stick Datalogger Demo V1.0

marcfmarcf Posts: 6
edited 2009-11-12 01:54 in BASIC Stamp
Hello:

I am trying to see how and where the VAR 'flag' gets set to 0 in the Subroutine 'Check_Drive' in DataLoggerDemoV1.0.bs2.

This is probably a "RTxM" problem on my part, but any help would be good.

Thanks.

Marc

Comments

  • skylightskylight Posts: 1,915
    edited 2009-11-10 19:06
    If a certain state is reached then the Var flag is set to 1, as this is called the event status flag perhaps this flag is automatically reset by the device after the event and is set to 1 once again when the flag=1 statement is reached again?

    this happens with the pink device once the status var is read so i presume the same happens with this one too?
  • marcfmarcf Posts: 6
    edited 2009-11-10 19:38
    Hello:

    Thanks for the reply.

    It looks like 'VAR flag' i s set to 0 by the device during the subroutine 'Get_Data'
    and is used to determine a "Connected" condition.

    Buffer(0) = "D", Buffer(1) = "D" and flag = 0

    I would just like to know how this is done.

    It seems to me that a valid response for a "Connected" condition would be if
    Buffer(0) = ">" and Buffer(1) = "0"

    Thanks

    marc
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-11-11 02:04
    Hi Marc , the sub routine Check_Drive is a loop looking for a series of events.
    A successful series of events·( or at least the beginning and the end of those events·) when a flash drive is plugged in is

    1. the logger transmits "DD"·
    2. then there is a little more activity which is ignored by the Stamp
    3. finally the logger transmits ">"

    The Check_Drive loop will detect the device ("DD") when it is plugged in and keep looping until it receives the ">" character .
    In the process of detecting the drive the program assigned buffer(0) the value "D" and buffer(1) a value of "D".
    Immediately following that line flag is set to 1 , the reason is so that·subsequent Check_Drive loops will now ignore the lines.

    ELSEIF buffer(0) = "D" AND buffer(1) = "D" AND flag = 0 THEN
          DEBUG "Connected!", CR, "Accessing..."
          flag = 1                          ' Memory Stick Ready
    

    because until told otherwise buffer (0) and (1) will still contain "DD"

    It may or may not be crucial in this instance but is a good example of setting a "flag" to control program flow.

    Jeff T.
  • marcfmarcf Posts: 6
    edited 2009-11-11 04:38
    Unsoundcode:

    It is clear to me how 'flag' gets set to "1", but I still do not understand how 'flag' gets set to "0".

    Could you explain it to me in detail?

    Inquiring minds need to know.

    Thanks
    Marc
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-11-11 14:09
    Hi Marc

    variables are initialized to zero at program start

    Jeff T.
  • marcfmarcf Posts: 6
    edited 2009-11-12 01:54
    my bad

    I guess that I came very close to asking a stupid question.

    Thanks for your understanding.

    Marc
Sign In or Register to comment.