Rockwell Automation 5370 Color CVIM Communications Manual User Manual
Page 135

Chapter 5
Using the RS–232 Ports
5–67
err |= 0x01; /* no DLE on send */
if (!err)
{
ch = _bios_serialcom(_COM_RECEIVE,portnum–1,0);
err = ch & COMMFLAGS;
if (err || ((ch & 0xFF) != ACK)) /* Mask character to 8 bits
*/
err |= 0x02; /* no ACK on send */
}
} while (err && (––retry > 0)); /* if any error, retry */
return (err);
}
/* Recieves a message into buffer pointed to by msg & places
length in *len. If the checksum is invalid or a timeout occurs,
sends NAK and attempts to re–receive up to 2 more times.
Returns zero on success or nonzero if an error occurs. */
int get_message (portnum, msg, len)
int portnum; /* Serial port number */
unsigned char *msg; /* Pointer to message buffer */
int *len; /* Pointer to return length of message */
{
int good_string = 0;
int message_started = 0;
int ch=0, err=0, retry=4;
int length = 0;
unsigned char *msg_start_ptr, df1_bcc=0;
msg_start_ptr = msg;
while ( !good_string && retry )
{
ch = _bios_serialcom(_COM_RECEIVE,portnum–1,0);
err |= ch & COMMFLAGS;
if (( ch & 0xFF ) == DLE )
{
ch = _bios_serialcom(_COM_RECEIVE,portnum–1,0);
err |= ch & COMMFLAGS;
switch( ch & 0xFF )
{
case STX:
message_started = 1;
break;
case ETX:
message_started = 0;
ch = _bios_serialcom(_COM_RECEIVE,portnum–1,0);
err |= ch & COMMFLAGS;