Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Trouble saving data to \Disk_mmc\ or \Disk_usb\

DanO
2007-07-30
2009-04-14
  • DanO - 2007-07-30

    I'm new to CoDeSys and I'm having problems saving an array within Global Memory to either the \Disk_mmc\ or \Disk_usb. In addition to the problem I'm having, I don't know what to expect the file format to be. Will it be in a Text Format, or will it only be readable by CoDeSys in a program. I'd like to have it in a Text, or Excel data format. But as for my problem, in both cases the Array appears to save (it saves the file name and returns the number of characters written), except that the Watchdog Timer times out and I don't know how to extend the time allowed during a the file save function. I think perhaps the SysWdgEnable function has something to do with that, but I haven't been able to find out how to use it. The same thing occures if I try to save a single variable value. How can I get past this issue??? The ST Code I'm using is as follows:

    FileSave Function:

    dwhdlFile:=SysFileOpen(Filename:=strFileName,Mode:='w');

    SysWdgEnable(bEnable := FALSE, byIECTaskIndex := 255, stIECTaskName := 0);

    dwCountOfCharacter := SysFileWrite(dwhdlFile,adrBuffer,dwBytes);

    SysWdgEnable(bEnable:=TRUE, byIECTaskIndex:=255, stIECTaskName := 0);

    blnFileError:=SysFileClose(File:=dwhdlFile);

    FileSave:=dwCountOfCharacter;

    PLC_PRG Segment to save data to file:

    IF Hour =24 THEN

    IF Download_Pulse = TRUE THEN
    
    x_mmc_path := TRUE;
    
    file_save :=TRUE;
    
    Download_Pulse := FALSE;
    
    END_IF
    
    IF Hour <> 24 THEN
    
    Download_Pulse := TRUE;
    
    END_IF
    

    END_IF

    (------------------- At the push of a button, Dumps retentive memory to a thumb drive ----------------------);

    IF USB_DownLoad AND Download_Pulse = TRUE THEN

    x_usb_path := TRUE;

    file_save :=TRUE;

    Download_Pulse := FALSE;

    END_IF

    IF USB_DownLoad = FALSE THEN

    Download_Pulse := TRUE;

    END_IF

    ( Build the filename)

    MoString := MonthToString [Month];

    YrString := YearToString [Year];

    FileName1stHalf := CONCAT (MoString, ' \ ');

    FileStringName := CONCAT (FileName1stHalf,YrString);

    IF x_usb_path = TRUE THEN

    Bytes_written:=0;

    x_mmc_path:=FALSE;

    s_path := '\DISK_USB\';

    END_IF

    IF x_mmc_path = TRUE THEN

    Bytes_written:=0;

    x_usb_path:=FALSE;

    s_path:='\DISK_MMC\';

    END_IF

    s_Filename := CONCAT (s_path, FileStringName);

    ( END of building Filename)

    IF file_save = TRUE THEN

    IF x_mmc_path =TRUE THEN

    Bytes_written:=FileSave(adrBuffer:=ADR(HrDayMo),strFileName:=s_Filename,dwBytes:=SIZEOF(Dummy_array_1));

    file_save:=FALSE;

    x_mmc_path:=FALSE;

    ELSIF x_usb_path = TRUE THEN

    Bytes_written:=FileSave( adrBuffer:=ADR(HrDayMo),strFileName:=s_Filename,dwBytes:=SIZEOF(Dummy_array_2));

    file_save:=FALSE;

    x_usb_path:=FALSE;

    END_IF

    END_IF

    The function produces error "#16 Watchdog expired for "Watchdog expired Task = DefaultTask""

    When I clear the error I get: "binFileError = INVALID: 16#10 "

     
  • Softwerker59 - 2007-08-07

    Hi Dan,

    the problem you have depends on the execution time of the file functions.

    SysFileOpen takes up to 100ms depending on open mode. SysFileWrite can take several 100ms depending on the buffersize.

    I suggest to execute the writing/reading of files in a separate task with a low priority and enough execution time. So you prevent the watchdog events.

    I've attached a sample program to demonstrate this. Please have a look at the task configuration. To prevent extended execution time the file handling works via state machine.

    You can watch the execution time in the PLC-browser using the "tsk"-command.

    I hope this helps.

    Klaus

    FileWriteExample.pro [31.57 KiB]

     
  • maauto - 2009-02-06

    Hello,

    I'm having the same problem with writing files (watchdog timeouts) so I found this post.

    The problem is that I don't have so much experience with Codesys and when I open the posted example I get an "Error while loacding the PLC configuration. Description file for 'Module.root' not found. Change configuration directory." and then if I contiue it says that it was not possible to find 2 of 3 libraries (SysLibFile.lib and Syslibcallback.lib).

    I have a fresh install of Codesys 2.3.9.7

    Is there any solution to this ?

     
  • Softwerker59 - 2009-02-09

    Hello,

    the example was written for a MOELLER plc. If you don't have installed the corresponding target you will get this error message.

    What targets do you use?

    Klaus

     
  • maauto - 2009-02-13

    Testing is done on Codesys SP RTE, however in the end it will probably be used on a Moeller XV panel / MXPro SoftPLC (that's where the flash write timeouts have been observed).

    I wanted to see the example, just to make sure what I was trying to do is correct...I've set up an additional task (besides PLC_PRG) that is called cyclically with a cycle of 200ms, has a priority of 31, and watchdog 300ms. It just checks if there is a "write flag" set and if it is then it starts the file write process, otherwise it just ends the call with a RETURN.

    This seems to be working, but I don't know if it's the correct way of doing things ?! My main concern is ... will the PLC_PRG task be able to interrupt the "writer" task even when it is performing some procedures as SysFileWrite and SysFileClose ?!?

     
  • Softwerker59 - 2009-02-17

    Hello,

    I've changed the attached project to target "Codesys SP RTE".

    Fileoperations extremely depends on the "plc load" and the amount of data to be transferred.

    The PLC_PRG task will always interrupt the lower priored writer task. Uncheck your watchdog and have a look at the task timing (plc browser "tsk" or include SysTaskInfo.lib). So you can check out the real time you need for the fileoperations.

    The best way for file handling is to use the library "SysLibFileAsync.lib" if your target supports this library.

    FileWriteExampleSPRTE.pro [32.61 KiB]

     
  • ndzied1 - 2009-02-17

    A few years ago I had tried to use a memory card to log data for a test system 100's of thousands of cycles. The writing was in its own task.

    What I found was that when I would keep opening the file for writing (append data) it would take longer and longer to open the file. I did not want to leave the file open so I didn't lose data in case the power dropped out.

    When it was problematic to keep opening the file for single records, I created a memory buffer that would only write every so many cycles. This helped but eventually the time required to open the file and move the pointer to the end became huge. This was on a Moeller XC200. s

    I have never gone back to see if later versions of the operating system made the open/append process faster.

    I just mention it so you can watch for this if you are trying to write a lot of data.

     
  • maauto - 2009-02-18

    Thank you very much for your help.

    I have one question about the example though....given the fact, that the WriteTask is being interrupted by the PLC_PRG anyway, is there really a need to subdivide the write process ? The only difference i can see (if the FileWrite PRG would not be subdivided) is that the one WriteTask cycle that would be active would also be much longer, but it shouldn't influence the PLC_PRG anyway.

     
  • Softwerker59 - 2009-02-20

    Hello,

    generally there is no need to subdivide the WriteTask. I've done this to give lower priored tasks time to run. Depending on the target and the open mode "Fileopen" or "Filewrite" can take several milliseconds (remember your watchdog problem). If you have a huge amount of data it is recommendable to subdivide the write process in this state machine too.

    regards

    Klaus

     
  • BernhardQ - 2009-04-14

    Hello

    I have one question about the example. I try to write Data to a connected PC but the test do not work. Which name was needed for Disk C:

    PROGRAM MAIN

    VAR

    fbOpenLogFile: INT;
    
    fbWriteLogFile: INT;
    
    fbCloseLogFile: INT;
    
    
    
    sLogDaten: STRING(255);
    
    sLogFilename: STRING := 'c:\test\logfile0000.txt';
    
    
    
    count1: UINT;
    
    count2: UINT;
    
    count3: UINT;
    
    count4: UINT;
    
    
    
    hFile: UINT;
    
    zLog: UINT := 0;
    
    
    
    Timer1: TON;
    
    
    
    bOpenFile: BOOL;
    
    bWriteData: BOOL;
    

    regards

    Bernhard

     

Log in to post a comment.