How do you use a script to determine whether a storage drive with removable media (USB stick, SD/MM card) is ready for writing on an HMI device?
Data of an HMI project is to be stored user-triggered on a drive with removable media (USB stick, SD/MM card, etc.) when the system is running. A missing storage medium or a storage medium that is not ready to write can lead to errors in the procedure. You avoid this by checking the status of the drive before starting the write procedure.
Before the planned write procedure you call a function from a Visual Basic Script to check whether the drive is ready for writing. The return value contains the status of the drive based on which you can decide whether to continue or abort the write procedure.
Depending on the operating system used (Windows or WinCE), Visual Basic Script provides different methods for checking whether the removable drive is ready for writing.
|1||Create a script for a function with the following code: |
Call the MediaCheckWin() or MediaCheckCE() script each time before you run a write procedure to the medium concerned. As parameter you assign the script the path on which the file to be written is to be located, for example: "e:\" (Windows) or "\Storage Card USB\" (Windows CE).
|3||Depending on the return value you decide whether to continue the write procedure or abort it.|
The return value "0" means that the medium was ready for writing when tested; any other return value means that the medium was not ready for writing.
TIA Portal sample project KP400 Comfort / PC Runtime with integrated scripts
storage_media_status.zip (379.4 KB)
- Note that the scripts only recognize whether an interchangeable medium is available. If, for example, the medium is write-protected or there is no more memory available, the scripts still return the value "0".
- On Windows CE-based devices it might take a few seconds before the new status is recognized after removing or plugging an interchangeable medium.
Basic information on the topic of "Working with system functions and Runtime scripting" is available in the WinCC Professional V15 system manual in Entry ID 109755202.
General information about file operations when scripting with WinCC flexible and devices in Windows CE and Windows is available in entries 26107211 and 26106418.
MMC, MMC card, Flash drive, Memory stick, Memory card, Access, Readiness