static uint8_t GetChar(void) { uint8_t ch; while (AS1_RecvChar(&ch) != ERR_OK) { } return ch; }
/* ** =================================================================== ** Event : AS1_OnRxChar (module Events) ** ** From bean : AS1 [AsynchroSerial] ** Description : ** This event is called after a correct character is ** received. ** DMA mode: ** If DMA controller is available on the selected CPU and ** the receiver is configured to use DMA controller then ** this event is disabled. Only OnFullRxBuf method can be ** used in DMA mode. ** Parameters : None ** Returns : Nothing ** =================================================================== */ void AS1_OnRxChar(void) { /* Write your code here ... */ AS1_TComData dat; // if(AS1_RecvChar(&dat)==ERR_OK) AS1_RecvChar(&dat); ModBus_Recive(dat); }
/* ** =================================================================== ** Method : CLS1_ReadChar (component Shell) ** Description : ** Reads a character (blocking) ** Parameters : ** NAME - DESCRIPTION ** * c - Pointer to character to be used to store the ** result ** Returns : Nothing ** =================================================================== */ void CLS1_ReadChar(uint8_t *c) { uint8_t res; res = AS1_RecvChar((uint8_t*)c); if (res==ERR_RXEMPTY) { /* no character in buffer */ *c = '\0'; } }
/* is set to 'yes' (#pragma interrupt saveall is generated before the ISR) */ void AS1_OnRxChar(void) { AS1_RecvChar(&receive[SCIcount]); if(receive[SCIcount]=='c') SCIcount=0; else { SCIcount++; if(SCIcount>=13) SCIcount=0; } }
/* ** =================================================================== ** Event : AS1_OnIdle (module Events) ** ** From bean : AS1 [AsynchroSerial] ** Description : ** This event is called when an idle condition on the ** receiver is detected. ** The event is available only when both <Interrupt ** service/event> and <Receiver > properties are enabled. ** Parameters : None ** Returns : Nothing ** =================================================================== */ void AS1_OnIdle(void) { /* Write your code here ... */ extern float timecoefficient; if(AS1_GetCharsInRxBuf()>0){ unsigned char cmd=255; AS1_RecvChar(&cmd); if(cmd==0){//handshake unsigned char t=0; unsigned char rply[2]={0}; unsigned short x; //unsigned char r; x=AS1_RecvChar(&t); rply[1]=(t+17)&0xff; AS1_SendBlock(rply,2,&x); }else if(cmd==1){//general query word x; byte t[4]; AS1_RecvBlock(t,4,&x); AS1_SendBlock((byte*)(t[0]+(t[1]<<8)),t[2]+(t[3]<<8),&x); }else if(cmd==2){//inc timecoefficient+=0.00001f; }else if(cmd==3){//dec timecoefficient-=0.00001f; } } /* char cmd=0; AS1_RecvChar(&cmd); if(cmd==CMD_SETTIMECOEFFICIENT&&AS1_GetCharsInRxBuf()>=sizeof(float)){ char t=0; AS1_RecvBlock((char *)&timecoefficient,sizeof(float),&t); if(t!=sizeof(float)){ //error; } }else if(cmd==CMD_INC){ timecoefficient+=0.00001f; }else if(cmd==CMD_DEC){ timecoefficient-=0.00001f; }*/ }
/* ** =================================================================== ** Method : AS1_RecvBlock (component AsynchroSerial) ** Description : ** If any data is received, this method returns the block of ** the data and its length (and incidental error), otherwise it ** returns an error code (it does not wait for data). ** This method is available only if non-zero length of the ** input buffer is defined and the receiver property is enabled. ** If less than requested number of characters is received only ** the available data is copied from the receive buffer to the ** user specified destination. The value ERR_EXEMPTY is ** returned and the value of variable pointed by the Rcv ** parameter is set to the number of received characters. ** Parameters : ** NAME - DESCRIPTION ** * Ptr - Pointer to the block of received data ** Size - Size of the block ** * Rcv - Pointer to real number of the received data ** Returns : ** --- - Error code, possible codes: ** ERR_OK - OK ** ERR_SPEED - This device does not work in ** the active speed mode ** ERR_RXEMPTY - The receive buffer didn't ** contain the requested number of data. Only ** available data has been returned. ** ERR_COMMON - common error occurred (the ** GetError method can be used for error ** specification) ** =================================================================== */ byte AS1_RecvBlock(AS1_TComData *Ptr, word Size, word *Rcv) { register word count; /* Number of received chars */ register byte result = ERR_OK; /* Last error */ for (count = 0x00U; count < Size; count++) { switch (AS1_RecvChar(Ptr++)) { /* Receive data and test the return value*/ case ERR_RXEMPTY: /* No data in the buffer */ if (result == ERR_OK) { /* If no receiver error reported */ result = ERR_RXEMPTY; /* Return info that requested number of data is not available */ } *Rcv = count; /* Return number of received chars */ return result; case ERR_COMMON: /* Receiver error reported */ result = ERR_COMMON; /* Return info that an error was detected */ break; default: break; } } *Rcv = count; /* Return number of received chars */ return result; /* OK */ }
static void UART_ReceiveChar(uint8_t *p) { if (AS1_RecvChar(p)!=ERR_OK) { *p = '\0'; } }