****************************************
*	 Prozeßnummer = 1
*	 Delay = 1000
*	 Eventsource = 0
*	 Number of Loops = 0
*	 Priorität = 0
*	 Version = 1
*	 FastStop = 0
*	 AdbasicVersion = 4000001
*	 ATSRAM = 0
*	 OPT_LEVEL = 1
*	 SAVECOMPIL = 0
****************************************
FUNCTION GetByteFromTablet(numPSerie) AS SHORT
	
DIM TimeOutSummaInit,TimeOutSumma AS INTEGER
DIM byte_SUMMA AS SHORT
	
	TimeOutSummaInit = read_timer()	
	do
		byte_SUMMA = read_fifo(1,numPSerie)
		TimeOutSumma = read_timer() - TimeOutSummaInit
	until ((byte_SUMMA<>-1) or (TimeOutSumma>40000))
	GetByteFromTablet= byte_SUMMA 
	
ENDFUNCTION

FUNCTION Call_ReadSUMMA(X_SUMMA,Y_SUMMA,BUTTONS_SUMMA,numPSerie) AS INTEGER
	
DIM PhaseBit_SUMMA,byte_SUMMA,fin_SUMMA AS SHORT
DIM Dummy_SUMMA_X,Dummy_SUMMA_Y AS INTEGER
DIM SUMMA_BUFFER[8] AS SHORT
DIM SUMMA_N_BYTE AS INTEGER

	'Demande un rapport : <ESC>G
	error=write_fifo(1,numPSerie,27) 'ESC
	error=write_fifo(1,numPSerie,71) 'G
	Call_ReadSUMMA= 0    
	fin_SUMMA = 0
	
	do
	  SUMMA_BUFFER[1]= GetByteFromTablet(numPSerie)
    if (SUMMA_BUFFER[1] <> - 1) then 
			PhaseBit_SUMMA = SUMMA_BUFFER[1] and 01000000B
			if (PhaseBit_SUMMA = 01000000B) then fin_SUMMA = 1	
	  else
			Call_ReadSUMMA= 1
			fin_SUMMA = 1
	  endif
	until (fin_SUMMA = 1)
	
	if (Call_ReadSUMMA= 0) then
    	
		for SUMMA_N_BYTE = 2 to 8 
			byte_SUMMA = GetByteFromTablet(numPSerie)			
			
			if (byte_SUMMA = - 1) then Call_ReadSUMMA = 2
			
			if (Call_ReadSUMMA = 0) then
    			
					SUMMA_BUFFER[SUMMA_N_BYTE] = byte_SUMMA
		 			byte_SUMMA = byte_SUMMA and 01000000B
					
					if (byte_SUMMA = 01000000B) then Call_ReadSUMMA = 3
					
					if ((Call_ReadSUMMA = 0) and (SUMMA_N_BYTE=8)) then
						Dummy_SUMMA_X = 4096*(SUMMA_BUFFER[5] AND 15)+64*(SUMMA_BUFFER[4] AND 63) + 1*(SUMMA_BUFFER[3] AND 63)
						X_SUMMA = Dummy_SUMMA_X / 100 
	  				Dummy_SUMMA_Y = 4096*(SUMMA_BUFFER[8] AND 15)+64*(SUMMA_BUFFER[7] AND 63) + (SUMMA_BUFFER[6] AND 63) 
						Y_SUMMA = Dummy_SUMMA_Y / 100
  					BUTTONS_SUMMA = (SUMMA_BUFFER[2] AND 15) 	
  					Call_ReadSUMMA = 255
					endif
			
			endif
		
		NEXT SUMMA_N_BYTE
	
	endif

ENDFUNCTION