//Startbedingung Datensammeln Datenbank
IF (GL_VAR.Pruefkoerper) OR ( NOT GL_VAR.Pruefkoerper_ohne_kontakt AND GL_VAR.KMZ_Anzeige > 5 AND GL_VAR.Widerstand < 8000) THEN b_sammeln:=TRUE; ELSE b_sammeln:=FALSE; END_IF;
bWrite:= NOT b_sammeln AND GL_VAR.Direction_z_ret; //OR GL_VAR.Messung_fertig);
bCreate:= GL_VAR.start_b OR GL_VAR.start_e OR GL_VAR.start_m OR GL_VAR.start_end;
IF row>=2501 THEN b_sammeln:=FALSE; row:=0; column:=0; END_IF;
IF NOT b_sammeln THEN
row:=0; Column := 0 ;
ELSE
cyclecount:=cyclecount+1;
IF GL_VAR.Newton > 400 AND GL_VAR.Messung =2
THEN Cyclecount2 := 50;
ELSE Cyclecount2 := 25;
END_IF
IF
cyclecount=Cyclecount2 THEN
cyclecount:=0;
database[row+10,0]:=Widerstand;
database[row+10,1]:=GL_VAR.KMZ_String;
database[row+10,2]:=GL_VAR.hoehe_dif;
row:=row+1;
END_IF;
END_IF;
IF GL_VAR.Messung_fertig
THEN
row:=0; column:=0;
END_IF
//Systemzeit ermitteln
systemzeit(
sNetID:= ,
bEnable:=TRUE ,
dwCycle:=5 ,
dwOpt:=1 ,
tTimeout:= ,
bValid=> ,
systemTime=> ,
tzID=> );
CASE step OF
0: //Bedingung bWrite erfüllt
IF bWrite THEN
bWrite := FALSE;
bBusy := TRUE;
bError := FALSE;
nErrId := 0;
hFile := 0;
nRow := 0;
nColumn := 0;
step := 1;
END_IF
ePath := SEL( bBootFolder, PATH_GENERIC, PATH_BOOTPATH );
sPathName := SEL( bBootFolder, CONCAT('D:\Pruefberichte\', GL_VAR.Ordnername), sFolderName );
IF bCreate THEN
bCreate := FALSE;
fbCreateDir( bExecute := FALSE );
fbCreateDir(sNetId:= '',
sPathName:= sPathName,
ePath:= ePath,
bExecute:= TRUE,
tTimeout:= DEFAULT_ADS_TIMEOUT,
bBusy=>bCreate_Busy, bError=>bCreate_Error, nErrId=>nCreate_ErrID );
ELSE
fbCreateDir( bExecute := FALSE, bBusy=>bCreate_Busy, bError=>bCreate_Error, nErrId=>nCreate_ErrID );
END_IF
1: //Öffne Quelldatei
//Dateinnamen zusammensetzen
bastelstring(
sFormat:='%s\P%2u_%2u-%2u-%4u_%2u-%2u-%2u.csv',
arg1:=F_STRING(sPathName) ,
arg2:=F_WORD(MAIN.Dimensionen.Punkt) ,
arg3:=F_WORD(systemzeit.systemTime.wDay) ,
arg4:=F_WORD(systemzeit.systemTime.wMonth) ,
arg5:=F_WORD(systemzeit.systemTime.wYear) ,
arg6:=F_WORD(systemzeit.systemTime.wHour) ,
arg7:=F_WORD(systemzeit.systemTime.wMinute) ,
arg8:=F_WORD(systemzeit.systemTime.wSecond) ,
sOut=>sFileName );
//Öffne Datei im Text Mode
fbFileOpen( bExecute := FALSE );
fbFileOpen( sNetId := sNetId, sPathName := sFileName, nMode := FOPEN_MODEWRITE OR FOPEN_MODETEXT,
ePath := PATH_GENERIC, bExecute := TRUE );
step := 2;
2:// Wearten bis open nicht busy *)
fbFileOpen( bExecute := FALSE, bError => bError, nErrID => nErrID, hFile => hFile );
IF NOT fbFileOpen.bBusy THEN
IF NOT fbFileOpen.bError THEN
step := 3;
ELSE//Fehler: Datei nicht gefunden
step := 100;
END_IF
END_IF
3:// Konvertierung in .CSV Format
sCSVLine := '';
fbWriter.eCmd := eEnumCmd_First; //Schreiben der ersten Zeile
IF nRow <= MAX_CSV_ROWS THEN
FOR nColumn := 0 TO MAX_CSV_COLUMNS BY 1 DO
sCSVField := STRING_TO_CSVFIELD( database[ nRow, nColumn ], FALSE );//Daten aus dem Array lesen
//Neues Feld in Buffer Schreiben
fbWriter( pBuffer := ADR( sCSVLine ),
cbBuffer := SIZEOF( sCSVLine ) - 1,
putValue := sCSVField, pValue := 0,
cbValue := 0,
bCRLF := ( nColumn = MAX_CSV_COLUMNS ));
IF fbWriter.bOk THEN
fbWriter.eCmd := eEnumCmd_Next;
ELSE
step := 100;
RETURN;
END_IF
END_FOR
IF RIGHT( sCSVLine, 2 ) = '$R$L' THEN
sCSVLine := REPLACE( sCSVLine, '$L', 2, LEN( sCSVLine ) - 1 );
END_IF
nRow := nRow + 1;//Inkrementieren der Zeile
step := 4;
ELSE
Memset(ADR(Database), 0, SIZEOF(Database));
step := 10;
END_IF
4: //Schreibe einzelne Zeile
fbFilePuts( bExecute := FALSE );
fbFilePuts( sNetId := sNetId, hFile := hFile, sLine := sCSVLine, bExecute := TRUE );
step := 5;
5:// Warten bis Schreiben nicht busy
fbFilePuts( bExecute := FALSE, bError => bError, nErrID => nErrID );
IF NOT fbFilePuts.bBusy THEN
IF NOT fbFilePuts.bError THEN
step := 3;
ELSE
step := 100;
END_IF
END_IF
10:// Erstelle Quell Datei
fbFileClose( bExecute := FALSE );
fbFileClose( sNetId := sNetId, hFile := hFile, bExecute := TRUE );
step := 11;
11:// Warten bis Schließen nicht busy
fbFileClose( bExecute := FALSE, bError => bError, nErrID => nErrID );
IF ( NOT fbFileClose.bBusy) THEN
hFile := 0;
step := 100;
END_IF
100: //Beenden
IF ( hFile <> 0 ) THEN
step := 10;
ELSE
bBusy := FALSE;
step := 0;
END_IF
END_CASE