<?xml version="1.0" encoding="Shift_JIS"?>
<?xml-stylesheet type="text/xsl" href="../Fmethod_xsl/fmethod_he_c.xsl"?>

<root>
  <func>
    <title>cnc_upload4</title>


    <declare>
      <vc>
        <include>#include "fwlib32.h"</include>
        <prottype>FWLIBAPI short WINAPI cnc_upload4(unsigned short FlibHndl, long *length, char *data);</prottype>
      </vc>
    </declare>



    <doc>
        <cmn>
            <p>Read NC data registered on the memory in CNC.</p>
            <p>
                This function reads the characters of NC data as long as it is specified by '*length'.<br/>
                However, if the number of characters to read is less than the specified number by delaying CNC data process,
                this function reads the characters as many as possible and then sets length' with the real number of 
                characters which are read in the buffer.
            </p>
            <p>
                In case that this function cannot read at least one character, 
                it returns EW_BUFFER, so again call this function with the same arguments.
            </p>
            <p>
                Because importance is attached to the speed of data transfer to the CNC, in general,
                return of errors(EW_DATA, etc.) may be delayed.
                Namely, an error status may refrect the result caused by the previously executed cnc_upload callings.
                And the error status for some cnc_upload callings just before the finish of uploading is returned
                by <a href="Program/cnc_upend4.htm" target="_parent">cnc_upend4</a> function.
            </p>
            <b>Format of input data</b>
            <p>NC data which is read from CNC is the string composed of ASCII characters as following format.</p>

            <p class="dd">
                % LF Block1 LF Block2 LF ... LF %<br/>
                where LF = 0x0A ('\n')<br/>
                <br/>
                or<br/>
                <br/>
                % LF CR CR Block1 LF CR CR Block2 LF CR CR ... LF CR CR %<br/>
                where CR = 0x0D ('\r') , LF = 0x0A ('\n') <br/>
                <br/>
                The parameter (Series 150i:0000#3, Series 160i/180i/210i/0i/Power Mate i:0100#3)
                determines which is used. And space code (' ') may be inserted before LF for TV check.<br/>
            </p>

            <p>
                A null character('\x00') is not added at the end of each string stored in the buffer.<br/>
                The last character of read NC data is '%'. If the application keeps reading by using this function
                after reading the last '%', cnc_upload3 returns EW_RESET.
            </p>
            <p>
                In case of 300i/310i/320i, when the CNC parameter No.6019#0 is '1', the number of the macro variable and the variable data are output as a comment continuously after '%' of the end of data.<p/>
                The last character of comment data is also '%'.  If the application keeps reading by using this function after reading the last '%', cnc_upload4 returns EW_RESET.
            </p>
            <p>
                The protected NC program(O8000-/O9000- protection, encoding) is acquired as "% LF % LF",  and EW_PROT error will return by cnc_upend4.
            </p>
        </cmn>
    </doc>



    <argument>
        <common>
            <vc>
                <item>
                    <name>FlibHndl</name>
                    <type>in</type>
                    <content>
                        <p>
                            Specify the library handle.
                            See "<a href="handle.htm" target="_parent">Library handle</a>" for details.
                        </p>
                    </content>
                </item>
                <item>
                    <name>length</name>
                    <type>in/out</type>
                    <content>
                        <p>
                            Specify the ponter of the variable to the character length of NC data.<br/>
                            Set read number of characters by one time to it and it must be a multiple of 256.
                        </p>
                        <p>After reading, the number of characters actually read is set in this variable again.</p>
                        <p>This function returns EW_LENGTH if '*length' is less than 256.</p>
                    </content>
                </item>
                <item>
                    <name>data </name>
                    <type>out</type>
                    <content>
                        <p>Specify the ponter to the buffer to be read.</p>
                    </content>
                </item>
            </vc>
        </common>
    </argument>



    <errcode>
        <item>
            <name>EW_RESET</name>
            <content>
                Reset or stop request<br/>
                The data to read is nothing.<br/>
                Call the <a href="Program/cnc_upend4.htm" target="_parent">cnc_upend4</a> function.
            </content>
        </item>
        <item>
            <name>EW_FUNC</name>
            <content>
                <a href="Program/cnc_upstart4.htm" target="_parent">cnc_upstart4</a> function has not been executed.
            </content>
        </item>
        <item>
            <name>EW_LENGTH</name>
            <content>
                The size of character string is less than 256.
            </content>
        </item>
        <item>
            <name>EW_DATA</name>
            <content>
                Data error<br/>
                In order to get more information for this err_no return value, execute
                <a href="Misc/cnc_getdtailerr.htm" target="_parent">cnc_getdtailerr</a> function.<br/>
                The following detail status will be set onto the member, err_no of ODBERR structure.
                <table>
                    <colgroup align="center" valign="top">
                    <colgroup align="center" valign="top">
                    <colgroup valign="top">
                    <tr>
                        <td>2</td><td>:</td><td>Program is not found within the specified range.</td>
                    </tr>
                    <tr>
                        <td>3</td><td>:</td><td>NC program memory is broken.</td>
                    </tr>
                    </colgroup>
                    </colgroup>
                    </colgroup>
                </table>
                See <a href="#disc">Description</a> about the timing of error.
            </content>
        </item>
        <item>
            <name>EW_PROT</name>
            <content>
                Protected<br/>
                Tape memory is read-protected by the CNC parameter setting(O8000-/O9000- protection, encoding).<br/>
                See <a href="#disc">Description</a> about the timing of error.
            </content>
        </item>
        <item>
            <name>EW_BUFFER</name>
            <content>
                Buffer empty/full<br/>
                Retry because the buffer is empty.<br/>
                See <a href="#disc">Description</a> about the timing of error.
            </content>
        </item>
<!--
        <item>
            <name>EW_REJECT</name>
            <content>
                CNC execution denied<br/>
                Uploading is disable in the current CNC status.
                (Machining, resetting, mode changing)<br/>
                See <a href="#disc">Description</a> about the timing of error.
            </content>
        </item>
        <item>
            <name>EW_ALARM</name>
            <content>
                Alarm state<br/>
                Alarm has occurred while uploading.<br/>
                See <a href="#disc">Description</a> about the timing of error.
            </content>
        </item>
-->
    </errcode>



    <option>
        <hssb>The extended driver/library function is necessary.</hssb>
        <type>
            Pitch error compensation<br/>
            Custom macro<br/>
            Work zero offset
        </type>
    </option>



    <parameter>
        <type>
            <ul>
                0100#3<br/>
                3202#0,#4,#6<br/>
                3204#3,#4<br/>
                3210,3211<br/>
                6019#0
            </ul>
        </type>
    </parameter>



    <mode>
    </mode>



    <support>
        <m>
            <fs0ia>X</fs0ia>
            <fs0ib>X</fs0ib>
            <fs15>X</fs15>
            <fs15i>X</fs15i>
            <fs16>X</fs16>
            <fs18>X</fs18>
            <fs21>X</fs21>
            <fs16ia>X</fs16ia>
            <fs18ia>X</fs18ia>
            <fs21ia>X</fs21ia>
            <fs16ib>X</fs16ib>
            <fs18ib>X</fs18ib>
            <fs21ib>X</fs21ib>
            <fs30i>O</fs30i>
        </m>
        <t>
            <fs0ia>X</fs0ia>
            <fs0ib>X</fs0ib>
            <fs15>X</fs15>
            <fs15i>X</fs15i>
            <fs16>X</fs16>
            <fs18>X</fs18>
            <fs21>X</fs21>
            <fs16ia>X</fs16ia>
            <fs18ia>X</fs18ia>
            <fs21ia>X</fs21ia>
            <fs16ib>X</fs16ib>
            <fs18ib>X</fs18ib>
            <fs21ib>X</fs21ib>
            <fs30i>O</fs30i>
        </t>
        <lc>
            <fs0ia>X</fs0ia>
            <fs0ib>X</fs0ib>
            <fs15>X</fs15>
            <fs15i>X</fs15i>
            <fs16>X</fs16>
            <fs18>X</fs18>
            <fs21>X</fs21>
            <fs16ia>X</fs16ia>
            <fs18ia>X</fs18ia>
            <fs21ia>X</fs21ia>
            <fs16ib>X</fs16ib>
            <fs18ib>X</fs18ib>
            <fs21ib>X</fs21ib>
            <fs30i>X</fs30i>
        </lc>
        <p>
            <fs16i>X</fs16i>
            <fs18i>X</fs18i>
        </p>
        <l>
            <fs16i>X</fs16i>
            <fs18i>X</fs18i>
        </l>
        <w>
            <fs16i>X</fs16i>
            <fs18i>X</fs18i>
        </w>
        <pw>
            <d>X</d>
            <h>X</h>
        </pw>
        <is>
            <!-- M -->
            <m>
                <fs30is>O</fs30is>
            </m>
            <!-- T -->
            <t>
                <fs30is>O</fs30is>
            </t>
        </is>
    </support>



    <reference>
        <item>
            <name>cnc_upstart4</name>
            <file>Program/cnc_upstart4.htm</file>
        </item>
        <item>
            <name>cnc_upend3</name>
            <file>Program/cnc_upend4.htm</file>
        </item>
    </reference>



    <example>
<vc>
The following program reads the specified NC program registered in CNC,
and displays its contents on the screen.

#include "fwlib32.h"
#define BUFSIZE 1280

/* prgnum is NC program number to read. */
short example( long *prgname )
{
        char buf[BUFSIZE+1] ;
        short ret ;
        long len ;
        ret = cnc_upstart4( h, 0 prgname ) ;
        if ( ret ) return ( ret ) ;
        do {
                len = BUFSIZE ;
                ret = cnc_upload4( h, &#38;len, buf ) ;
                if ( ret == EW_BUFFER ) {
                        continue ;
                }
                if ( ret == EW_OK ) {
                        buf[len] = '\0' ;
                        printf( "%s", buf ) ;
                }
                if ( buf[len-1] == '%' ) {
                        break ;
                }
        } while ( ret == EW_OK ) ;
        ret = cnc_upend4( h ) ;
        return ( ret ) ;
}
</vc>
    </example>



  </func>
</root>
