Hello,
I am trying to control a CD-ROM drive using python. The code I use is
shown below.
The code that calls the class is a follows:
This works great, but only when there is a disk inside, otherwise we get
an error.
My issue is that I need to be able to eject the CDROM tray even if there
is no disk inside.
This is possible because other programs (like the linux "eject" command)
can do it. Its just a question of how it is done in python. So I'm
posting here in the hope someone can tell me.
Thanks,
Ognjen
I am trying to control a CD-ROM drive using python. The code I use is
shown below.
import CDROM
from fcntl import ioctl
import os
>
>
class Device:
>
CDdevice=""
CDfd = None
>
def __init__(self,n ame):
self.CDdevice = name #we get a device name when module loaded
>
if self.CDdevice == "":
print "No device specified"
sys.exit(-1)
self.openCD()
>
def openCD(self):
>
try:
self.CDfd = open(self.CDdev ice, 'r') #open the device and return filedescriptor
>
except(OSError, IOError): #if there is an OS or IO Error (usually indicates nodisk)
print "Device Error, Halting.... (usually means drive or disk not found)"
sys.exit(-1)
from fcntl import ioctl
import os
>
>
class Device:
>
CDdevice=""
CDfd = None
>
def __init__(self,n ame):
self.CDdevice = name #we get a device name when module loaded
>
if self.CDdevice == "":
print "No device specified"
sys.exit(-1)
self.openCD()
>
def openCD(self):
>
try:
self.CDfd = open(self.CDdev ice, 'r') #open the device and return filedescriptor
>
except(OSError, IOError): #if there is an OS or IO Error (usually indicates nodisk)
print "Device Error, Halting.... (usually means drive or disk not found)"
sys.exit(-1)
> def unlockCD(self):
return self.sendCDcomm and(CDROM.CDROM _LOCKDOOR,0)
return self.sendCDcomm and(CDROM.CDROM _LOCKDOOR,0)
def ejectCD(self):
self.unlockCD() #we need to unlock the CD tray before we try to eject, otherwise we get an IO Error (#5)
return self.sendCDcomm and(CDROM.CDROM EJECT)
>
self.unlockCD() #we need to unlock the CD tray before we try to eject, otherwise we get an IO Error (#5)
return self.sendCDcomm and(CDROM.CDROM EJECT)
>
def sendCDcommand(s elf,command,arg ument=''):
return ioctl(self.CDfd ,command,argume nt)
>
return ioctl(self.CDfd ,command,argume nt)
>
The code that calls the class is a follows:
import CD_Bindings
>
CD = CD_Bindings.Dev ice("/dev/cdrom")
>
print CD.ejectCD()
>
CD = CD_Bindings.Dev ice("/dev/cdrom")
>
print CD.ejectCD()
an error.
My issue is that I need to be able to eject the CDROM tray even if there
is no disk inside.
This is possible because other programs (like the linux "eject" command)
can do it. Its just a question of how it is done in python. So I'm
posting here in the hope someone can tell me.
Thanks,
Ognjen
Comment