2013-02-08 3 views
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 

End Class

+0

Немного больше информации. Я попытался повторно инициализировать класс в вызывающей функции и поразить каким-то странным поведением. Кажется, что первый диск я призываю, так сказать, к победе. Например, если я сначала звоню на E: диск, а затем попробую позвонить на F: диск, он все еще управляет диском e :. Его вроде windows mci не отпускает диск. – Robert

ответ

1

Я думаю, я нашел решение. Его программа командной строки cdrecord.exe. Отправляя ему вариант командной строки, у него нет проблем с открытием и закрытием лотков!

Смежные вопросы