wwatson4506 / UsbMscFat

Teensy 36/40/41 Compatiblility Layer for MSC and SdFat
MIT License
10 stars 4 forks source link

MSC.Open don't return error if first write is ok (key Plug) and key is unplug (T3.6) #11

Closed BOBILLIER closed 3 years ago

BOBILLIER commented 3 years ago

Hi wwatson If you start my test program with one plugged and then remove it and try to write some datas on key, MSC.Open correctly return an error in the open process. But if you plug key again, write data, unplug the key and write data again, MSC.Open don't return an error. Is it like if one write is OK , Msc.Open stay always OK. (in my test program, just use 'w' in consol to test write cycle) (you can use 'c' in consol to see if the key is ready or not and with the problem above, you can see that mscontroller return good information) It will be good if you can add something like MSC.available() or MSC.ready() in your library. I have add my own function (Is Connected() and IsInitialized())in my test program but it's not so clean than in the library. Essai_init_USB.zip

wwatson4506 commented 3 years ago

BOBILLIER,

Please check out a modified version of your sketch. I added two things to it and added comments to explain what you were missing in the sketch to check for an attached USB drive. The function 'msDrive1.checkConnectedInitialized()' checks for a USB drive being connected and if it is, it checks for it being initialized. If it is connected and not initialized it will try to initialize it. If it is not connected or not ready for use it will return one of two error codes.

Not Connected will return error code 'MS_NO_MEDIA_ERR' which = 0x28 or 'MS_UNIT_NOT_READY' which = 0x23.

Secondly, I added an int variable 'bw' so when you do the write to the file SdFat will return the number of bytes written to the file or a negative number if it failed. These are two ways to check for failures. Hope this helps you:) See modified zip file below...

Essai_init_USB_test_connect.zip

BOBILLIER commented 3 years ago

Thank wwatson That solves my issue. Last question of topic. Do you think than your library can work with teensy threading of ftrias https://github.com/ftrias/TeensyThreads ?

wwatson4506 commented 3 years ago

BOBILLIER,

Glad it worked for you. I have not tried anything like that yet. Not sure if it is thread safe.