Reading text from the datalogger
aladas
Posts: 18
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.
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
' 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
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.
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?