The PAC Control command "Send Communication Handle Command" is a flexible and useful command to know.
It sends a command that accomplishes a specific purpose for the type of communication handle you're using. For example, you might use it with a File or FTP comm handle to work with files on a SNAP PAC controller.
But it can sometimes be a little complicated.
A recent customer question pointed that out: When you use "Send Communication Handle Command" to delete a file, how does the command know which file to delete?
Let's take a look at how you might delete a file using this command.
In this example we’ve created a communication handle variable we called ch_local_file. We could have initialized it when we created it, specifying the filename then; but this time we’ll initialize it in our flowchart.
We use the command Set Communication Handle Value for the purpose, to set the current value of the comm handle. This is where we specify the filename we want to delete. It's part of a string literal that includes:
- the type of comm handle (file)
- the open mode that opens the file for writing (w)
- the name of the file to open (in this case, MyFilenamehere)
Then we open outgoing communication, send the command to delete the file, and finally close communication.
Here's how it might look in your flowchart block:
In an OptoScript block, the logic would look something like this:
SetCommunicationHandleValue ("file:w,MyFilenamehere", ch_local_file);
n_com_stat_local_OOC = OpenOutgoingCommunication(ch_local_file);
n_com_stat_local_SCHC = SendCommunicationHandleCommand(ch_local_file,"delete");
n_com_stat_local_OOC = CloseCommunication(ch_local_file);
This Send Commmuncation Handle Command is good for many other things, too. For example, you can use it to change the timeout value of your TCP comm handle or even search for a string in a text file (it's faster than searching a string table).
For more specifics on this command (and all the PAC Control commands), see the PAC Control Command Reference.
For more background on communication handles, see:
- PAC Control 101: Communication Handles on the OptoForum
- "Communication Commands" in Chapter 10 of the PAC Control User's Guide, which includes specifics on types of comm handles, open modes, and so on