Spinning up a CD Cleaner automatically for a set time

Use this forum to discuss about anything you want, post announcements and informational topics.
Forum rules
We have no special rules for UVK forums. Just try to be polite and clear in your posts.
Please don't post spam in this forum. Spammers will be banned by IP, e-mail and username.
We reserve the right to delete all posts and ban all users we consider not having respected these rules without warning.
Post Reply
Xander
Posts: 438
Joined: Sun May 24, 2015 11:55 pm
Contact:

Spinning up a CD Cleaner automatically for a set time

Post by Xander »

As a little "value added" service, I'm incorporating a cleaning of their oft-neglected CD drive as part of my setup and, obviously, I want to automate it. The disc basically just needs to spin for a minute to get the job done. It has audio tracks to walk you through it but, really, it just needs to spin for a bit to work.
I figured I'd use NirCMD to eject the tray to remind me to insert/remove the disc. If

So: Anyone know how to just get the drive to spin for a set period and do nothing else?


(This might be better off in Feature Requests but I can't imagine anyone else wanting this enough to merit adding a <SpinCDDrive> command into UVK.)
Charger440
Posts: 1529
Joined: Sun May 25, 2014 7:44 am
Location: Missouri

Re: Spinning up a CD Cleaner automatically for a set time

Post by Charger440 »

Xander,

You might could just eject the drive a couple times by code. Each time you enter a disk it spins for a few seconds to figure out what it is. Cycling the drive tray a couple times might do what you want.
Jim

It is not "Can it be done?" but rather, "How can we do it?"
Fred
Site Admin
Posts: 2357
Joined: Sat Jul 30, 2011 12:05 pm
Location: Red coast, France
Contact:

Re: Spinning up a CD Cleaner automatically for a set time

Post by Fred »

This works for me with an audio CD. I don't have any cleanup disk right now, but if I recall correctly they are audio CDs.
spincd.uvk
(3.91 KiB) Downloaded 184 times
Anyway, I never thought those cleanup disks do their job. I always ended up cleaning up the laser head myself.
One thing we humans have in common is that we are all different. So, if you think you're weird because you're different from everyone else, then we are all weird.

Fred
Xander
Posts: 438
Joined: Sun May 24, 2015 11:55 pm
Contact:

Re: Spinning up a CD Cleaner automatically for a set time

Post by Xander »

Wow. I certainly wasn't expecting a full script written for it. If I'd even suspected this could be done with a script, I'd have looked into it myself. (Now googling mcisendstring commands).

I'm going to see if I can adapt it into a GUI-less version to:
setaudio off (see? already learning), open CD tray, wait till it's closed, play for 30 seconds, eject/wait, setaudio on, exit.
Fred
Site Admin
Posts: 2357
Joined: Sat Jul 30, 2011 12:05 pm
Location: Red coast, France
Contact:

Re: Spinning up a CD Cleaner automatically for a set time

Post by Fred »

OK. That should be pretty easy. All you need is already in the script.

set cdaudio door open
sleep in chunks until "status cdaudio mode" is not "open"
play cdaudio from 1
sleep 30 secs
stop cdaudio
set cdaudio door open

Let me know if I can help with anything else.
One thing we humans have in common is that we are all different. So, if you think you're weird because you're different from everyone else, then we are all weird.

Fred
Xander
Posts: 438
Joined: Sun May 24, 2015 11:55 pm
Contact:

Re: Spinning up a CD Cleaner automatically for a set time

Post by Xander »

Got it working. About the only thing I'd change would be the MsgBox -- if I'm popping the CD in manually, I'm almost certainly give the tray a bump to close it. Could it auto-detect when the tray has closed?

Code: Select all

<UVKCommandsScript>
<AutoItScript>
Global Const $__HWINMM = DllOpen('Winmm.dll')
_mciSendString('set cdaudio door open')
SoundPlay(@WindowsDir & "\Media\Windows Exclamation.wav",0) ; audio cue
Msgbox("","","Insert Cleaning CD")
If _mciSendString('status cdaudio mode') = 'open' Then _mciSendString('set cdaudio door closed')
_mciSendString('play cdaudio from 9')
Sleep(30000)
_mciSendString('stop cdaudio')
SoundPlay(@WindowsDir & "\Media\Windows Exclamation.wav",0)
_mciSendString('set cdaudio door open') ;go ahead and leave the tray open
Exit

Func _mciSendString($command)
	Local $acall = DllCall($__HWINMM, 'DWORD','mciSendStringW', _
	'wstr',$command, 'wstr','', 'UINT',65535, 'HANDLE',Null)
	If @error Then Return SetError(1, 0, '')
	If $acall[0] Then Return SetError($acall[0], 0, '')
	Return $acall[2]
EndFunc ;==> _mciSendString
Charger440
Posts: 1529
Joined: Sun May 25, 2014 7:44 am
Location: Missouri

Re: Spinning up a CD Cleaner automatically for a set time

Post by Charger440 »

You'd have to use a timer and check for the closed state of the drive. Or, maybe the ready state.
Jim

It is not "Can it be done?" but rather, "How can we do it?"
Xander
Posts: 438
Joined: Sun May 24, 2015 11:55 pm
Contact:

Re: Spinning up a CD Cleaner automatically for a set time

Post by Xander »

Now with Wait-For-CD!

Code: Select all

<UVKCommandsScript>
<AutoItScript>

Global Const $__HWINMM = DllOpen('Winmm.dll')
_mciSendString('set cdaudio door open')
SoundPlay(@WindowsDir & "\Media\Windows Exclamation.wav",0) ; audio cue
While _mciSendString('status cdaudio mode') = 'open'
	Sleep(2500)
Wend

If _mciSendString('status cdaudio mode') = 'open' Then _mciSendString('set cdaudio door closed')
_mciSendString('play cdaudio from 9')
Sleep(30000)
_mciSendString('stop cdaudio')
SoundPlay(@WindowsDir & "\Media\Windows Exclamation.wav",0)
_mciSendString('set cdaudio door open') ;go ahead and leave the tray open
Exit

Func _mciSendString($command)
	Local $acall = DllCall($__HWINMM, 'DWORD','mciSendStringW', _
	'wstr',$command, 'wstr','', 'UINT',65535, 'HANDLE',Null)
	If @error Then Return SetError(1, 0, '')
	If $acall[0] Then Return SetError($acall[0], 0, '')
	Return $acall[2]
EndFunc ;==> _mciSendString
Fred, does the mcisendstring support a check for an empty tray? This way, if for some reason I want to skip this step, I could leave the tray empty and "if empty, Exit" ?
Charger440
Posts: 1529
Joined: Sun May 25, 2014 7:44 am
Location: Missouri

Re: Spinning up a CD Cleaner automatically for a set time

Post by Charger440 »

Xander I think you can use the disk ready state for that.
Jim

It is not "Can it be done?" but rather, "How can we do it?"
Xander
Posts: 438
Joined: Sun May 24, 2015 11:55 pm
Contact:

Re: Spinning up a CD Cleaner automatically for a set time

Post by Xander »

Hitting a dead end. Found "status cd media present" but if I push its contents to a MsgBox or to the clipboard, it comes back empty with or without a CD in the tray.
Maybe an easier option is to have it look for the Escape key while the tray is open with _IsPressed
Charger440
Posts: 1529
Joined: Sun May 25, 2014 7:44 am
Location: Missouri

Re: Spinning up a CD Cleaner automatically for a set time

Post by Charger440 »

Xander

See if this is of any use....

http://stackoverflow.com/questions/1142 ... -dvd-drive

This page says status cdaudio mode returns open with the tray open OR no disk in it.

http://www.developerfusion.com/thread/5 ... or-status/
Jim

It is not "Can it be done?" but rather, "How can we do it?"
Fred
Site Admin
Posts: 2357
Joined: Sat Jul 30, 2011 12:05 pm
Location: Red coast, France
Contact:

Re: Spinning up a CD Cleaner automatically for a set time

Post by Fred »

Xander, As Jim mentioned, the state returned by _mciSendString('status cdaudio mode') may not be accurate. For instance, if I close the tray without disc, it keeps returning 'open', forever.

To work around this, we can abort the operation if a disc is not inserted and the tray closed in, say, 2 minutes. We also set a timer for the case you remove the disc before the 30 seconds play time ends.

I also placed an error check for the case the disc can not be played from the specified position.
spincd.uvk
(2.11 KiB) Downloaded 179 times
One thing we humans have in common is that we are all different. So, if you think you're weird because you're different from everyone else, then we are all weird.

Fred
Xander
Posts: 438
Joined: Sun May 24, 2015 11:55 pm
Contact:

Re: Spinning up a CD Cleaner automatically for a set time

Post by Xander »

Thanks, Fred. That's a valid workaround.
Post Reply