70 Ethernet module User’s Manual
Chapter 5 Computer Link Protocol and the PC Link Protocol Transmission
5
icunt = icunt + 4 ;
}
sprintf( &csnd[ (strlen( csnd )) - 1], ")\r" ) ;
isndsiz = strlen( csnd ); /* Set the send data length */
Snd.sin_family = AF_INET;
Snd.sin_addr.s_addr = inet_addr( DST_IP ); /* Set the remote IP address */
Snd.sin_port = htons( DST_PORT ); /* Set the remote port number */
/* Send a register write request */
ists = sendto( Isdp, csnd, isndsiz, 0,
(struct sockaddr *)&Snd,sizeof( Snd ) );
if ( ists == isndsiz ){ /* If the send length was OK */
/* Set the SELECT argument */
memset(&ibits,0x00,sizeof(fd_set)); /* Set the BIT initial value */
timeout.tv_sec = RECVTOUT; /* Set the timeout time */
FD_SET(Isdp,&ibits); /* BIT setup */
ists = select( 1, &ibits,0,0,(struct timeval *)&timeout);
if(ists > 0){ /* f normal return: */
/* Register write response reception */
ists = recvfrom( Isdp, crcv, sizeof( crcv ), 0
,(struct sockaddr *)&Rcv, &ircvsiz) ;
if ( ists > 5 ){
if( crcv[ 4 ] == ’C’ && crcv[ 5 ] == ’E’ ||
crcv[ 4 ] == ’E’ && crcv[ 5 ] == ’E’ ){
return( -1 ) ; /* Register write response error */
}
/* Register read request creation */
memset( csnd, 0x00, sizeof( csnd ) ) ;
memset( crcv, 0x00, sizeof( crcv ) ) ;
sprintf( &csnd[ 0 ] , "(A01DR" ); /* Register read command setup */
/* Set up the starting reg. no. */
sprintf( &csnd[ strlen(csnd)], "%s", REG_TYPE );
sprintf( &csnd[ strlen(csnd) ], "%04s", REG_ADR );
sprintf( &csnd[ strlen( csnd) ], "," ) ;
/* Set the data count */
idat = DATASIZ ; /* Register read data length */
sprintf( &csnd[ strlen( csnd ) ], "%02d", idat ) ;
sprintf( &csnd[ strlen( csnd )], ")\r" ) ;
isndsiz = strlen(csnd) ; /* Set up the data transmission length */
/* Send the register read command */
ists = sendto( Isdp, csnd, isndsiz, 0,
(struct sockaddr *)&Snd,sizeof( Snd ) );
if( ists == isndsiz ){
/* Set the BIT initial value */
memset(&ibits,0x00,sizeof(fd_set));
timeout.tv_sec = RECVTOUT; /* Set the timeout time */
/* BIT setup */
FD_SET(Isdp,&ibits);
ists = select( 1, &ibits,0,0,
(struct timeval *)&timeout);
if(ists <= 0){ /* If timeout and error: */
return( -1 ) ; /* recvfrom timed out */