Back to top

Writing Data to the PDMM SD Card or Embedded Flash

This application note describes the process of writing data to the SD card or the embedded flash on the PDMM in .CSV (comma separated variable) format.  This is a general overview for writing data.  More read/write functions can be found in the KAS help section under File Management Functions.

Write Data to SD Card

Data logging with an SD card is used when a user wants to collect data from the PDMM, and then view this data on another computer.

Mount the SD card (Step 1)

Before any data transaction can take place, the SD card must be mounted.  To accomplish this, you would use the SD_MOUNT() instruction.  This instruction must be executed when a KAS program is running.  I would suggest executing SD_MOUNT() in a startup routine.

2015_03_05_22_32_492.png

Note: if you wish to remove the SD card you must first use SD_UNMOUNT() instruction to avoid file corruption.

Obtain a File ID (Step 2)

To obtain a File ID, you will need to use the F_AOPEN or F_WOPEN instruction (see File Management Functions in KAS help section for the difference between these 2 instructions). These functions will return a DINT as a File ID.

This instruction takes a string in as an argument.  This string should be the name of the file you wish to write to with a prefix of //SDCard/.  This file should have an extension of .csv.

2015_03_05_22_34_263.png

Write Data String (Step 3)

To write data to the SD you will need to do 2 things:

  1. Build a string with all the data needed to log, with a comma in between each piece of data
  2. Use a FM_WRITE instruction

To build a string, you need to use the CONCAT function.  Once you build your string, you can write to the SD card with the file ID.

2015_03_05_22_40_114.png

Note: Upon completion of the FM_WRITE instruction, it will return a bool value.  This value will be true if the instruction wrote the data, and false if it did not. It is a good suggestion to use this return value to implement error handling.

View Data (Step 4)

Remove the SD card from the PDMM and insert into SD reader. Warning! You must “unmount” the SD card before removing.

Entire Example Program (Step 5)

2015_03_05_22_41_555.png

Write Data to Embedded Flash

Data logging to the PDMM embedded flash memory can be used if the user does not have an SD card or is simply always connected to the system.

Logging to embedded flash is very similar to the SD card, except you do not need to mount the SD and you do not need the //SDCard/ prefix on the file name.

  1. Obtain a File ID

To obtain a File ID, you will need to use the F_AOPEN or F_WOPEN instruction (see File Management Functions in KAS help section for the difference between these 2 instructions).  These functions will return a DINT as a File ID.

2015_03_05_22_44_546.png

  1. Write Data String

This is the same as writing to the SD card.  Refer to step 3 in the Write Data to SD Card

  1. View Data

From your computer open the IE browser and type in the PDMM IP address.  Go to the User Data tab in the webserver.  Right click on the file and either open or save file to computer (see image below).

2015_03_05_22_47_127.png

  1. Entire Example Program

2015_03_05_22_56_581.png

Comments

Demero's picture
Demero
Hello,
I have question for this program. 
After starting the program, I see an error ('error writing to SD card') if "date1" = 11.

I use KAS 2.8. 
Where is problem? 
cwontrop's picture
cwontrop
Daniel, Please send your .kas program and IDE controller log to carroll.wontrop@kollmorgen.com for evaluation
Hayk Markaroglu's picture
Hayk Markaroglu
Hello Carroll;
I have another question. Is it possible to create a file and write data in a shared directory?
http://curvegen.kollmorgen.com/webhelp/kas/#6.UsingAKDPDMM/WebServer_SharedDir.htm?Highlight=shared%...
Thanks
Hayk
 
cwontrop's picture
cwontrop

Hello Hayk,

 

IF I understand your question (below) properly, yes it is possible to create a file and write data in a shared directory?


For more information:

http://curvegen.kollmorgen.com/webhelp/kas/#11.TechRefs/SharedDirPathConventions.htm

 

To create and open the file use the F_AOPEN function block:

http://curvegen.kollmorgen.com/webhelp/kas/#11.TechRefs/SharedDirPathConventions.htm