OptoBlog

OptoNews Tip: The useful Send Communication Handle Command

Posted by Jean Femia on Oct 12, 2016 3:09:19 PM

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:

Opto 22 PAC Control flowchart block instructions to delete a file

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:

Read more on comm handles

Topics: Tips, optonews, PAC Control, OptoNews 2016-10-12

Written by Jean Femia

Jean Femia writes about technical subjects and has focused on automation and control systems for more than 15 years. She likes learning about technology and taking corners in her Honda S2000.
Find me on:

    Subscribe to Email Updates

    Recent Posts

    Posts by Topic

    see all