Jump to content

Download CSV from SD


Nacho

Recommended Posts

  • External Moderators

I know it's possible with the Advanced Web Server to download a file from the SD to the PC via web explorer. Now I have a finished application where the customer needs to download the CSV without use the SD Card Explorer. Copy and paste all the application to the .vlp with the embedded webserver is a task for titans but I don't know how to start to make a simple application to download a CSV. It will be about chunks...

Anyone can help me?

Project: A PLC with IP 192.168.1.201 and a CSV called test.

Download from internet explorer: http://192.168.1.201/EXCEL/TEST.CSV

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 years later...

Yeah.. That's not what i want.. I have a file that needs to be written to the sdcard. Because the software needs to be flexible i have to use the ipadres as part of the saving path. 9so for example: 192.168.1.16\SDcard\Excel. For me that's the easiest way.

The ip adres is selected by the user from a dropdown menu. If i need to use the .net driver, how could i do that? I didn't find anything in the documentation. 

Link to comment
Share on other sites

I've mentioned the .Net communication driver and its SD capabilities, since it gives you the ability to read and write files to the SD.\

 

This is what the SD Card Explorer uses. The SD Card Explorer is just a UI wrapper that manages things (like listing the files, handling the transfers and showing progress bars). The true API is inside the driver.

 

After you have a plc object (follow the .Net communication driver manual and examples, if you don't know how), that plc object has an SD property with a readfile and writefile methods, for example:

 

plc.SD.ReadFile(.....

Link to comment
Share on other sites

1 more question: 

Right now i got this code:

plc.SD.WriteFile(Sdfolder.EXCEL_EXCEL1, sDateTimePicker & ".xml", null)

I want to transfer the xml file to that folder on the sdCard. However, i notice that writefile can only write 1 byte? 

(my collegue is working on something to let the plc read .xml file's, if he doesnt succeed i'll try .udt.)

Link to comment
Share on other sites

Hi, it can write more than 1 byte. The function signature is:

public void WriteFile(SdFolder sdFolder, string fileName, byte[] fileContent, ProgressStatusChangedDelegate del)

 

The first parameter is the folder

the second one is the filename inside the plc (the target filename)

the third parameter is the content of the file (byte array... You should read the content of the original file)

The 4th parameter is the progress delegate.

Link to comment
Share on other sites

Ah okay. :) Thanks. 

Hmm, It looks like it's quite easy to save to UDT then as wel isn't it? 

Something like Public Void SaveToUDT(Sdfolder.EXCEL_EXCEL1, sDateTimePicker, dtverzenden) ?

dtverzenden is the datatable that contains the data that needs to be send to the plc. DatetimePicker contains the value used for the filename(so for example 10-10-1730 to indicate that it should be executed at 10 october at 30 minutes past 5. )

 

That way it's 2 flys in 1 hit(dutch proverb) because then it will save it on the plc's SD card and as the recommended UDT file.  

Link to comment
Share on other sites

Yes, it doesn't care what file is it, as long it follows the 8.3 filename standard.

You can write your own SaveToUDT that will save to file and then upload it the SD.

 

You might also be able to write an extension method. This will allow you to do (where dtverzenden is the Unitronics Data Table object):

dtverzenden.UploadToSD(Sdfolder.EXCEL_EXCEL1, sDateTimePicker)

Link to comment
Share on other sites

Thanks, 
Right now i got this:

first saving the UDT to the pc

Then uploading it to the plc.

 


 Dim fileContent As Byte()
        fileContent = System.IO.File.ReadAllBytes("c:\Voerkar\" & sDateTimePicker & ".udt")

 
SaveToUDT("C:\Voerkar\", sDateTimePicker, dtverzenden)
     
        plc.SD.WriteFile(Sdfolder.EXCEL_EXCEL1, sDateTimePicker & ".udt", fileContent, Nothing)
The savetoUDT is a C code i believe, and the dll documentation i have isn't saying anything about how it works in .net. 
I know(or atleast i think) i need the change the public void to a DIM, but as i need to declare it, can you help me further?
Link to comment
Share on other sites

Is the SaveToUDT a function you wrote?

(Because the only SaveToUDT function I know, accepts one parameter, which is a file path).

 

The SaveToUDT I know is written in C#, which is a .Net languages (the whole .Net communication driver and then Data Tables DLLs are written in .Net), and it compiles to IL code (So it doesn't matter if  you use C# or VB.Net... You can use those DLLs).

 

 

I'm not sure I understand the question.

Link to comment
Share on other sites

Is the SaveToUDT a function you wrote?

(Because the only SaveToUDT function I know, accepts one parameter, which is a file path).

 

The SaveToUDT I know is written in C#, which is a .Net languages (the whole .Net communication driver and then Data Tables DLLs are written in .Net), and it compiles to IL code (So it doesn't matter if  you use C# or VB.Net... You can use those DLLs).

 

 

I'm not sure I understand the question.

No, i took it from the documentation. But in there it uses public void. If i use it in front of the savetoudt part, i get the the error "End of statement expected" after the void.

Link to comment
Share on other sites

The documentation is outdated. The SaveToUDT accepts only 1 paremeter, which is the filename (it takes all the tables and saves them to a UDT file).

void in c# means that the function does not return anything.

In VB.net there is Function and there is Sub (where Sub is a function that does not return any result).

 

You should just call it like:

SaveToUDT("c:\hello.udt")

 

No need for Public or void...

Link to comment
Share on other sites

The documentation is outdated. The SaveToUDT accepts only 1 paremeter, which is the filename (it takes all the tables and saves them to a UDT file).

void in c# means that the function does not return anything.

In VB.net there is Function and there is Sub (where Sub is a function that does not return any result).

 

You should just call it like:

SaveToUDT("c:\hello.udt")

 

No need for Public or void...

Ah thanks :) That solved part of the problem. So i need to declare a function where the datatable will be saved to the pc and then call that function inside the part where the user actually presses Save? 

I loaded the Unitronics COM driver dll but that doesnt help recognize the SaveToUDT. 

Link to comment
Share on other sites

Hello,

 

Sure. I changed a couple of things and removed some specific forms for privacy reasons. but here it is. The saving functions are in the homescreens, the 2 buttons to the right. Right now im working with the save as xml button(the left one of the two). 

Code is a bit messy, but it is still a work in progress. I usually clean up the code after i'm done and leave the old code or info in commented lines so i can refer to it if something screws up. ;)

 

Edit: Filesize of total project is 1406 kb. So too much for the forum. The solution file is 1 kb, so i don't think you can work from  only that file. ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...