Rockwell-automation 5370 Color CVIM Communications Manual Manual de usuario Pagina 134

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 222
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 133
Chapter 5
Using the RS232 Ports
566
} while (op_num >= 0); /* End do loop */
}
int send_message (portnum, msg, len)
int portnum; /* Communications port # */
unsigned char *msg; /* Pointer to message data */
int len; /* Length of message */
/* Transmits the message pointed to by msg, consisting of len characters.
If the message is not acknowledged, retransmits it up to 2 more
times.
Returns zero if successful or nonzero if an error occurs. */
{
int x=0, ch=0, chksum=0, err=0, retry=3;
do {
/* if an incoming char is waiting, clear it out */
while (_bios_serialcom(_COM_STATUS, portnum1, 0) & 256)
_bios_serialcom(_COM_RECEIVE, portnum1, 0);
/* send DLE STX to initiate message transfer */
_bios_serialcom(_COM_SEND,portnum1,DLE);
_bios_serialcom(_COM_SEND,portnum1,STX);
/* Send all bytes of the selected command & compute checksum */
for (x=chksum=0; x<len; x++)
{
_bios_serialcom(_COM_SEND,portnum1,msg[x]);
chksum += msg[x];
/* If data within the message was 0x10 (a DLE), send another
DLE so the receiver knows it is data, not a control
character.
(But dont include the second DLE in the checksum) */
if (msg[x] == DLE)
_bios_serialcom(_COM_SEND,portnum1,msg[x]);
}
/* send DLE ETX and CHKSUM */
_bios_serialcom(_COM_SEND,portnum1,DLE);
_bios_serialcom(_COM_SEND,portnum1,ETX);
_bios_serialcom(_COM_SEND,portnum1,(chksum)&0xFF);
/* check for DLE ACK */
ch = _bios_serialcom(_COM_RECEIVE,portnum1,0);
err = ch & COMMFLAGS;
if (err || ((ch & 0xFF) != DLE)) /* Mask character to 8 bits */
Vista de pagina 133
1 2 ... 129 130 131 132 133 134 135 136 137 138 139 ... 221 222

Comentarios a estos manuales

Sin comentarios