2013-02-08 4 views
3

DVD 굽기 로봇 작업 중입니다. 이 과정의 일부로 DVD 트레이를 열고 닫아서 로봇이 굽기 작업 후에 디스크를 집어 올릴 수 있도록해야합니다. 그러나 나는 문제에 부딪쳤다. 하나의 DVD 레코더에서만 꺼내기를 제어 할 수 있습니다! 두 가지가 있기 때문에 이것이 문제입니다. 나는 이것을 한 시간 동안보고 있었고 무엇이 잘못되었는지를 알 수 없다. 그것은 1 개의 DVD 벌금을 통제 할 수있다. 그러나 내가 다른 학급에서 그것을 instatiate 할 때 그것은 작동하지 않는다. 아래에 클래스가 있습니다. 나는 아마 내가 간단한 것을 놓치고 있다는 것을 압니다. 그러나 저의 삶을 위해 나는 그것을 이해할 수 없습니다.여러 드라이브 열기 및 닫기

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 

최종 클래스

+0

조금 더 자세한 정보. 호출 함수에서 클래스를 다시 초기화하고 일부 이상한 동작을 시도했습니다. 내가 말하는 첫 번째 드라이브가 이기기 위해 전화를하는 것 같습니다. 예를 들어, 먼저 E : 드라이브를 호출 한 다음 F : 드라이브를 호출하여 E : 드라이브를 계속 제어합니다. 그것의 창문처럼 mci는 드라이브를 놓아주지 않습니다. – Robert

답변

1

은 내가 해결책을 찾은 것 같아요. 이 프로그램은 cdrecord.exe라는 명령 행 프로그램입니다. 명령 줄 옵션을 보내면 트레이를 열고 닫는 데 아무런 문제가없는 것 같습니다!