csiki Member junior

Joined: 21 Aug 2015 Posts: 62 Location: Hungary
|
Posted: 19/10/2015 18:55 Post subject: SD/MM card ready for writing on an HMI device? |
|
|
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?
1 Create a script for a function with the following code:
For Windows-based devices:
| Code: | Function MediaCheckWin(ByRef path)
Dim fso, drive, result
Set fso= CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set drive=fso.GetDrive(fso.GetDriveName(fso.GetAbsolutePathName(path)))
If Err.Number=0 Then
result= 0
Else
result= Err.Number
End If
MediaCheckWin= result
End Function
|
For WindowsCE-based devices:
| Code: |
Function MediaCheckCE(ByRef path)
Dim fso, result
Set fso= CreateObject("Filectl.filesystem")
If fso.dir(path)="" Then
result= 1
Else
result= 0
End If
Set fso= Nothing
MediaCheckCE= result
End Function |
Note
The "result" return value can be changed to suit your requirements.
2 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).
Note
If you transfer the path as parameter via an input field, make sure that your input is accepted (press Enter key).
If you do not transfer the path as parameter, but define it in the script, then you set the path specification in quotation marks.
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
https://support.industry.siemens.com/cs/attachments/89855157/storage_media_status.zip |
|