Writing to a SD Card Help


#1

So, it seems the code I have written creates a file on the SD Card, but creates nothing in it.
My code is this:
SetCommunicationHandleValue(“file:a,/sdcard0/myfile.txt”,Test_Handle);
status=TransmitString(“Write some text!”, Test_Handle);
CloseCommunication(Test_Handle);

So, it only creates the file on the card, but there is no text in it.
I’ve also tried w instead of a, and still does the same thing.

I don’t know if it’s the SD Card format or what have you. I formatted it to FAT, if that matters.


#2

Looks like you’re missing the open command after the SetCommunicationHandleValue and before the TransmitString, something like this:

 open_status = OpenOutgoingCommunication( Test_Handle );

Don’t forget to check the return codes, like your status after your TransmitString executed was probably -52 meaning “not open yet.” The return values are usually pretty handy when troubleshooting comm handle code.

I’m making some assumptions here, like didn’t have that open somewhere else, but I can’t explain how the empty file got there unless it was leftover from something else? In any case, if you’re still having trouble, let us know your firmware version, etc. and we’ll get it sorted out for you.


#3

Oh, I did have that OpenOutgoingCommunication ( Test_Handle) code, I forgot to type it in the post, sorry.
Okay, so checking status codes after running the strategy file, status for the OpenOutgoingCommunication returns 0, so that means it’s fine, and I guess that’s why it created the myfile.txt file? However, status for TransmitString is -11, could not send data. So makes sense that it didn’t write the text now. Also, when I ftp.exe into it, I can’t delete the file because it says 550 DELE action not taken. Does that have something to do with communication with the opto22?

My firmware version is 9.3e, and loader r6.0b

Thanks


#4

I get that 550 DELE error if I try to delete the file while it’s still open in the strategy.

You might get that -11 error in your strategy if the file is open somewhere else? Maybe try a different filename so you know nothing else is accessing it while you try to append to it?


#5

I tried myfile2 instead, and it creates myfile2…but now I get errors -417 for OpenOutgoing and -52 for the TransmitString. If I stop the strategy and run the strategy again, I get 0 and -11. Don’t exactly know what’s going on. I can’t find what -417 means.


#6

The Command Help for the open command lists possible errors, but you should also check out this video:

//youtu.be/39KGOHJnxFE

In the meantime, -417 just means “Cannot open file.” Still sounds like you might have more than one thing (maybe your ftp client?) trying to access the file at the same time? Have you called/emailed support@opto22.com on this one?