How to check if USB or SD are actually inserted and OK
How to check if USB or SD are actually inserted and OK
Before writing something into external memory we, probably, must be sure that they are inserted and ready. How to do it by script?
Regards, Waldemar
Regards, Waldemar
-
- Posts: 824
- Joined: Tue Mar 13, 2012 9:53 am
Re: How to check if USB or SD are actually inserted and OK
You can try and write your data to the USB card, and then use a try catch block to catch the error that will occur if the USB card is not inserted.
C# try-catch
C# try-catch
Best Regards,
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer
Re: How to check if USB or SD are actually inserted and OK
You can also use the Directory.Exists method.
http://msdn.microsoft.com/en-us/library ... s.90).aspx
But even if you use this method, you should still have a try catch block when you open the file.
http://msdn.microsoft.com/en-us/library ... s.90).aspx
But even if you use this method, you should still have a try catch block when you open the file.
Best Regards,
Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer
Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer
-
- Posts: 22
- Joined: Fri May 25, 2012 7:44 am
- Location: Charlotte, NC. USA
Re: How to check if USB or SD are actually inserted and OK
The Directory.Exists Method is the one I use. Make sure you add a using to the script code.
Or possibly as public properties in the Tags script, or in a custom ScriptModule for global access if you like.
I have not tested to see what directories are created (if any) on devices other than WinCE HMI's I know that those directories do not exist when you Simulate or Run HMI code on the developing PC so it might be worth your effort to include a check to see if the executing device is actually a WinCE target.
And from that substitute paths or drives which are to be checked accordingly.
Code: Select all
using System.IO;
Code: Select all
bool UsbPresent = Directory.Exists("\\Hard Disk");
bool SDCardPresent = Directory.Exists("\\Storage Card");
Code: Select all
public bool UsbPresent {
get {
return Directory.Exists("\\Hard Disk");
}
}
public bool SDCardPresent {
get {
return Directory.Exists("\\Storage Card");
}
}
Code: Select all
public bool IsWinCE {
get {
return Environment.OSVersion.Platform == PlatformID.WinCE;
}
}
Best Regards,
Patrick Hall
Patrick Hall
Re: How to check if USB or SD are actually inserted and OK
Thank You very much for the help. I want to write a script which will write to an external memory (SD or USB, depending what is available) the information about finished process.
What is the difference between ("Storage Card")
and ("\\Storage Card")?
Regards, Waldemar
What is the difference between ("Storage Card")
and ("\\Storage Card")?
Regards, Waldemar
-
- Posts: 824
- Joined: Tue Mar 13, 2012 9:53 am
Re: How to check if USB or SD are actually inserted and OK
You can think of \ as the root directory in Windows CE. The first "\" is required because in C# "\" is a special character and will not be interpreted as a character. So one "\" means escape the next character.
Is you were to print "\\" on a screen using C# you would only see "\" printed on the screen.
Is you were to print "\\" on a screen using C# you would only see "\" printed on the screen.
Best Regards,
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer
Re: How to check if USB or SD are actually inserted and OK
Thank You very much for the help.
I tried Directory.Exists(). Works fine. Did not check othe other options. When they are preferable?
Regards, Waldemar
I tried Directory.Exists(). Works fine. Did not check othe other options. When they are preferable?
Regards, Waldemar
Re: How to check if USB or SD are actually inserted and OK
A try/catch block is your insurance against an attempt to open a file and have it fail. Without the tray/catch block, if you try to access a file that doesn't exist and it fails the application will display a message and close.
Best Regards,
Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer
Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer
Re: How to check if USB or SD are actually inserted and OK
Hello
i try to gain access to USB or SD through FTP but the projekt folder on SD ,USB have not show me. Could you send me projekt T4A where can I have access on USB and SD through FTP.
Many Thanks
JohnCZ
i try to gain access to USB or SD through FTP but the projekt folder on SD ,USB have not show me. Could you send me projekt T4A where can I have access on USB and SD through FTP.
Many Thanks
JohnCZ
-
- Posts: 824
- Joined: Tue Mar 13, 2012 9:53 am
Re: How to check if USB or SD are actually inserted and OK
You can not access the USB or SD card through FTP. Only the data in the project files folder is accessible through FTP.
Best Regards,
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer