Saving a Data Block into a txt file in every cycle

ajaysharma

Member
Join Date
Dec 2011
Location
darmstadt
Posts
11
Hello all,

I need your help to understand, How can I save values in DB to a Txt file in each cycle.


Hardware used: CPU317F-2 PN/DP
HMI: MP 377, 12" Touch

I understood that I can use vb script to do this. Can anyone please provide me an example.

The sequence is as follows:

- Do a operation and record the data
- Process data recorded in a DB100
- Copy and move the DB into a excel file or CSV
-If possible, I would like to save the data in the same CSV file with maximum 1000 lines
-Clear the DB after each Cycle

Please let me know if more information is required.

Thanks for the help.

regards
Ajay
 
I'd recommend using a Data Log in the HMI, and logging the tags. f you want to do event based logging, instead of cyclic logging, you'll have to trigger it based on some tag or button.

I don't have an example, but take a look at logging in your HMI and the system functions related to it.

One question you'll have to ask yourself is "where do I want the files created/stored, and how do I need to access/use them?"
 
At every cycle? hmm going to eat up some resources....
I'd tend to save on change of data only.
Easy enough to copy the db and compare and then trigger a tag in the event of any change which can be used for the export
You state every cycle...i'm guessing to mean machine cycle rather than processor cycle?
I'd also go along with using the HMI to do the data export.
 
At every cycle? hmm going to eat up some resources....
I'd tend to save on change of data only.
Easy enough to copy the db and compare and then trigger a tag in the event of any change which can be used for the export
You state every cycle...i'm guessing to mean machine cycle rather than processor cycle?
I'd also go along with using the HMI to do the data export.




Thanks.. for the reply.

Sorry for the error, when I say every cycle it means the every machine cycle only. For every part the data is different and I am looking to save the data in a CSV file fro every part.

Please see the image and example text file.

[/QUOTE]I'd also go along with using the HMI to do the data export.[/QUOTE]

Could you please Provide an example?? How can I do this?

regards
Ajay

example.png
 

Attachments

  • Example.txt
    313 bytes · Views: 15
Hello All,

Working on the above problem, I wrote the below Script for MP377 Pannel.

But the code is executing without providing me an output. There was no file generated on the HMI.
Can someone help me with this?

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''CREATE A FILE WITH NEW RESULT '''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


Dim fo,FS, Path, Dataformat, file
Dim delimiter
Dim mode
Dim gap
Const NEU = 0
Dim csv
Dim Applicaiton ,WriteMethod
'Appeniding is used
mode = 8
delimiter=" ;"
gap = vbTab
csv = 1

'********************************************
'Code starts here
'*****************************************


'Path = " \Storage Card CF \TESTFILE.TXT"
'Path = " \flash \TESTFILE.TXT"

Path = "\STORAGE CARD USB\ CARTDIAL-curve "
file = " \STORAGE CARD USB\ CARTDIAL-curve\TESTFILE.TXT"



On Error Resume Next

'CREATE A FILE SYSTEM OBJECT

Set FS = CreateObject("filectl.filesystem")

'Create a file object

Set fo = CreateObject("FileCtl.File")

'Check if there is any error

If Err.Number <>0 Then
ShowSystemAlarm "Error#"& CStr(Err.Number) & "" & Err.Description
Err.Clear
Exit Sub
End If

'Check for the Director
If (FS.Dir(Path)<>"") Then FS.MKDIR(Path)

if fo.LOF = Neu then

'Open or Create a File
fo_Open file, 8

'Wrting the Header
fo.LINEPRINT ( "Date" & gap & delimiter & "Part Id:" & gap & delimiter & "PeakForce" & gap & delimiter & "PeakForce Position" & gap & delimiter &_
"FinalForce " & gap & delimiter & "TransitionForce" & gap & delimiter & "S6.TransitionForceServoPostion"_
& gap & delimiter &"SmallDiaStartForce" & gap & delimiter& "SmallDiaStartPosition"& gap & delimiter &_
"SmallDiaEndPointForce"& gap & delimiter & "SmallDiaEndPointPositon" )

'write actual Data
fo.LINEPRINT( Now & gap & delimiter & SmartTags( "S6 CurrentETR.Data.PartID") & gap & delimiter & SmartTags( "S6.PeakForce") & gap & delimiter & SmartTags( "S6.PeakForcePostion" )& gap & delimiter &_
SmartTags("S6.FinalForce ") & gap & delimiter & SmartTags("S6.TransitionForce ") & gap & delimiter &SmartTags( "S6.TransitionForceServoPostion")_
& gap & delimiter & SmartTags("S6.smallDiaStartForce ") & gap & delimiter& "S6.smallDiaStartPosition"& gap & delimiter &_
"S6.SmallDIaENdForce"& gap & delimiter & "s6.SmallDIaENdForceServoPosition" )
If Err.Number <>0 Then
ShowSystemAlarm "Error#"& CStr(Err.Number) & "" & Err.Description
Err.Clear
Exit Sub
End If
'Close the file
fo.close

Else

If Err.Number <>0 Then
ShowSystemAlarm "Error#"& CStr(Err.Number) & "" & Err.Description
Err.Clear
Exit Sub
End If

'Open or Create a File
fo_Open file, 8

'Write Data into the File
fo.LINEPRINT( Now & gap & delimiter & SmartTags( "S6 CurrentETR.Data.PartID") & gap & delimiter & SmartTags( "S6.PeakForce") & gap & delimiter & SmartTags( "S6.PeakForcePostion" )& gap & delimiter &_
SmartTags("S6.FinalForce ") & gap & delimiter & SmartTags("S6.TransitionForce ") & gap & delimiter &SmartTags( "S6.TransitionForceServoPostion")_
& gap & delimiter & SmartTags("S6.smallDiaStartForce ") & gap & delimiter& "S6.smallDiaStartPosition"& gap & delimiter &_
"S6.SmallDIaENdForce"& gap & delimiter & "s6.SmallDIaENdForceServoPosition" )

'Close the File
fo.close

End If
'


''Release the fileobject
Set fo = Nothing


'ShowSystemAlarm "Storage of the data was successful!"
SmartTags ("CreateCurveAnalysisDataRev01")= False

ShowSystemAlarm "File Saved in the Location" & Path



thanks for the help

ajay
 
Last edited:

Similar Topics

It has been a while since I used RSLogix 5000. Is there a way for me to save data in excel, notepad, etc?? I want data to be saved when a user...
Replies
4
Views
1,780
Hi, I have a system that creates a text file that is comma delimited and it works great...in the US. I installed it on a computer in Germany and...
Replies
2
Views
1,917
I'm using a 1769-L16ER-BB1B. I'm storing recipe data in an array of user-defined data types. For disaster recovery purposes, I need to make sure...
Replies
12
Views
8,861
Simple question, is there any way of saving Function Block Output values on power down in Alpha2? Or more general question, is there any way of...
Replies
1
Views
1,570
Hi everyone, I have to modify a program that has been running in the field for several weeks now. I would like to be able to save the tag data...
Replies
7
Views
6,537
Back
Top Bottom