Shop OBEX P1 Docs P2 Docs Learn Events
Reading text from the datalogger — Parallax Forums

Reading text from the datalogger

aladasaladas Posts: 18
edited 2008-03-12 00:58 in BASIC Stamp
I am trying to get proper control of the datalogger and having difficulty reding from a text file. This piece of code manages to display the first word in the file, letter by letter, and then stops.
' Open textfile.TXT for input (read)
  PAUSE 200
  SEROUT TX\CTS, Baud, [noparse][[/noparse]"OPR textfile.txt", CR]
  DEBUG "Opening text file", CR

  GOSUB Get_Serial_Bytes
  FOR x = 1 TO 10
  PAUSE 120
  SEROUT TX\CTS, Baud, [noparse][[/noparse]"RDF ", $00, $00, $00, $0e, CR]
  '  Four Hex digits describe amount to read - the final 0e is 15 in hex
  SERIN RX\RTS, Baud, 500, No_Data2, [noparse][[/noparse]buffer]
  DEBUG DEC x, "text:", buffer , CR         ' Display data read from file
  NEXT
   'Close textfile.txt




Am I misusing the instructions to the logger, or SERIN? Any ideas much appeciated. I have attached the full code, which is derived from the dataloggerTest.bs2

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-11 20:16
    You need to understand the basic statements first.

    Your SERIN statement reads only a single byte and the DEBUG statement outputs only a single byte.
    For multiple bytes, have a look at the STR formatter in the chapter of the manual on the SEROUT statement.

    The command to the datalogger is basically correct except that $0e = 14 and you're only attempting to read one byte.

    You could change the command to the datalogger to request only one byte to be read. You could also use the STR
    formatter and a byte array for the buffer to read more bytes per datalogger command.
  • aladasaladas Posts: 18
    edited 2008-03-11 20:46
    Thanks - I was afraid it was something like that. I will get ny head around it in the morning.

    My longterm plan for world domination is based on a project for an autonomous sail craft of some academics in Wales, so I still have to learn how to get a decent reading from a compass, hook up to an old serial GPS unit and eventually to a cellphone. In principle one would provide the beast with a list of waypoints and actions which would include periodically coming to shore or at least within reach of the celular network, to upload its data collection. There is also the issue of solar trickle charging of batteries for all that, and trying to get the code to fit. Apart from that - nothing can stop us now. (Cackles manically)

    Here are the Welsh: http://cadair.aber.ac.uk/dspace/bitstream/2160/357/1/paper.pdf
    Many thanks - as usual - how DO you find the time or inclination to be so helpful?
  • aladasaladas Posts: 18
    edited 2008-03-12 00:58
    Mike - finally got it, much thrashing about and some surprises like the drives prompt. Maybe it would be more taciturn in hex mode.
    temp=0
      readagain:
      FOR x = 1 TO 10
      PAUSE 220
        SEROUT TX\CTS, Baud, [noparse][[/noparse]"RDF ", $00, $00, $00, $0f, CR]
        '  Four Hex digits describe amount to read - the final 0f is 15 in hex
        SERIN RX\RTS, Baud, 500, No_Data2, [noparse][[/noparse]STR buffer\15]
        FOR z = 1 TO 15       'The text I was reading was littered with Line Feeds
          IF buffer(z)=10 THEN buffer(z)=7  'If I recall this is Ctrl-G the bell, and non-printing
        NEXT
        DEBUG  STR buffer\15         ' Display data read from file
        SERIN RX\RTS, Baud, 500, No_Data2, [noparse][[/noparse]STR buffer\5]     'The prompt from the drive 
                                                                                          'D:\> plus a CR - discard it
      NEXT
      temp=temp+1
      'DEBUG " [noparse][[/noparse]",DEC temp,"] "
      IF temp < 40 THEN readagain
    
    
Sign In or Register to comment.