User Tools

Site Tools

한국어

moacon:comget:index

comGet

short comGet (u8 comCh)

comCh : Channel number
returns 0~0xFF if successful, and -1 (0xFFFF) otherwise

Reads a sing character from the receive buffer for channel comCh. Bytes received are stored in a 255-byte receive buffer. comGet reads from this buffer one byte at a time. The comLen function can be used to see if there is any data in the receive buffer.

The following program echoes received data back to the sender one byte at a time.

#include "moacon500.h"
void cmain(void)
{
 short c;
 openCom(0, 115200, C8N1);              // Channel 0, 115200 Baud, data bits: 8, no parity, stop bits: 1
 while (1)                              // Repeat forever
 {
   if(comLen(0) > 0)                    // if data exists in the receive buffer
   {
     c = comGet(0);                     // Get one byte
     comPut(0,c);                       // Send byte back to sender
   }
 }
}

go MOACON home

moacon/comget/index.txt · Last modified: 2016/04/14 11:07 (external edit)