SoftPAC Creating a Log File

I want to create a log file for certain events. I have read about when using an actual controller, but in SoftPAC what do I use for the Initial Value for my Comm Handle? If I was using a controller and an sd card I would use this: “file:a,/sdcard0/LogFile.txt”. How can I do the exact same thing using SoftPAC?

Thanks,
Dan

See this post: File Parsing example - SuperTrend - #28 by mstjohn

Thank you. Works perfect.

What do I use in my comm handle to delete a file on my sdcard?.. /sdcard0/LogFile.txt …file:/sdcard0/LogFile.txt I can’t find it in the manual.

See the “Send Communication Handle Command” command. It has a delete command.

Edit: You can also overwrite an existing file if you open it with “w” instead of “a”.

I am trying to use the SendCommunicationHandleCommand(chFile, “delete”); hmm, maybe I don’t need to OpenOutgoingCommunication before I use that command? Yes, it says I have to open it first. …So I need the string for my CommHandle. I’ve tried file:/sdcard0/LogFile.txt and just /sdcard0/LogFile.txt

Have you tried file:r,/sdcard0/LogFile.txt?

When the SendCommunicationHandleCommand(chFile, “delete”) command doesn’t work, check what you get as the status code, maybe that will provide a hint to what is going on.

Success… file:r,/sdcard0/LogFile.txt was the correct answer. I’m simply creating a log of daily events and then emailing that file at the end of the day or when an operator requests the data.

This would work as well without using the SendCommunicationHandleCommand(chFile, “delete”) command.

Thank you

Few more questions… Is there harm in leaving the Comm Handle (CH) open all the time and append to the file all day? Or is it best to open it and close it every time? What is the execution time of opening and closing this type of CH? What effect does it have on the performance of the system if I left it open indefinitely? Will the controller close the CH after a certain amount of time? What happens to the CH/controller/file when the CH is open and I download an update for the strategy? When power is lost with the CH open, does anything happen to the file I’m appending (in my case)? What happens to the CH/file when switching from Run to Stop if it is in the middle of appending the file? …not in a critical situation here, but I’m curious.

Check to see if sdcard is present? If someone removes the card during CH open or appending a file? Eject card button to safely remove it?

For those of you following along, some answers to @Drenton’s excellent questions, from our awesome support team:

  1. Is there harm in leaving the Comm Handle (CH) open all the time and append to the file all day? Or is it best to open it and close it every time?

The biggest possible harm would be corruption to the file, since its file descriptor may not be fully updated until the file is closed. You probably wouldn’t see that happen often, and might not ever see it, but it’s worth mentioning.

  1. What is the execution time of opening and closing this type of CH?

We have not benchmarked this and it could be affected by what the comm handle is to. For example, if accessing files on a microSD card, the more files you have, the longer it takes to access them. We recommend keeping less than 1000 files in each folder.

  1. What effect does it have on the performance of the system if I left it open indefinitely?

None.

  1. Will the controller close the CH after a certain amount of time?

No; the only thing other than a CLOSE command that would close the handle is a critical error.

  1. What happens to the CH/controller/file when the CH is open and I download an update for the strategy?

Before the new strategy is downloaded, the existing strategy is stopped, which cleanly closes any open handles.

  1. When power is lost with the CH open, does anything happen to the file I’m appending (in my case)?

It could be corrupted, as mentioned in #1.

  1. What happens to the CH/file when switching from Run to Stop if it is in the middle of appending the file? …not in a critical situation here, but I’m curious.

Same as #5; whenever the strategy is stopped, all open handles are cleanly closed.

  1. Check to see if sdcard is present?

Programmatically, the only way to check would be to try to list the uSD directory; if the card isn’t in, you should get an error.

  1. If someone removes the card during CH open or appending a file?

Possible file corruption

  1. Eject card button to safely remove it?

The STAT LED blinks rapidly whenever the card is being read or written. Wait until the LED stops blinking, which means uSD activity is complete, before removing the card.

Keep those good questions coming!
Thanks,
OptoMary

1 Like