Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Data retrieval using Seek,Input or whatever
Author | Message | ||||
Chrisk Senior Member Joined: 21/12/2014 Location: AustraliaPosts: 112 |
Hi guys I need to be able to extract the time data from a file written to an SD card on my micromite 100. The lines I use to write the file are: open datafile$ FOR APPEND AS #1 print #1,GateCount,GateCountNow,Date$,Mid$(Time$,1,5) The data has the format 1 1 02-02-2019 20:21 2 1 04-02-2019 07:21 3 2 04-02-2019 08:07 4 3 04-02-2019 13:55 5 4 04-02-2019 17:23 6 5 04-02-2019 18:11 I will then use this time info in the LCD display to show the last 6 gate openings. I have looked at the info in the MMBasic language file but needless to say nothing I do seems to work. Any suggestions Chrisk |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3165 |
If the fields have a fixed width then INPUT$() will do it for you. Alternatively you could use LINE INPUT and pick the line apart with MID$(). Geoff Geoff Graham - http://geoffg.net |
||||
jirsoft Guru Joined: 18/09/2020 Location: Czech RepublicPosts: 532 |
Or LINE INPUT and then look with FIELD$ through spaces-separated fields... Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5882 |
I think you are looking for the last 6 lines. OPEN the file AS RANDOM (Normal AS INPUT may also work) LOF() will give you the length of the file SEEK LOF()-(22*6) will give you the start of the last 6 lines. 20 characters plus 2 bytes for crlf per line. form there you can INPUT each line. You may have to tweak the position you start reading from a little. You could also keep a count of the number of times you add an entry and that will give you the starting point if LOF() isn't suitable. It's a while since I did this in MMBasic so things might have changed a little. Jim VK7JH MMedit MMBasic Help |
||||
Chrisk Senior Member Joined: 21/12/2014 Location: AustraliaPosts: 112 |
Thanks Guys I will have a go. Chrisk |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5882 |
It would help if you can format the data to keep the line length the same when the count gets above 9 (and 99) Jim VK7JH MMedit MMBasic Help |
||||
jirsoft Guru Joined: 18/09/2020 Location: Czech RepublicPosts: 532 |
I expected missing it, so this was the reason I thought Chrisk will need LINE INPUT + FIELD$... Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
Chrisk Senior Member Joined: 21/12/2014 Location: AustraliaPosts: 112 |
Further to the above. I have these two files a gtest3.bas and the data file gtest3.txx The program works with mmbasic but when I load them into my micromite there is no data (dat$) printout. The data file consists of the date and times the gate device was triggered.The first two columns are just counters. Any ideas guys 'gtest3.bas 'Works fine using mmbasic 'Note: First 9 records must have a space preceeding the digit 'to ensure uniform bytes in field. ' cx = 24 'Characters per line plus cr + lf should be 22+2 x = 0 y = 0 open "gtest3.txx" for random as #3 ' gtest3 is data file y = LOF(#3) ' Determines number of bytes in file cb = y/cx ' Number of lines in file z = cint(cb) do i = LOF(#3) - y + (cx*x) ' Determine start of data location seek #3, i ' points to start of data location dat$ = INPUT$(cx, #3) ' now read next 24 bytes x=x+1 if x =< z then 'count number of lines read pause 100 print dat$ loop else endif print "This is the end" close #3 end 1 1 02-02-2019 20:21 2 1 04-02-2019 07:21 3 2 04-02-2019 08:07 4 3 04-02-2019 13:55 5 4 04-02-2019 17:23 6 5 04-02-2019 18:11 7 1 05-02-2019 08:21 8 1 06-02-2019 11:39 9 1 06-02-2019 15:22 10 1 07-02-2019 07:53 11 2 07-02-2019 13:06 12 3 07-02-2019 18:17 13 4 07-02-2019 22:33 14 1 07-02-2019 22:50 15 1 08-02-2019 08:21 16 2 08-02-2019 11:52 17 3 08-02-2019 16:37 18 4 08-02-2019 17:19 19 1 09-02-2019 08:10 20 2 09-02-2019 08:46 21 1 09-02-2019 19:42 22 1 10-02-2019 12:16 23 2 10-02-2019 12:22 24 1 11-02-2019 07:35 25 2 11-02-2019 07:51 26 3 11-02-2019 08:27 27 4 11-02-2019 10:43 28 5 11-02-2019 11:17 |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3008 |
Your code is somewhat hard to follow without indentation, but it appears that you have a DO loop which contains an IF, but the ELSE and ENDIF are outside the loop. Who knows what MMBasic thinks you are trying to do. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5882 |
I would allow the extra byte on each line to cater for greater than 99 records. An alternative is to go back a bit further and discard the first line you read which would be a partial line. LINE INPUT will cover lines of any length. If you want the order reversed, save them into an array then print in reverse order. Jim VK7JH MMedit MMBasic Help |
||||
Chrisk Senior Member Joined: 21/12/2014 Location: AustraliaPosts: 112 |
Hi Guys Just thought I would let you know that the problem I had with the SEEK instruction was due to MM version 5.0405. With an upgrade (heavily supported by grogster) to 5.0503 the damn thing works. Thought I would post this in case someone else has the same problem. Chrisk |
||||
Print this page |