gpt4 book ai didi

.net - 打开和关闭多个驱动器

转载 作者:行者123 更新时间:2023-12-02 03:49:53 25 4
gpt4 key购买 nike

我正在研究 DVD 刻录机器人。作为过程的一部分,我需要打开和关闭 DVD 托盘,让机器人在刻录后拾取光盘。但是我遇到了问题。我只能控制一台DVD刻录机的弹出!因为我有两个,所以这是一个问题。我已经看了这个小时了,无法弄清楚出了什么问题。它可以很好地控制 1 张 dvd,但是当我在另一个类上实例化它时它不起作用。这是下面的类(class)。我知道我可能遗漏了一些简单的东西,但我一辈子都弄不明白。

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

下课

最佳答案

我想我找到了解决办法。它是一个名为 cdrecord.exe 的命令行程序。通过向它发送命令行选项,打开和关闭托盘似乎没有问题!

关于.net - 打开和关闭多个驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14781874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com