Redlion G306 writing file data to CF

burnerman

Member
Join Date
Nov 2005
Location
Huddersfield
Posts
212
I didn't have much time to check this today but I'd like to complete this job tomorrow morning.

Following a batch process I trigger a program that creates a string comprising several items of data with comma seperators in between.

In the same program I then want to write that string to the next line in a file and then send that file to a PC (overwriting the previous version of that file) using the FTP server.

So far I've got the generation of the string working fine as I have a test page where I can view the string created and view the value of the integer 'bytes_written' (I never saw a value other than zero). After that the program should write the string to the relevant file on the CF card (which is mounted OK) but it doesn't seem to be writing anything to the file.


My code is like this:

int cfile;
cfile=OpenFile(file_path,1);
bytes_written:=WriteFileLine(cfile,file_data);
CloseFile(cfile);


where 'file_path' is a string variable, say, "/logs/reports/machine1.csv" and 'file_data' is the string that I created.


Once I get this part working then I will put a further line in the program like this to send the file to the pc:

FtpPutFile(0,file_path,"c:/reports/machine1.csv",0);

Will this ovewrite a previous version of c:/reports/machine1.csv ?


My thoughts as to why it might not be writing to the CF card are:

A. at the time of testing I was connected to the G306 via USB - does this prevent any writing to the CF by the program because the PC is accessing the CF?

or

B. Delays (and/or proof of actions completed) are required between actions such as opening, writing to and closing the file (and subsequently sending the file to the pc).



Does anyone have any experience with this and point me in the right direction.

Thanks
 
Last edited:
Just a different View

Why don't you just use the data log function. It can be triggered by either time or event.

Once you have this configured then you can have your PC grab the file and dump it where you want.
 
The drawback to using the built in logger is that you can't control the filename. The advantage (for fast logging) is that it uses caching to avoid excessive write cycles to the CF card, and you don't have to write and debug your own code.

I have done custom logging similar to what burnerman has, but I did not use the exact same instructions. I eventually switched to the built in logger to greatly reduce the number of write cycles since I am logging about 10,000 items per day on that system.

BurnerMan:
Are you sure that you are successfully creating the directory and file first?

I used a create directory command and a create file command before trying to open the file. I created a new file once per day:

Code:
int result;
int success;
//create a directory with a new name for today's data
LOG_Number=LOG_Number+1;
if(LOG_Number>999) LOG_Number=0;
//
LOG_Name=AsText(LOG_Number);	
result:=CreateDirectory(LOG_Name);

//create a file in this new directory

LOG_File_Name="/"+LOG_Name+"/DATA.csv";
success:=CreateFile(LOG_File_Name);

Then I had a separate program with code to open, append, and close the file. That code used the WriteFile and WriteFileLine instructions just like you have. I did write a numeric tag using its .AsText property, not the integer value itself.

My tags for the Log_name and Log_Number were C3 tags (not local to the program) so they could easily be used among different programs.
 
Last edited:
Clay B said:
Why don't you just use the data log function. It can be triggered by either time or event.

Once you have this configured then you can have your PC grab the file and dump it where you want.

Funnily enough, this is a solution I thought of myself tonight although I wasn't sure if I could log just one set of data on an event. And I would like the G306 to send the file to the pc as soon as it's generated rather than doing anything fancy in the pc to upload files.

Okie PC said:
Are you sure that you are successfully creating the directory and file first?
Yes, forgot to mention that. I have a page where I can enter filenames, paths, etc. and create directories and files. I created the required path/file and checked is was there in the F: drive on my laptop when connected via USB.

So theres no issue with opening, writing and closing as sequential instructions in a program? I had assumed that the next line would not be executed until the preceding one had finished it's task but I did just wonder that I may be wrong (it has happened before!)
 

Similar Topics

Hi, I have a Redlion G306 and its GSM Modem add on which I have successfully managed to send and receive texts from. I'm interested to know...
Replies
0
Views
2,164
Hello masters, I have a trouble, I need change the IP for ML1400, I have a program with download the results with archive csv, but the program it...
Replies
1
Views
2,957
I have a G306 hmi I have tried to upgrade from a panelview 600 on an existing line that is connected to a SLC 5/03. I have had succuess for the...
Replies
7
Views
2,579
Hi all I just upgraded our G306 to a bigger G310 display. The G310 just will not serve a web page to the Internet. I can see it on the LAN...
Replies
2
Views
2,223
HI, As you can see from my name ! I am struggling ! I am trying to get my SLC 5/03 talking to and working with my RED LION G306 Hmi. I have...
Replies
2
Views
4,288
Back
Top Bottom