VC4 Visapi

Merhaba,

Panel PC2200 cihazımda Visu üzerinde cyclic olarak grafik çiziyorum. Fakat grafik kırpışarak çalışıyor. Sanki visu taskı ile program taskı senkron olsa bu sorun çözülecek gibi fakat bu ayarı bulamadım.

Şimdiden teşekkür ederim.

Hi @c513531
The VC4 visualizations run in idle time. If you want to synchronize, you should use the task class you configured to provide idle time.

But I’ve already done some visapi painting applications and don’t know this reqirement and also never had this issue of flickering. So I guess it’s not a problem of synchronization.

Can you describe the phenomena in more detail? What is your environment: do you use DrawBox or not? Is it drawn one time at page load or cyclically?

Some hints which I can give you:

  • Many actions like e.g. opening a edit keyboard cause screen refresh. If not using DrawBox, your drawing will be erased
  • Page loading can take slightly longer than indicated by the Page Command / Actual Page datapoints. We typically start painting wit a short delay of approx. 50ms
1 Like

Merhaba Emanuel,

Öncelikle cevabın için teşekkür ederim.

Grafiği Döngüsel olarak çiziyorum.

Örnek program aşağıda mevcut.

IF iCurrentPage=iSetPage THEN
    
	IF ready <> 1 THEN
		VC_HANDLE := VA_Setup(1 , sVisuName);
		IF VC_HANDLE <> 0 THEN
			ready := 1;
		END_IF
	END_IF
	IF ready = 1 THEN
		IF VA_Saccess(1,VC_HANDLE)= 0 THEN
			VA_Redraw(1,VC_HANDLE);
			VA_Srelease(1,VC_HANDLE);
		END_IF
	END_IF	
	ready		:=0;
	VC_HANDLE	:=0;
    

	//Grafik Line
	FOR i:=0 TO 100-1 DO
		uiX[i]:=REAL_TO_UINT(rLineLenght*i)+iXoffset;
		uiX[i+1]:=REAL_TO_UINT(rLineLenght*(i+1))+iXoffset;
		
		uiY[i]:=REAL_TO_UINT(iYoffset-rArrPoints[i]*rLineWidth);
		uiY[i+1]:=REAL_TO_UINT(iYoffset-rArrPoints[i+1]*rLineWidth);
        
		IF ready <> 1 THEN
			VC_HANDLE := VA_Setup(1 ,sVisuName);	
			IF VC_HANDLE <> 0 THEN
				ready := 1;
			END_IF
		END_IF
		IF ready = 1 THEN
			IF VA_Saccess(1,VC_HANDLE) = 0 THEN		 
                                  VA_Line(1,VC_HANDLE,uiX[i],uiY[i],uiX[i+1],uiY[i+1],uiLineColor);
			      VA_Srelease(1,VC_HANDLE);	
			END_IF
		END_IF			
		ready		:=0;
		VC_HANDLE	:=0;           
	END_FOR

    END_IF

Hi there,

the current code calls VA_Redraw() in every cycle, leading to the result you are observing.
What I would recommend is to only call it in case you really need a complete redraw of the screen content, so whenever you modify the graph data. You can test what I mean by commenting your VA_Redraw() method call - you will still be able to see new values added and the flickering stops. Only once you start over (or really, change anything that would change an existing line), I’d call the redraw method.
Also, as a side note, I wouldn’t call the VA_Setup() in every cycle (you currently set “ready” to 0 in every cycle) and VA_saccess also can be used across all drawing code, no need to access and release 100 times during your code (every loop)

PROGRAM _CYCLIC
	IF iCurrentPage = iSetPage THEN
		IF ready <> 1 THEN
			VC_HANDLE := VA_Setup(1, sVisuName);
			
			IF VC_HANDLE <> 0 THEN
				ready := 1;
			END_IF
		END_IF
	
		IF ready = 1 THEN
		    // we use the access for all line draws
			IF VA_Saccess(1, VC_HANDLE) = 0 THEN
				// do not hardcode sizes
				FOR i := 0 TO SIZEOF(uiX)/SIZEOF(uiX[0]) - 1 DO
					uiX[i] := REAL_TO_UINT(rLineLenght*i) + iXoffset;
					uiX[i+1] := REAL_TO_UINT(rLineLenght*(i+1)) + iXoffset;
					
					uiY[i] := REAL_TO_UINT(iYoffset - rArrPoints[i] * rLineWidth);
					uiY[i+1] := REAL_TO_UINT(iYoffset - rArrPoints[i+1] * rLineWidth);
					 
			        VA_Line(1, VC_HANDLE, uiX[i], uiY[i], uiX[i+1], uiY[i+1], uiLineColor);
				END_FOR
				// call the redraw here, and only do so once you changed something about the points, offsets, line width or color
				// note: currently we only redraw on change of a value
				IF brsmemcmp(ADR(rArrPoints), ADR(rArrPointsMem), SIZEOF(rArrPoints)) <> 0 THEN
					brsmemcpy(ADR(rArrPointsMem), ADR(rArrPoints), SIZEOF(rArrPoints));
					VA_Redraw(1, VC_HANDLE);
				END_IF
				
				// we release once we are done drawing
				VA_Srelease(1, VC_HANDLE);
			END_IF
		END_IF
	ELSE
		ready := 0;
		VC_HANDLE := 0;
    END_IF
	 
END_PROGRAM

That way it might still flicker, but only on update of a value, not every cycle

Edit: Additionally, to remove the flickering completely, you might want to use a DrawBox, example here: B&R Online Help (Ansi C, but should be easy enough to translate)

2 Likes

Teşekkürler Michael,

Bahsettiğin şekilde deneyeceğim ve son durumu burada paylaşacağım.

1 Like