3
我正在研究DVD刻录机器人。作为该过程的一部分,我需要打开和关闭DVD托盘,以便机器人在刻录后拾取磁盘。但是我遇到了一个问题。我只能控制一台DVD刻录机弹出!由于我有两个这是一个问题。我一直在看这个小时,并不知道有什么问题。它可以控制1 DVD,但是当我在另一个类上安装时它不起作用。这是下面的课程。我知道我可能错过了一些简单的事情,但对于我的生活我无法弄清楚。打开和关闭多个驱动器
Public Class openCloseDrive
'Api call to send the commands to the mci device
Private Declare Function mciSendString Lib "winmm.dll" Alias _
"mciSendStringA" (ByVal lpstrCommand As String, ByVal _
lpstrReturnString As String, ByVal uReturnLength As Integer, _
ByVal hwndCallback As Integer) As Integer
'
'Api call to check for mci success or error
Private Declare Function mciGetErrorString Lib "winmm.dll" Alias _
"mciGetErrorStringA" (ByVal dwError As Integer, ByVal lpstrBuffer _
As String, ByVal uLength As Integer) As Integer
'will hold the mci return value
Dim retVal As Integer = Nothing
'This will contain the drive letter of the specified cd drive.
Dim _cdDrive As String = Nothing
Public Sub New(_driveLetter As String)
_cdDrive = Chr(34) & _driveLetter & Chr(34)
End Sub
Public Function Open() As Integer
'This will open the DVD Tray
Dim retVal As Integer
'This will Open the CD Drive Tray.
mciSendString("open " & _cdDrive & " type cdaudio alias cd wait shareable", 0, 0, 0)
retVal = mciSendString("set cd door open", 0, 0, 0)
Return retVal
End Function
Public Function Close() As Integer
'this Will close the DVD tray
Dim retVal As Integer
'This will Close the CD Drives Tray door.
mciSendString("open " & _cdDrive & " type cdaudio alias cd wait shareable", 0, 0, 0)
retVal = mciSendString("set cd door closed", 0, 0, 0)
Return retVal
End Function
Public ReadOnly Property devices_InternalMCIStatus() As String
'
'Check the mci device to see if a error occured, and/or give
'some type of description even if everything was executed ok.
'
'Use this property if you want to, after each command you carried
'out to check and see if the command was successfully executed or
'not. It will tell you the status whether it was successful or not.
'
Get
'
'Make the length of this buffer 255 spaces since the returned
'value could get pretty long, depending on what is going on.
Dim buf As String = Space(255)
mciGetErrorString(retVal, buf, 255)
Return buf
buf = Nothing
End Get
End Property
末级
更多信息。我试图在调用函数中重新初始化类,并碰到一些奇怪的行为。可以这么说,我看到的第一个驱动器就是赢得胜利。例如,如果我先打电话给E:驱动器,然后尝试调用F:驱动器,它仍然控制着e:驱动器。它就像windows mci不会放开驱动器。 – Robert 2013-02-09 03:05:43