PDA

View Full Version : سوال: کار با usb و بررسی کانکت شدن یک دیوایس



ravaei
شنبه 06 دی 1393, 20:07 عصر
درود ، می خواستم ببینم چطور میشه بررسی کرد که آیا فلان نوع دیوایس وصل هست به pc یا نه ؟ منظورم از نوع اینه که مثلا گوشی آیفونه ، که ممکنه کاربر 4s وصل کنه یا 5 یا 5s یا... ولی اگه android یا هرچی دیگه وصل شد اعلام کانکتینگ نکنه.

می دونم این یه سوال کلیه و دنباله سورسش نیشتم می خواستم کمک کنید که با C#‎‎‎ چطور میتونم پیاده سازیش کنم؟؟

Mahmoud Zaad
شنبه 06 دی 1393, 20:51 عصر
سلام
ببین این نمونه (http://www.codeproject.com/Articles/60579/A-USB-Library-to-Detect-USB-Devices) بدردت می خوره. برای قسمت دوم یعنی نوع گوشی، احتمالا با آزمون خطا و آزمایش چند تا گوشی به جواب برسی.

ravaei
شنبه 06 دی 1393, 21:34 عصر
والا راستشو بخوای اینو خودمم دیدم ولی سر در نیاوردم !:متفکر:

ben-robot
شنبه 06 دی 1393, 22:57 عصر
سلام

اگر دستگاهی می خوای بسازی که کانکت شه به usbاز ایسی FT232استفاده کن

اگر می خوای هر وقت دستگاه وصل شد به usbخبر کنه شما رو


$DBT_DEVICEARRIVAL = "0x00008000"
$WM_DEVICECHANGE = 0x0219
GUICreate (https://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("")
GUIRegisterMsg (https://www.autoitscript.com/autoit3/docs/functions/GUIRegisterMsg.htm)($WM_DEVICECHANGE , "MyFunc")
Func (https://www.autoitscript.com/autoit3/docs/keywords.htm) MyFunc($hWndGUI, $MsgID, $WParam, $LParam)
If (https://www.autoitscript.com/autoit3/docs/keywords.htm) $WParam == $DBT_DEVICEARRIVAL Then (https://www.autoitscript.com/autoit3/docs/keywords.htm)
$dg = DriveGetDrive (https://www.autoitscript.com/autoit3/docs/functions/DriveGetDrive.htm)( "REMOVABLE" )
For (https://www.autoitscript.com/autoit3/docs/keywords.htm) $i = 1 to (https://www.autoitscript.com/autoit3/docs/keywords.htm) $dg[0]
$dt = DriveGetType (https://www.autoitscript.com/autoit3/docs/functions/DriveGetType.htm)( $dg[$i] )
If (https://www.autoitscript.com/autoit3/docs/keywords.htm) $dt = "REMOVABLE" And (https://www.autoitscript.com/autoit3/docs/keywords.htm) $dg[$i] <> "a:" And (https://www.autoitscript.com/autoit3/docs/keywords.htm) $dg[$i] <> "b:" Then (https://www.autoitscript.com/autoit3/docs/keywords.htm)
;;look for my marker file at $dg[$i] , if found do check...
MsgBox (https://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(4096,"Drive " & $i, $dg[$i] & " = " & $dt)
EndIf (https://www.autoitscript.com/autoit3/docs/keywords.htm)
Next (https://www.autoitscript.com/autoit3/docs/keywords.htm)
EndIf (https://www.autoitscript.com/autoit3/docs/keywords.htm)
EndFunc (https://www.autoitscript.com/autoit3/docs/keywords.htm)
While (https://www.autoitscript.com/autoit3/docs/keywords.htm) 1
$GuiMsg = GUIGetMsg (https://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
WEnd (https://www.autoitscript.com/autoit3/docs/keywords.htm)




توابع هایی API وجود دارن در کامپیوتر که اسم اونا در کد بالا نشون داده شده:لبخندساده:

ravaei
یک شنبه 07 دی 1393, 14:37 عصر
سلام

اگر دستگاهی می خوای بسازی که کانکت شه به usbاز ایسی FT232استفاده کن

اگر می خوای هر وقت دستگاه وصل شد به usbخبر کنه شما رو


$DBT_DEVICEARRIVAL = "0x00008000"
$WM_DEVICECHANGE = 0x0219
GUICreate (https://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("")
GUIRegisterMsg (https://www.autoitscript.com/autoit3/docs/functions/GUIRegisterMsg.htm)($WM_DEVICECHANGE , "MyFunc")
Func (https://www.autoitscript.com/autoit3/docs/keywords.htm) MyFunc($hWndGUI, $MsgID, $WParam, $LParam)
If (https://www.autoitscript.com/autoit3/docs/keywords.htm) $WParam == $DBT_DEVICEARRIVAL Then (https://www.autoitscript.com/autoit3/docs/keywords.htm)
$dg = DriveGetDrive (https://www.autoitscript.com/autoit3/docs/functions/DriveGetDrive.htm)( "REMOVABLE" )
For (https://www.autoitscript.com/autoit3/docs/keywords.htm) $i = 1 to (https://www.autoitscript.com/autoit3/docs/keywords.htm) $dg[0]
$dt = DriveGetType (https://www.autoitscript.com/autoit3/docs/functions/DriveGetType.htm)( $dg[$i] )
If (https://www.autoitscript.com/autoit3/docs/keywords.htm) $dt = "REMOVABLE" And (https://www.autoitscript.com/autoit3/docs/keywords.htm) $dg[$i] <> "a:" And (https://www.autoitscript.com/autoit3/docs/keywords.htm) $dg[$i] <> "b:" Then (https://www.autoitscript.com/autoit3/docs/keywords.htm)
;;look for my marker file at $dg[$i] , if found do check...
MsgBox (https://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(4096,"Drive " & $i, $dg[$i] & " = " & $dt)
EndIf (https://www.autoitscript.com/autoit3/docs/keywords.htm)
Next (https://www.autoitscript.com/autoit3/docs/keywords.htm)
EndIf (https://www.autoitscript.com/autoit3/docs/keywords.htm)
EndFunc (https://www.autoitscript.com/autoit3/docs/keywords.htm)
While (https://www.autoitscript.com/autoit3/docs/keywords.htm) 1
$GuiMsg = GUIGetMsg (https://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
WEnd (https://www.autoitscript.com/autoit3/docs/keywords.htm)




توابع هایی API وجود دارن در کامپیوتر که اسم اونا در کد بالا نشون داده شده:لبخندساده:

بله گزینهء 2 ، می خوام یه device با یه name خاص هروقت connect شد اطلاع بده ، ممنون میشم اگه یمقدار بیشتر در بارهء کد بالا توضیح بدی.

ben-robot
یک شنبه 07 دی 1393, 18:34 عصر
در واقع من رشتم کامپیوتر نیست:کف: اما از یه نرم افزار برنامه نویسی استفاده می کردم به نام autoitاین نرم افزار تمام APIهایی که در ویندوز وجود داره رو در قالب دستور معرفی کرده البته در

سی شارپ هم میشه اینا رو تعریف کرد کد هایی بالا رو چون مت کپی کردم این شکلی شده
http://www.autoitscript.com/forum/topic/105016-usb-device-detection-media-device/
به این لینک بروید و دستور هایی را که نوشته شده DLLاون رو پیدا کنید و با دستور importDLLاونو در C#ایجاد کنید