top of page

Programming Examples:  Launching RFControl

 

The application should open RFControl with a pipe to STDOUT so it can capture the response. Note that these are code segments for demonstration of the main concept but don’t code for the possible exceptions and error returns.

 

In TCL launching RF control and capturing the port number  might look like:

 

set appname “|RFControl HEXKEY”   # note the | to open the pipe

set ahandle [open $appname]

gets $ahandle buf

lassign $buf ipname ipaddr portnum

 

In perl:

 

$appname = “RF_Control.exe HEXKEY”

open (AHANDLE, “<$appname”);  # in perl, < redirects STDOUT to us

$buf = <AHANDLE>;

($ipname, $ipaddr, $portnum) = split (“ “,$buf);

 

In c#:

Process p = new Process();

// Redirect STDOUT from RFControl to us

p.StartInfo.UseShellExecute = false;

p.StartInfo.RedirectStandardOutput = true;

p.StartInfo.FileName = "C:/Program Files (x86)/SynthMachine/RFControl.exe";

// Launch it with Hexkey it and get the first line of output from STDOUT

p.StartInfo.Arguments = Hexkey;

p.Start();            

string output = p.StandardOutput.ReadLine();

// Output will have port number in third parameter or an error message.

char[] delim = { ' ' };

string[] fields = output.Split(delim);

Int32 portnum = Convert.ToInt32(fields[2]);

 

The application would then open the TCP port using the appropriate form of socket command.  For example,

 

In TCL this would be:

 

set handle [socket “localhost” $portnum]   

gets $handle buf                                         # buf has RF control response

 

In perl this might be:

 

use scrict;

use IO::Socket;

my $handle;

 

$handle = IO::Socket::INET->new (Proto => “tcp”,

    PeerAddr = “localhost”,

    PeerPort = $portnum);

$buf  = <$handle>;

In c#:

    // the port must be opened, and a stream must also be allocated

    client = new TcpClient(“localhost”, port);

           stream = client.GetStream();

           buf = GetMessage();

 

When the connection is established, RFControl will respond via the TCP connection with:

 

SynthMachine Ready\n

 

RFControl Commands

 

Commands are sent to RFControl using the handle (or object) for the open channel.  Note that all commands must be terminated with a newline (\n).

 

RFControl recognizes the following commands:

 

    constant mode:

        rfon    - turn the RF on

        rfoff   - turn the RF off

 

    frequency scan modes:

        freqscan - start frequency scan

        freqonce - start frequency once mode.  Issue again to scan once "again"

        freqstep - start frequency step mode.  Issue again to take next step

 

    power scan modes:

        pwrscan  - start power scan

        pwronce  - start power once mode.  Issue again to scan once "again"

        pwrstep  - start power step mode.  Issue again to take next step

 

    stop scan frequency or scan power operations:

        stop     - cancels the current scan mode and turns off the RF if it is on  

 

    set up frequency and power

        setfreq value - set the frequency to value

        setpwr  value - set the power to value

 

    set up frequency scan modes

        setfreqfrom value - set the scan frequency "from" field to value

        setfreqto value   - set the scan frequency "to" field to value

        setfreqstep value - set the scan frequency step size field to value

        setfreqdelay value- set the scan frequency delay field to value

 

    set up power scan modes

        setpwrfrom value  - set the scan power "from" field to value

        setpwrto value    - set the scan power "to" field to value

        setpwrstep value  - set the scan power step size field to value

        setpwrdelay value - set the scan power delay field to value

    other:

       help  - display commands. The returned string is a  message that uses embeded “,,” as a new line separator.  To properly   

                   display this string replace “,,” with “\n”.  The length of this string may change in the future.

       shutdown - terminates RFControl

 

For each command sent to RFControl, the server responds with a string containing a status, an error, or the help message as below:

 

The possible responses:

          good - command accepted

already scanning – stop first:  issued if a scan operation is already in progress

stopped scan

stopped once/step

nothing scanning - if  a stop is issued when scanning is not active

value* is not a valid frequency

value* is not a valid power setting

power step must be non-zero integer

abs (frequency step) must be > .001

delay must be >= .01 seconds

unknown command – send help

a  “help string” that contains the valid RFControl commands.  

 

* value is the value parameter that was passed to RFControl with the command.

 

Programming Examples:  Command processing

 

In TCL, the interaction between the application and RFControl may look like this, assuming the socket had been opened as above:

 

    puts $handle “rfon”   # send the command

    flush $handle

    gets $handle buf    # get the response

 

In perl it may look like this:

 

    print $handle “rfon”; #send the command

    $buf = <$handle>;  # get the response

 

In c#:

 

// allocate no less than the longest reply message expected from RFControl (364 bytes) or multiple reads

// will have to be performed to read the full help reply.

            Byte[] data = new Byte[364];

            data = System.Text.Encoding.ASCII.GetBytes(message + "\n");  // append the newline to the command

 // Send the message to the connected TcpServer via the stream

           stream.Write(data, 0, data.Length);

// Read full response from stream

           Int32 bytes = stream.Read(data, 0, data.Length);

           string buf = System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bottom of page