// * The body of REXLANG algorithm * 
// The main procedure is executed once in each sampling period.
long main(void)
{
  if (hCom<0)
  {
    hCom = OpenUDP(0, receiverPort, 0, 0);  //opening UDP socket, syntax long OpenUDP(string localname, long lclPort, string remotename, long remPort)
  }
  else 
  {
    //receive the data
    dataCnt = Recv(hCom,buffer,BUFFER_SIZE); //receive data, max number of bytes = BUFFER_SIZE

    //the first signal is of type long, therefore 4 bytes
    signal0 = buffer[0] | buffer[1]<<8 | buffer[2]<<16 | buffer[3]<<24;
    dat0 = buffer[0];
    dat1 = buffer[1];
    dat2 = buffer[2];
    dat3 = buffer[3];
    
    //the second signal is binary, therefore 1 byte
    signal1 = buffer[4];
    
    //the third signal is of type double, therefore 8 bytes will be processed
    signal2 = buf2double(subarray(5,buffer),1);

    //the fourth signal is of type double, therefore 8 bytes will be processed
    signal3 = buf2double(subarray(13,buffer),1);
  }  
  //publishing the UDP communication handle through output signal (for debugging)
  handle = hCom;
  //and also the number of received bytes
  receivedBytes = dataCnt;
  return 0;
}
Exemple #2
0
double wnd_floatinput(double lastval)
{
	uchar msg;
	
	key = MSG_INIT;
	while(1)
	{
		if(key != KEY_INVALID)
		{
			msg = key;
			key = KEY_INVALID;
		}else{
			continue;
		}
		if(msg == MSG_INIT)
		{
			LCD_Cls();
			databuf[0] = '0';
			databuf[1] = '\0';
			pos_databuf = 0;
			draw_label(&datalbl,SW_NORMAL);
			wnd_inputbox(&databox);
//			LCD_ShowCursor(databox.x,databox.y);
		}

		if(msg == KEY_TAB)
		{
			databuf[pos_databuf++] = '0';
			databuf[pos_databuf] = '\0';
			msg = MSG_REFRESH;
		}
		if(pos_databuf >= max_databuf)
			continue;
		if(msg == KEY_DN) {
					if(pos_databuf == 0)
			{
				databuf[pos_databuf++] = '0';
				databuf[pos_databuf] = '\0';
			}

			if(databuf[pos_databuf-1] == '0')
				databuf[pos_databuf-1] = '9';
			else
				databuf[pos_databuf-1] -= 1;
			msg = MSG_REFRESH;
		}
		if(msg == KEY_UP) {
			if(databuf[pos_databuf-1] == '9')
				databuf[pos_databuf-1] = '0';
			else
				databuf[pos_databuf-1] += 1;
			msg = MSG_REFRESH;
		}
		if((msg >= KEY_NUM0 && msg <= KEY_NUM9) || msg == KEY_DOT) {
			databuf[pos_databuf++] = msg;
			databuf[pos_databuf] = '\0';
			msg = MSG_REFRESH;
		}
		if(msg == KEY_CE) {
//			LCD_HideCursor();
			return lastval;
		}
		if(msg == KEY_OK){
//			LCD_HideCursor();
			return buf2double();
		}
		if(msg == MSG_REFRESH) {
			draw_label(&databox,SW_NORMAL);
//			LCD_ShowCursor(databox.x+pos_databuf*16,databox.y);
		}
	}
}