Shop OBEX P1 Docs P2 Docs Learn Events
USB Mem stick datalogger w/BS2, upgraded firmware, initialization question — Parallax Forums

USB Mem stick datalogger w/BS2, upgraded firmware, initialization question

xanatosxanatos Posts: 1,120
edited 2011-10-26 16:17 in BASIC Stamp
Hi again,

I have a memory stick data logger attached to my BS2sx. I have used the Vinculum Firmware Modifier to change the startup settings to 4800, IPA, SCS and removed the "Show Version" option. The datalogger initializes fine apparently as it delivers the ">" on a power cycle. However - the program hangs whenever I attempt to write to the data logger. Here's the relevent code:
Init_Dlogger:
  SEROUT LCD, LcdBaud, [LcdCls]
  PAUSE 5
  SEROUT LCD, LcdBaud, ["Initializing    "]
  LOW DLTX
  SERIN DLRX, 500,[WAIT(">")]
  PAUSE 20
  SEROUT LCD, LcdBaud, [LcdCls]
  PAUSE 5
  SEROUT LCD, LcdBaud, ["Initialized     "]
  PAUSE 400


'----[subroutines]--------------------------------------------

OPEN_WRITE_CLOSE:
  SEROUT DLTX, DBaud,[$9, $20, "FMlog.csv", CR]  ' Open file
  SERIN DLRX, DBaud,[WAIT (">")]

  SEROUT DLTX, DBaud, [$8,$20,$0,$0,$0,$25,CR,DI, ",", TRN, ",", TRKMLG, ",", GDL, ",", HEX2 month, "/", HEX2 date, "/", HEX2 year, " ", HEX2 hrs, ":", HEX2 mins, ":", HEX2 secs,CR,$0A]  ' 6th code is write size - this example, 24 (36 characters incl. CR & LFs: DI,TR#,TRKMLG,GDL,YY/MM/DD HH:MM
  SERIN DLRX, DBaud,[WAIT (">")]

  SEROUT DLTX, DBaud,[$0A, $20, "FMlog.csv", CR] ' Close file
  SERIN DLRX, DBaud,[WAIT (">")]
RETURN
  

Note that the values in the write line itself are properly sized and existent (times, etc are all incoming from a DS1302 and everything worked prior to the change of the initialization.

Using DEBUGS I am able to determine that the program is hanging at the point where it is waiting for the ">" after the line to open the file:

SEROUT DLTX, DBaud,[$9, $20, "FMlog.csv", CR] ' Open file
SERIN DLRX, DBaud,[WAIT (">")]

It apparently never gives the ">" at that point. But it does in the initialization routine:

SERIN DLRX, 500,[WAIT(">")]
PAUSE 20
SEROUT LCD, LcdBaud, [LcdCls]
PAUSE 5
SEROUT LCD, LcdBaud, ["Initialized "]

Can anyone suggest what I need to do differently, now that I have firmware-changed the initialization routine, to write to the datafile on the USB stick?

Thanks very much,

Dave

PS., While much of this was covered in a 2009 thread, http://forums.parallax.com/showthread.php?114218-Datalogger-writing-requirement-question - I never actually needed this code until now. Hence this issue was never discovered until now. The 2009 project had it's parameters changed. This is a new project that is revisiting the USB Datalogger, and the need for it to power cycle to a known state, hence the firmware edit. Now I just need it to take a write again! :-)

Comments

  • xanatosxanatos Posts: 1,120
    edited 2011-10-20 11:56
    UPDATE:

    In the place of the code where I was waiting for ">", I replaced that line with a SERIN for a variable to see what, if anything, the datalogger was returning when I attempted to open the file for writing. The response captured is:

    charHold = 66 (this is the DEC of the captured value)
    charHold = $42 (HEX)
    charHold = "
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-10-20 17:31
    Hi Dave, decimal 66 is the code value for ASCII "B", if you were to capture a second character I would guess it would be 67 (ASCII character "C") .

    "BC" in short command set is an abreviation of Bad Command, your test code seems to be ok so I would say the drive is not initialized completely or the baud rate is wrong.

    I ran the following with a datalogger configuration of IPA,4800 with no version report. I powered up the hardware with the thumbdrive removed from the logger, I downloaded the example and then inserted the thumbdrive. The file was written to the flash. Give it a try and see if it will complete for you.
    TX CON 0          'P0 assigned TO SEROUT
    RX CON 1          'P1 assigned TO SERIN
    Baud CON 500      'A baud rate of 4800
    
    SERIN RX, Baud,[WAIT ("DD")]
    DEBUG CLS, "Device Detected Please Wait...", CR
    SERIN RX,baud,[WAIT(">")]
    SEROUT TX, Baud,[$9,$20,"FMLOG.csv",CR]
    SERIN RX, Baud,[WAIT (">")]
    DEBUG "File open", CR
    SEROUT TX, Baud,[$0A,$20,"FMLOG.csv",CR]
    SERIN RX, Baud,[WAIT (">")]
    DEBUG "File closed", CR
    

    Jeff T.
  • xanatosxanatos Posts: 1,120
    edited 2011-10-22 17:50
    Maybe this is where I am having the issue. I am *trying* to be able to initialize the drive without having to remove it - my reason being that if there's ever a power failure, it would be a non-starter to have to have the users remove and reinsert the drive, or to have to have the site administrator have to run out to the box to remove & reinsert the memory stick.

    I'm actually trying to tie up several parts of the same program at once at the moment, so I may be a bit slow in coming back to one of the issues... :-)

    Currently when I power up the system with the Memory Stick inserted with my code, it does at least say that it is initialized (it reports Initialized once it receives the ">" that it waits for on power up.) So if I'm getting the ">"... I guess I'm confused as to why it won't respond after that. I need to initialize the drive and have it take a write command without having to remove and re-insert the drive...

    More tomorrow... thanks for your assistance so far. Let me know what ideas you may come up with regarding a stationary initialization.

    Best,

    Dave
  • xanatosxanatos Posts: 1,120
    edited 2011-10-23 14:30
    OK... part of the problem solved. I still had the LOW DLTX part of the original initialization in place. I had read that you needed to do that to force the device to output that initial > - but by removing that line, it can now open and close the file just fine. It just can't write to it.

    So... Here's my write line:

    SEROUT DLTX, DBaud, [$8,$20,$0,$0,$0,$24,CR, DEC2 DI, ",", DEC3 TRN, ",", DEC4 TRKMLG, ",", DEC3 GDL, ",", HEX2 month, "/", HEX2 date, "/", HEX2 year, " ", HEX2 hrs, ":", HEX2 mins, ":", HEX2 secs,CR,$0A]

    I know these things are picky as all heck when it comes to being told the exact size of the string coming at them. As I understand it. the 6th code is write size - this example, $24 (36 characters incl. commas, spaces, CR & LFs: DI,TR#,TRKMLG,GDL,YY/MM/DD HH:MM

    But it hangs on the write.

    Here's what is actually being written to the datalogger:

    C54,064,9768,035,10/23/11 16:50:20CL

    The leading C is the CR after the $24 in front of the data string, and the trailing CL represents the CR & $0A at the end of the data string.

    Now I count 36 characters. Which is $24.

    But just for the heck of it, I have tried $20 through $28, with the same results. It'll open the file, but hangs on write.

    Stay tuned for updates... I'm still up to my neck in it...

    Dave
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-10-23 15:20
    Hi Dave, your modified program ran, displayed all the Debug statements and created a file on the thumbdrive. The only difference code wise was the baud, I am using a standard BS2 for testing, lets look at the configuration file.

    The configuration file I am using is named FTRFB.ftd and these are the settings

    UART = 4800, 8 data bits, 1 stop bit, no parity, CTS/RTS flow control

    Initialization = Input mode IPA , Command mode Short Command Set , Led's flash at power on

    Firmware options = there are two boxes checked :- Show Prompt and Show Device Connects/Removals

    Check that your configuration matches.

    It may also be looking for an upgrade, just for a test try a PAUSE 20000 right after DEBUG "> Received", CR. A twenty second delay should be enough for the upgrade check to clear if it were present.

    Jeff T.

    EDIT : Our posts crossed Dave, great news, your moving forward.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-10-23 15:35
    Try this Dave

    SEROUT DLTX, DBaud, [$8,$20,$0,$0,$0,DEC 35,CR, DEC2 DI, ",", DEC3 TRN, ",", DEC4 TRKMLG, ",", DEC3 GDL, ",", HEX2 month, "/", HEX2 date, "/", HEX2 year, " ", HEX2 hrs, ":", HEX2 mins, ":", HEX2 secs,CR,$0A]

    let me know if it makes a difference

    Jeff T.
  • xanatosxanatos Posts: 1,120
    edited 2011-10-23 15:47
    WooHoo! I've got it working - turns out (apparently) there is a data limit of how much you can send in one line... max 15 characters ($0F). I broke the data line into three parts, put the CR,$0A only on the last line, and it's happily writing the full line to the USB stick..

    So I now have a USB stick that starts in a known state, doesn't require extensive gyrations from the operator any time a power cycle occurs or the admin guy needs to remove and copy the data on the USB stick, and that writes all my data in csv spreadsheet form.

    I am a happy camper! :-)

    Thanks everyone for lending me your thoughts and being willing to help on this!

    Dave
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-10-23 15:57
    Dave, the loggers buffer is larger than 15, you should be able to write your string in one go.

    Jeff T.
  • xanatosxanatos Posts: 1,120
    edited 2011-10-23 17:26
    Well... no answer there. When I try with one shot - it hangs. Keep each line 15 or under, writes like a champ. So it's working - and well - but if there's something going on I can fix further - I'm utterly open to the idea... as long as I can find out what it is...

    Dave

    PS,. Just FYI - I actually tried with 16 - hangs. Won't write. 15 is good, 16 hangs. How odd is that?
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-10-24 18:23
    Yes it is odd Dave, there are a few oddities about the logger and the firmware documents are not as concise as they could be.

    I think in this case the input mode is making the difference.

    With input mode set to IPA then the data size should be written as ASCII
    SEROUT DLTX, DBaud, [$8,$20,DEC 35,CR........................
    

    With input mode set to IPH then the data size should be written as a HEX value
    SEROUT DLTX, DBaud, [$8,$20,$0,$0,$0,$23,CR.................
    


    Jeff T.
  • xanatosxanatos Posts: 1,120
    edited 2011-10-24 18:40
    Cool thinking... I'm not near my dev system but I'll try that tomorrow... That would be nice!

    Thanks,

    Dave
  • xanatosxanatos Posts: 1,120
    edited 2011-10-26 16:17
    Hi Jeff,

    You're right on the money! I changed the hex values to DEC values and I can write the whole line in one shot.

    Thanks very much! These dataloggers do have some quirks... but slowly we're getting them all documented up here. The thing works fantastically well now - completely unattended operation, self-initializing, silent logging. Happy camper! :-)

    Dave
Sign In or Register to comment.