Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
* * * * * 1 votes

Cd unit open and close program

machine hardware programing project robot easy

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1 brainiac080195

brainiac080195

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 17 April 2013 - 01:16 AM

i have no idea in which programing language can this be done, so i am posting it here.

 

Ok i am making a really simple robot from computer components. I need a program that will open and close cd units in a time period of 5 seconds. There will be 2 cd units. So my idea is to make a program that will open the cd unit then keep it opened for 5 sec and then close it. I can sort this out with hardware accessories some electrical timers. But i want to see if i can keep it single with a program. It should run on windows xp platform.

Thanks in advance, if u need more information please PM me. P.S It is URGENT!

 



#2 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts

Posted 17 April 2013 - 09:04 AM

I found some information on doing this in C# here:
http://www.codeproje...e-CD-drive-in-C

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3 brainiac080195

brainiac080195

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 25 April 2013 - 11:56 AM

this is what i came up with. Test button isn't working btw.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [System.Runtime.InteropServices.DllImport("winmm.dll", EntryPoint = "mciSendStringA")]
        public static extern void mciSendStringA(string lpstrCommand, string lpstrReturnString, long uReturnLength, long hwndCallback);

        

        string rt = "";


        private void button1_Click(object sender, EventArgs e)
        {            
            timer1.Interval = 1000 * 5; //timer to open first and close second 
            timer1.Enabled = true;
            timer1.Start();
            timer2.Interval = 1000 * 5; //revers timer
            timer2.Enabled = true;
            mciSendStringA("open D: type CDAudio alias driveD", rt, 127, 0); //defining driver
            mciSendStringA("open E: type CDAudio alias driveE", rt, 127, 0); 
        }

        private void button2_Click(object sender, EventArgs e)
        {            
            //test button

            mciSendStringA("set driveF door open", rt, 127, 0);
            MessageBox.Show("Radi li");
        }       

        
        private void timer1_Tick(object sender, EventArgs e)
        {
            //open first close second
            mciSendStringA("set driveE door closed", rt, 127, 0);
            mciSendStringA("set driveD door open", rt, 127, 0);
            //MessageBox.Show("start");
            timer1.Stop();
            timer2.Start();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            //open second close first
            mciSendStringA("set driveD door closed", rt, 127, 0);
            mciSendStringA("set driveE door open", rt, 127, 0);
            //MessageBox.Show("stop");
            timer2.Stop();
            timer1.Start();
        }



    }
}

But i have a problem. This is opening them in the same time. I need 1 to be closed when 2 is opened. And reverse. Any help?



#4 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts

Posted 25 April 2013 - 12:45 PM

Have you tried just executing the open and close commands themselves without the use of timers to verify it's doing what it's supposed to? (To narrow down your problem between the drive control routines and the timer logic.)

Edit: You might also just try controlling one drive at a time and get that logic down before trying to tackle two.

Edited by gregwarner, 25 April 2013 - 12:46 PM.

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#5 brainiac080195

brainiac080195

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 25 April 2013 - 01:34 PM

Ok i sorted it out code works perfect it was a hardware problem. Ty for help anyways. Problem solved!






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download