Quantcast
Channel: SPS-Forum - Automatisierung und Elektrotechnik
Viewing all articles
Browse latest Browse all 47324

CX1010 Textdatei auf USB-Stick speichern

$
0
0
Hallo,

für eine Heizungssteuerung versuche ich in einer CX1010 einen Datenlogger mit einzubauen. Das folgende Testprogramm funktioniert leider nicht wie erwartet:

Code:

PROGRAM MAIN
VAR
    Path : T_MaxString;
    fbFileOpen : FB_FileOpen;
    fbFileClose : FB_FileClose;
    fbFilePuts : FB_FilePuts;
    hDestFile : UINT := 0;
    Status: INT := 0;
    bError : BOOL := FALSE;
    bStart : BOOL := FALSE;
    WriteInt : INT := 0;
    WriteString : T_MAXString;
END_VAR

VAR CONSTANT
    Standby : INT := 0;
    OpenFile : INT := 1;
    CreateHandle : INT := 2;
    WriteData : INT := 3;
    CloseFile : INT := 4;
    Error : INT := 5;
END_VAR

CASE Status OF
    Standby:
        IF bStart THEN
            Status := OpenFile;
            WriteInt := 0;
        END_IF;
    OpenFile:
        Path := '\Hard Disk2\test.txt';
        fbFileOpen (bExecute := FALSE);
        fbFileOpen (sNetId :='', sPathName := Path, nMode := FOPEN_MODEAPPEND OR FOPEN_MODETEXT,
            ePath := PATH_GENERIC, tTimeOut := DEFAULT_ADS_TIMEOUT, bExecute := TRUE);
        Status := CreateHandle;
    CreateHandle:
        fbFileOpen (bExecute := FALSE);
        IF NOT fbFileOpen.bBusy THEN
            IF fbFileOpen.bError THEN
                Status := Error;
            ELSE
                hDestFile := fbFileOpen.hFile;
                Status := WriteData;
                fbFilePuts (bExecute := FALSE, sNetId := '', hFile := hDestFile, tTimeout := DEFAULT_ADS_TIMEOUT);
                Status := WriteData;
            END_IF
        END_IF
    WriteData:
        IF NOT bStart THEN
            Status := CloseFile;
        END_IF;
        fbFilePuts(bExecute := FALSE);
        IF NOT fbFilePuts.bBusy THEN
            WriteString := CONCAT (INT_TO_STRING (WriteInt) , '$N');
            fbFilePuts (sLine := WriteString, bExecute := TRUE);
            WriteInt := WriteInt + 1;
            IF WriteInt > 99 THEN
                Status := CloseFile;
            END_IF;
        END_IF
        fbFilePuts(bExecute := FALSE);
        IF NOT fbFilePuts.bBusy THEN
            IF fbFilePuts.bError THEN
                Status := Error;
            END_IF
        END_IF
    CloseFile:
        IF (hDestFile <> 0) THEN
            fbFileClose(bExecute := FALSE);
            fbFileClose(sNetId := '', hFile := hDestFile, bExecute := TRUE, tTimeout := DEFAULT_ADS_TIMEOUT);
            fbFileClose;
        END_IF
        bStart := FALSE;
        Status := Standby;
    Error:
        IF (hDestFile <> 0) THEN
            fbFileClose(bExecute := FALSE);
            fbFileClose(sNetId := '', hFile := hDestFile, bExecute := TRUE, tTimeout := DEFAULT_ADS_TIMEOUT);
            fbFileClose;
        END_IF
        bError := TRUE;
        bStart := FALSE;
        Status := Standby;
END_CASE

Die damit erstellte Textdatei schaut dann so aus:

Code:

0
2
4
6
usw...

Warum wird nur jeder zweite Wert gespeichert?

Viewing all articles
Browse latest Browse all 47324


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>