


              Frye Instrument Communication Description        2006/04/05



        General Description:

        Current Frye instruments use a protocol called FIPP (Frye 
        Instrument Packet Protocol) to communicate over a communications 
        port of a computer.

        Because the instruments are usually busy making measurements and
        displaying the results the computer can not communicate with the
        instrument any time it pleases, instead it waits for the 
        instrument to signal its availability through what is known as a 
        reverse poll.

        Once the instrument sends this poll the computer has a 50 mS time
        window (longer on ethernet) in which the instrument will accept 
        messages with instructions. Any other time the instrument will 
        ignore data coming over the port.  If the 50 mS time window goes 
        by with no data from the computer the instrument will return to 
        its measurement and display functions. If the computer has 
        started sending a message the instrument will go through a full 
        conversation cycle before it resumes its normal operation.
        Note: Some instruments allow the poll delay time to be reduced to 
        improve the speed of operation. See the documentation for the 
        specific instrument to determine if the the poll delay time can 
        be adjusted.

        Messages are divided into two main categories, those issued by 
        the computer, and those issued by the FIPP instrument.

        The command messages issued by the computer are divided into 
        three categories. 
         1. SET messages set some parameters or values in the instrument. 
         2.  DO messages request the instrument do something. 
         3. GET messages request the instrument send some information 
              such as configuration parameters or measurement data.

        The messages issued by the instrument are divided into two 
        categories.
         1. CONTROL messages help control the flow of data between the 
              instrument and the computer. 
         2. RESPONSE messages return data to the computer in response to 
              a get message.










                                        1


        All conversations between the instrument and the computer start 
        with the instrument issuing a poll, the computer responds with a 
        message and the instrument acknowledges it.  As an example: 

        Instrument            Computer             Notes
        -----------------------------------------------------------------
        POLL                             |Instrument is ready and waiting
                     Set Source to 90 dB |SET message
        ACK                              |I got your order
        -----------------------------------------------------------------
        POLL                             |Instrument is ready and waiting
                       Get mic amplitude |GET message
        amp=112.4 dB                     |OK, here it is
        -----------------------------------------------------------------
        POLL                             |Instrument is ready and waiting
                   Wake me up at 6:00 am |Invalid message
        ILLEGAL                          |I don't do that

        All messages have this general format:
        message ID      Indicates what message this is
        message size    How much if any data is included in the message
        data            The data if message size is not 0
        checksum        An inverse checksum of the three items above.

        All data is organized in words, each word consists of 16 bits 
        (two bytes).  In a message the message ID, the size, and the 
        checksum each are one word in length.  The data field is always 
        made up of word length data (an even number of bytes).  The bytes 
        within a word are normally arranged in the order used by Intel's 
        80x86 family of processors, that is low byte first, high byte 
        second.  Note that there may be some exceptions to this in some 
        messages. See the specific instrument documentation for details. 

        The message ID is a word that tells the recipient of the message 
        what to do with the message.  Different values have different 
        meanings, for example on the 6500 instrument, a value of 2 is set 
        frequency, a value of 28 is get software version, a -4 is an ACK.

        The message size refers to how many data words follow, this can 
        be 0 for messages which do not carry data. This length is in 
        words, not bytes. Messages that contain byte oriented data will 
        always be filled to a word boundary.

        The data is dependent on the message. Some messages may contain 
        variable length data, while others may contain fixed length data.
        You should refer to the command documentation for the data length 
        requirements of the individual commands.

        The checksum is the 16 bit complement of the sum of all the 
        previous words in a message.  i.e. the complement of message ID + 
        message size + each data word. If you are using the Fryers 
        driver, you do not need to worry about the checksum, Fryers 
        computes it for you.



                                        2


        Here are some example messages.

        -----------------------------------------------------------------
        POLL message, instrument tells computer it is ready to converse.

        FFFF h    -1 is the message ID for POLL
        0000 h    POLL caries no data
        0000 h    inverted checksum is the complement of FFFFh + 0000h
        -----------------------------------------------------------------
        Set frequency to 1000 Hz.

        0002 h    2 is the message ID for set frequency
        0001 h    there is one word of data
        03E8 h    1000 Hz is the data (1000 decimal is 03E8 hex)
        FC14 h    the complement of 0002h + 0001h + 03E8h
        -----------------------------------------------------------------

        Error Handling:

        Several mechanisms have been incorporated to detect communication
        errors.  The response message returned by the instrument is the 
        primary mechanism used for error detection.  The status flag is 
        the second mechanism used to detect errors.  Additionally most 
        set messages have associated get messages which allow double- 
        checking that the set message did work as intended.

        Instrument Response:

        When an instrument receives a packet it does several basic checks 
        on it before returning a response.  If all checks are successful 
        it returns an ACK for set and do messages, and a data response 
        message for get messages. 

        The first check is that the packet is complete, that is, there 
        must be exactly the number of words of data given by the size 
        field plus three extra words (one word for the ID, one for the 
        size word, and one word for the checksum).  If this check fails 
        the instrument returns a NAK (Not AcKnowledge) message and 
        resumes normal activity. Note: If the message is a variable 
        length data type message, the size word will not be checked.

        The next test is the checksum.  If the checksum is incorrect a 
        NAK (Not AcKnowledge) is returned.

        Next the message ID is checked for validity, for example, in the 
        current revision of FIPP a message ID of 4356 is not defined. 
        This will cause an ILLEGAL message to be returned.

        For messages which have a fixed size the length is checked 
        against the message ID and an ILLEGAL message is returned if this 
        fails. For example a set frequency message is known to always be 
        4 words in length.  A set operating parameters message is 
        variable in length thus this check is skipped for this message.



                                        3


        Command Status:

        Even when a message is successfully received there are two 
        situations that can cause problems.  The first is if an invalid 
        parameter is sent, for example a frequency which is outside the 
        range of the instrument (eg. 20 KHz for a 6500).  The second is 
        if a request is made which is inappropriate in a given operating 
        mode (eg. run a pure tone sweep when in composite mode). 

        Depending on how the instrument processes the error, it will 
        either return an ILLEGAL response, or an ACK response to indicate 
        that the command was correctly received.  If an ACK was returned, 
        the instrument maintains a status flag which can be checked by 
        the computer with the get status message.

        Generally, an instrument will return an ACK to the command even 
        if there was an error if the command will take time to process 
        before the error is known. It is important to the protocol that a 
        response be received by the computer in a timely manner. Thus the 
        ACK is sent if the result is not immediately available. 

        If the instrument can immediately determine a problem with a 
        command, such as a parameter value out of range, it may respond 
        with an ILLEGAL response. Some instruments may still return an 
        ACK under this situation with the command status error flag set. 
        It is up to the program on the computer to look for the command 
        status error flag to determine status if an ACK is returned.

        The command status flag is set any time an ACK based command 
        error occurs and is not cleared until the computer issues a get 
        status message followed by another message which is not get 
        status.  The clear and set states of this flag are called GO and 
        NOGO respectively. An ILLEGAL command response does not set the 
        command status flag. It doesn't clear the flag either. The 
        command status error flag is only cleared after it is read.
         
        Since the flag is not cleared when a message is successfully
        processed it is possible to issue a group of commands such as:

                set frequency to 1000 Hz
                set amplitude to 70 dB
                set gain mode
                run a pure tone sweep

        You can then check the status once to verify the whole group of 
        messages was successful before requesting the measured data be 
        transferred to the computer.

        Note that the command status flag is not set by messages which 
        cause the instrument to return a NAK or an ILLEGAL message, nor 
        will a valid ACK response (without an error) set the flag.





                                        4


        Protocol in Detail:

        Since initiating a conversation between a computer and the 
        instrument is time critical the first step of the conversation 
        has to be synchronization.  To do this the computer must look at 
        the byte stream coming from the instrument and find a sequence of 
        6 bytes that looks like "FF FF 00 00 00 00".  As soon as the last 
        zero is confirmed the computer needs to issue its command 
        message.  If the instrument starts receiving the first byte of 
        the command message within 50 mS of when it sent the poll it will 
        then allow up to 100 mS between successive bytes.  If the 100 mS 
        limit is not met the instrument will time-out and return a NAK. 

        If a full packet is received the previously indicated tests 
        (see Instrument Response) are done to insure integrity.  If they 
        all pass the message is processed.  A set or a do message will 
        immediately return an ACK message.  A get message will return a 
        data response message.  The data response message's ID is always 
        the same as the ID of the get message but with the high bit set, 
        therefor the get frequency message who's ID is 0017h (23 decimal) 
        will result in a data response message with an ID of 8017h 
        (-32745 decimal).  

        Some instruments will issue a poll immediately after the ACK or 
        data response message rather than waiting for a measurement cycle 
        to occur, this is so that multiple commands can be issued in 
        rapid succession.  The side effect is that data dependent on the 
        previous command may not be available at the first poll.  For 
        example if the set frequency is issued and the get microphone 
        amplitude is issued on the very first poll after set frequency 
        command is given, the amplitude returned will have been measured 
        at the old frequency value, not the new one. This sort of 
        sequence of events should be tracked and a poll skipped before a 
        get is issued that would be affected by a set (see Skipping 
        Polls).

        There is no guarantee of how often the instrument will issue 
        polls, in fact the computer should always be prepared for the 
        polls to stop completely as would be the case if someone turned 
        the instrument off or disconnected the cable.  Additionally the 
        instrument may have modes in which it will not issue polls at 
        all, for example on the old 6500 when in a menu polls are not 
        issued.













                                        5


        Skipping Polls:

        Some instruments like the 6500 and the FP40 are not able to 
        communicate while measuring data. Because of this, once the 
        computer sends a command to the instrument, the instrument enters 
        its communication mode and will stay there until the computer 
        releases it. The release can either happen automatically, by the 
        computer not responding to the poll from the instrument, or the 
        computer can send a command to tell the instrument to exit the 
        communications mode and go do a measurement. This later "quick 
        terminate" function is a new addition. Older instruments do not 
        support the function, and will return an ILLEGAL response. If you 
        get an ILLEGAL response to the quick terminate command, you 
        should wait 100ms after issuing the last command to allow the 
        instrument to exit the communication mode. Refer to the 
        instrument software to determine if it supports Quick Terminate.

        Newer instruments also allow the poll delay time to be adjusted. 
        A command can be sent to the instrument to adjust the delay time 
        to a smaller value if desired. This is useful to speed up the 
        operation of the instrument if the computer does not need the 
        full 50ms delay time to respond to a poll. 

        The minimum amount of poll delay time that can be set is 
        dependent upon the instrument. All instruments will have a 
        minimum poll delay time of 10ms available. The default poll delay 
        time is 50ms for all instruments. 

        Note that the poll delay time does not refer to the time between 
        polls. It refers to the time available to the computer in which 
        it must respond with a command after the poll has been given. The 
        actual time between polls will be a variable amount of time that 
        is equal to or longer than the poll delay time. The exact amount 
        of time is dependent upon the time it takes the instrument to 
        perform the activity it needs to do. Depending on the activity, 
        this can be as much as a second or more. In the case of a pure 
        tone sweep, it can be as much as a minute if long settle times 
        are used, distortion is being measured, and 16x noise reduction 
        is used. 

        A new command was added to V4.00 of Fryers which provides the 
        Skip Poll function ($FF1C). This eliminates the time dependency 
        problems of the older Skip Poll methods. If you are using V4.00 
        (or later) of Fryers and you need to perform the Skip Poll 
        operation, you might want to consider using the Skip Poll 
        function unless you need to maintain compatibility to the older 
        versions of the Fryers driver. 









                                        6


        Quick Terminate: 

        On newer machines, the Quick Terminate function has been added. 
        this performs a function similar to the Skip Poll without the 
        time dependence of the Skip Poll. 

        The Quick Terminate command message tells the attached instrument 
        that no more commands will be sent so it can exit the 
        communications mode. This can potentially speed up data flow by 
        eliminating the need to wait for a poll to be skipped.

        The proper response to a Quick Terminate command message is no 
        response at all. The Receive Ready flag will not be set as a 
        result of this command, only the Send Ready flag will be set when 
        it is completed.

        If the receive ready flag is set as a result of this command, and 
        the returned message is an ILLEGAL response, it means that the 
        Quick Terminate function is not supported.

        The new Fryers driver supports an automatic quick terminate 
        function. If no command has been been presented to the Fryers 
        driver to send, the Fryers driver will send a Quick Terminate 
        message in response to the poll request. This will cause the 
        instrument to immediately exit the communication mode rather than 
        wait around doing nothing. The Fryers automatic Quick Terminate 
        function is disabled if the attached instrument indicates that it 
        does not understand the command (by returning an ILLEGAL 
        response). 

        While the automatic quick terminate feature is available, we 
        don't recommend that you use it. Experience in testing has shown 
        that the feature tends to slow down the computer because it 
        spends a significant amount of time responding to the polls with 
        a quick terminate command. Use the manual quick terminate to end 
        commands, which minimizes computer performance slow down. 

        Using the automatic quick terminate feature in Fryers can 
        slightly improve performance on the Fonix instrument by reducing 
        the cycle time when there is no command to be given by the 
        computer in response to a poll, but it adds work to the computer 
        which slows down the computer. In most cases, the extra slow down 
        on the Fonix instrument by not using the quick terminate is 
        unnoticeable. 

        -med
        <eof>









                                        7
