Rockwell Automation 5370 CVIM Communications Manual User Manual
Page 131

Chapter 5
Using the RS-232 Ports
5–61
{
int good_string = 0;
int message_started = 0;
int ch, err, retry=4;
int length = 0;
unsigned char *msg_start_ptr, df1_bcc;
msg_start_ptr = msg;
while ( !good_string && retry )
{
ch = _bios_serialcom(_COM_RECEIVE,portnum, 0);
err |= ch & COMMFLAGS;
if (( ch & 0xFF ) == DLE )
{
ch = _bios_serialcom(_COM_RECEIVE,portnum,0);
err |= ch & COMMFLAGS;
switch( ch & 0xFF )
{
case STX:
message_started = 1;
break;
case ETX:
message_started = 0;
ch = _bios_serialcom(_COM_RECEIVE,portnum,0);
err |= ch & COMMFLAGS;
df1_bcc = –df1_bcc;
if (( (ch & 0xFF) == df1_bcc ) && !err )
{
_bios_serialcom(_COM_SEND,portnum,DLE);
_bios_serialcom(_COM_SEND,portnum,ACK);
last responsem = 1;
good_string = 1;
}
else
{
_bios_serialcom(_COM_SEND,portnum,DLE);
_bios_serialcom(_COM_SEND,portnum,NAK);
if ( ––retry )
{
err = 0;
length = 0;
df1_bcc = 0;
msg = msg_start_ptr;
}
}
break;