CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version Spanish version French version
It is currently Thu Oct 30, 2014 11:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Mon Jul 30, 2007 10:07 pm 
Offline

Joined: Tue Jun 12, 2007 4:53 am
Posts: 5
Location: Tacoma, WA
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 ***"

_________________
Dan in Tacoma


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 12:03 pm 
Offline

Joined: Fri Aug 25, 2006 10:33 am
Posts: 8
Location: Bad Honnef
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


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 1:36 pm 
Offline

Joined: Thu Sep 18, 2008 1:31 pm
Posts: 24
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 ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2009 4:50 pm 
Offline

Joined: Fri Aug 25, 2006 10:33 am
Posts: 8
Location: Bad Honnef
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2009 8:04 am 
Offline

Joined: Thu Sep 18, 2008 1:31 pm
Posts: 24
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 ?!?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 1:54 pm 
Offline

Joined: Fri Aug 25, 2006 10:33 am
Posts: 8
Location: Bad Honnef
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.


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 2:00 pm 
Offline
Frequent User
Frequent User

Joined: Fri Dec 23, 2005 7:36 pm
Posts: 145
Location: Chicago, IL USA
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.

_________________
nOrM
=====
nOrM = Norman Dziedzic Jr.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 10:20 am 
Offline

Joined: Thu Sep 18, 2008 1:31 pm
Posts: 24
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2009 10:30 am 
Offline

Joined: Fri Aug 25, 2006 10:33 am
Posts: 8
Location: Bad Honnef
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 14, 2009 8:44 am 
Offline

Joined: Sun Mar 15, 2009 12:24 pm
Posts: 1
Location: Cloppenburg
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group