You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old September 6th, 2016, 05:49 AM   #1
SautauxT
Member
Switzerland

SautauxT is offline
 
Join Date: Sep 2016
Location: Neuchatel
Posts: 4
Create/Read File in Twincat 2

Hi!

First at all, I don't speak English very well so sorry for the faults

I'm new in the Twincat environnement and I have to do a little project for Philipp Morris during my studies.

I have a problem with a little sub-program that I've made.

I have to do a system who can measure the length of cigarettes and save all the results in the PLC's memory. For the program who saves the results, I tried to do like the Beckhoff example here:
https://infosys.beckhoff.com/english...leopen.htm&id=

The one from Beckhoff is a simple function block that copy some stuff, it works step by step with on Case OF,

I tried to do like this one but with two Case Of because I have one button who saves the results, and another one who can open the olds results

But it doesn't work well. The problem are:
- I can't open the files
- When I save something, the FB_FileOpen stay busy and I'm stuck in the step 2 of my case of


So here's the program who saves the results, tell me if you see some errors or if something is missing:


Variable

PROGRAM
Gestion_Fichier
VAR
Save_Array: BOOL:=FALSE; (*Trigger for saving*)
RTRIG_Save_Array: R_TRIG;
FileNameSave: STRING:='Batch'; (*Name of the new file*)
BatchID: STRING:='B00000';
hSavedFile: UINT;
Step_Save: INT:=0;


Open_Array: BOOL:=FALSE; (*Trigger for the opening of an old array*)
RTRIG_Open_Array: R_TRIG;
FileNameOpen: STRING:='Batch'; (*Name of the old file you want to open*)
BatchID_ToOpen: STRING:='B00000';
hOpenedFile: UINT;

Array_Opened: ARRAY [1..100] OF LREAL:=100(0); (*It's the target where I want the old opened array*)
Step_Open: INT:=0;

FB_FileOpen1: FB_FileOpen;
FB_FileWrite1: FB_FileWrite;
FB_FileClose1: FB_FileClose;
FB_FileOpen2: FB_FileOpen;
FB_FileRead2: FB_FileRead;
FB_FileClose2: FB_FileClose;
T_AmsNetId: T_AmsNetId:='5.24.113.50.1.1';
END_VAR

Programme
FileNameSave:= CONCAT('\Hard Disk\MesurePlug\', BatchID);
FileNameOpen:= CONCAT('\Hard Disk\MesurePlug\', BatchID_ToOpen);

RTRIG_Save_Array(CLK:=Save_Array);
RTRIG_Open_Array(CLK:=Open_Array);

CASE Step_Save OF

0:

IF RTRIG_Save_Array.Q THEN
FB_FileOpen1.bExecute:=FALSE;
FB_FileWrite1.bExecute:=FALSE;
FB_FileClose1.bExecute:=FALSE;
Step_Save := 1;
END_IF;

1:

FB_FileOpen1(
sNetId:= T_AmsNetId,
sPathName:= FileNameSave,
nMode:= FOPEN_MODEWRITE OR FOPEN_MODEPLUS,
ePath:= PATH_GENERIC,
bExecute:= TRUE,
tTimeout:= ,
bBusy=> ,
bError=> ,
nErrId=> ,
hFile=> hSavedFile);

Step_Save:=2;

2:
FB_FileOpen1.bExecute:=FALSE;

IF NOT(FB_FileOpen1.bBusy) THEN
FB_FileWrite1(
sNetId:= T_AmsNetId,
hFile:= hSavedFile,
pWriteBuff:= ADR(Mode_Auto.Arr_Temp),
cbWriteLen:= SIZEOF(Array_Opened),
bExecute:= TRUE,
tTimeout:= ,
bBusy=> ,
bError=> ,
nErrId=> ,
cbWrite=> );

Step_Save:=3;
END_IF;

3:

IF NOT(FB_FileWrite1.bBusy) THEN
FB_FileClose1(
sNetId:= T_AmsNetId,
hFile:= hSavedFile,
bExecute:= TRUE,
tTimeout:= ,
bBusy=> ,
bError=> ,
nErrId=> );

Step_Save:=0;
END_IF;
END_CASE;

(*Lecture fichier*)
CASE Step_Open OF
0:

FB_FileOpen2.bExecute:=FALSE;
FB_FileRead2.bExecute:=FALSE;
FB_FileClose2.bExecute:=FALSE;
IF RTRIG_Open_Array.Q THEN
Step_Open := 1;
END_IF;
1:


FB_FileOpen2(
sNetId:= T_AmsNetId,
sPathName:= FileNameOpen,
nMode:= FOPEN_MODEREAD OR FOPEN_MODEPLUS,
ePath:= PATH_GENERIC,
bExecute:= TRUE,
tTimeout:= ,
bBusy=> ,
bError=> ,
nErrId=> ,
hFile=> hOpenedFile);
Step_Open:=2;
2:
FB_FileOpen2.bExecute:=FALSE;
IF NOT(FB_FileOpen2.bBusy) THEN
FB_FileRead2(
sNetId:= T_AmsNetId,
hFile:= hOpenedFile,
pReadBuff:= ADR(Array_Opened),
cbReadLen:= SIZEOF(Array_Opened),
bExecute:= TRUE,
tTimeout:= ,
bBusy=> ,
bError=> ,
nErrId=> ,
cbRead=> ,
bEOF=> );

Step_Open:=3;
END_IF;
3:
FB_FileRead2.bExecute:=FALSE;
IF NOT(FB_FileRead2.bBusy) THEN
FB_FileClose2(
sNetId:= T_AmsNetId,
hFile:= hOpenedFile,
bExecute:= TRUE,
tTimeout:= ,
bBusy=> ,
bError=> ,
nErrId=> );

Step_Open:=0;
END_IF;
END_CASE;




Thank you if you can help me
  Reply With Quote
Old September 6th, 2016, 05:54 AM   #2
SautauxT
Member
Switzerland

SautauxT is offline
 
Join Date: Sep 2016
Location: Neuchatel
Posts: 4
Ho and I forgot to say something..
this is the PLC: CP6201-0001-0020
  Reply With Quote
Old September 6th, 2016, 08:27 AM   #3
Iman
Member
Iran

Iman is offline
 
Iman's Avatar
 
Join Date: Jul 2010
Location: Tehran
Posts: 170
Attach your logic (PRO)file. it is better for diagnosis
  Reply With Quote
Old September 6th, 2016, 09:05 AM   #4
SautauxT
Member
Switzerland

SautauxT is offline
 
Join Date: Sep 2016
Location: Neuchatel
Posts: 4
Yep of course, there it is
Attached Files
File Type: zip temp.zip (30.2 KB, 6 views)
  Reply With Quote
Old September 12th, 2016, 07:09 AM   #5
Berke84
Member
Belgium

Berke84 is offline
 
Join Date: Sep 2016
Location: Lummen
Posts: 2
Hi SautauxT,

Sorry, I didn't have the time to fully evaluate your PLC code but I do have a sample for this with a User Manual included. I've added it in a attachment

Good luck with it & best regards!

Bert
Attached Files
File Type: zip LogToFile.zip (294.8 KB, 23 views)
  Reply With Quote
Old September 12th, 2016, 11:00 AM   #6
SautauxT
Member
Switzerland

SautauxT is offline
 
Join Date: Sep 2016
Location: Neuchatel
Posts: 4
Hi!

I just found finally a solution to my problem but I'll have a look at your function Block, maybe it will work better with it.

Thank for all,

Best regards!

Thierry Sautaux
  Reply With Quote
Old September 15th, 2016, 01:39 PM   #7
ElGranMaikel
Member
Spain

ElGranMaikel is offline
 
Join Date: Sep 2016
Location: Bilbao
Posts: 1
Hi Thierry,

I am working with twincat 2 and I have the same problem as you, fb_fileopen just doesn't give me hFile. Would you mind telling me how did you solve the issue?

Thanks in advance,

Best regards,

Mikel Losada
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Codesys :How do i read all lines of text from a text file? EnterDownload LIVE PLC Questions And Answers 1 September 1st, 2015 02:11 PM
Factory Talk View Studio ME older .mer that doesnt allow conversion jtashaffer LIVE PLC Questions And Answers 13 April 25th, 2015 06:58 AM
RSLogix 500 Installation nagaraj_h LIVE PLC Questions And Answers 13 December 18th, 2014 08:11 PM
How to switch drivers lbeh LIVE PLC Questions And Answers 7 December 11th, 2014 03:11 PM
am i correct? excel & logix CSV communication. fusion LIVE PLC Questions And Answers 14 October 19th, 2005 07:18 PM


All times are GMT -5. The time now is 01:00 AM.


.