Hack Forums
[C#] Controlling cd-rom motor - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Controlling cd-rom motor (/showthread.php?tid=5370224)



Controlling cd-rom motor - Mudzay - Aug 10, 2016

Hey, can someone tell me if its possible to control (change speed, start/stop) the cd-rom motor?
Thanks in advance :P


* - i-manuel - Aug 10, 2016

(Aug 10, 2016 10:13 AM)Mudzay Wrote:  Hey, can someone tell me if its possible to control (change speed, start/stop) the cd-rom motor?
Thanks in advance :P

lol i asked my teacher about that, he told me that it is not possible with .NET


* - Lor‌d - Aug 10, 2016

(Aug 10, 2016 10:29 AM)i-manuel Wrote:  lol i asked my teacher about that, he told me that it is not possible with .NET

Everything is possible.
I'm sure there's a dll out there somewhere or something.


* - Mudzay - Aug 10, 2016

(Aug 10, 2016 10:29 AM)i-manuel Wrote:  lol i asked my teacher about that, he told me that it is not possible with .NET
U can always make c++ etc. dll and call it from c# xD (I think its possible, windows dlls like wimm.dll are c or c++)


* - Oliver Sykes - Aug 10, 2016

You can open/close the tray from within c# easily. Not so sure about the speed, though.


* - еlixir - Aug 10, 2016

Code
public bool IsDiscAvailable(int driveNumber)
{
    MsftDiscMaster2Class discMaster = new MsftDiscMaster2Class();
    string id = discMaster[driveNumber];

    MsftDiscRecorder2Class recorder = new MsftDiscRecorder2Class();
    recorder.InitializeDiscRecorder(id);

    MsftDiscFormat2DataClass dataWriter = new MsftDiscFormat2DataClass();
    if (dataWriter.IsRecorderSupported(recorder))
    {
        dataWriter.Recorder = recorder;
    }
    else
    {
        Console.WriteLine("Recorder not supported");
        return false;
    }
    if (dataWriter.IsCurrentMediaSupported(recorder))
    {
        var media = dataWriter.CurrentPhysicalMediaType;
        if (media == IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN)
        {
            Console.WriteLine("Unknown media or no disc");
        }
        else
        {
            Console.WriteLine("Found disc type {0}", media);
            return true;
        }
    }
    else
    {
        Console.WriteLine("Disc absent or invalid.");
    }
    return false;
}

or

Code
using System;
using System.Management;

class Application
{
    public static void Main()
    {
        SelectQuery query =
            new SelectQuery( "select * from win32_logicaldisk where drivetype=5" );
        ManagementObjectSearcher searcher =
            new ManagementObjectSearcher(query);

        foreach( ManagementObject mo in searcher.Get() )
        {
            // If both properties are null I suppose there's no CD
            if(( mo["volumename"] != null) || (mo["volumeserialnumber"] != null))
            {
                Console.WriteLine("CD is named: {0}", mo["volumename"]);
                Console.WriteLine("CD Serial Number: {0}", mo["volumeserialnumber"]);
            }
            else
            {
                Console.WriteLine("No CD in Unit");
            }
        }

        // Here to stop app from closing
        Console.WriteLine("\nPress Return to exit.");
        Console.Read();
    }
}

The snippets above checks for a disk, causing the motor to run.

source:
http://stackoverflow.com/questions/11420365/detecting-if-disc-is-in-dvd-drive


* - 0xDEAD10CC - Aug 10, 2016

You would need to use IOCTL's for this. IOCTL_CDROM_SET_SPEED more specifically as the control code that you'd have to send to the CD-ROM class driver as a request of type CdromSetSpeed (from the CDROM_SPEED_REQUEST enum) in the RequestType memer of the CDROM_SET_SPEED struct. The buffer at Irp->AssociatedIrp.SystemBuffer would contain the CDROM_SET_SPEED structure. You wouldn't need to keep track of the previous speed either because when media is changed it will revert to it's default speed. From a user-mode application you would have to call DeviceIoControl() to send these requests.

(Aug 10, 2016 07:33 PM)еlixir Wrote:  ...

Yeah wonderful -- Not at ALL what OP asked for...