Sign in to follow this  
Followers 0
Lakes

Converting C Code To Autoit

2 posts in this topic

I`m hoping you C programming guru`s can help me out here...

I have one of these http://www.itechdeals.com/itechcds/Scripts...asp?idproduct=8

But I would like to control it directly, rather than use the software provided.

I have been given some basic C code that sends a command to the machine, here it is:

/*
 * testlibusb.c
 *
 *  Test suite program
 */

#include <stdio.h>
#include <usb.h>

void controlit(usb_dev_handle *udev, int numb);

int main(int argc, char **argv)
{
  int numb;
  struct usb_bus *bus;
  struct usb_device *dev;

  usb_init();

  usb_find_busses();
  usb_find_devices();

  if(argc!=2) {
    fprintf(stderr, "Usage: %s carosel_number\n", argv[0]);
    return 1;
  }

  numb = atoi(argv[1]);

  //printf("bus/device  idVendor/idProduct\n");
  for (bus = usb_busses; bus; bus = bus->next) {
    for (dev = bus->devices; dev; dev = dev->next) {
      int ret, i;
      char string[256];
      usb_dev_handle *udev;

      //printf("%s/%s    %X/%X\n", bus->dirname, dev->filename,
    //dev->descriptor.idVendor, dev->descriptor.idProduct);

      udev = usb_open(dev);
    //if(dev->descriptor.idProduct == 0x5203) usb_reset(udev);
    if(dev->descriptor.idProduct == 0x5a9b) controlit(udev, numb);
      usb_close (udev);

    }
  }

  return 0;
}

void controlit(usb_dev_handle *udev, int numb)
{
int k,j,l,m,n,i,d;
char buf[16384];

    //d = 0x9040202;
    d = 0;
    //d = 151257602;
    k = 0;
    //m = usb_reset(udev);
        buf[0] = 0x80;
        buf[1] = 0x6;
        buf[2] = 0x0e;
        buf[3] = 0x03;
        buf[4] = 0x9;
        buf[5] = 0x4;
        buf[6] = 0x2;
        buf[7] = 0x2;
        buf[8] = 0x0;
        //j = usb_control_msg(udev, 0x80, 0x6, 0xa03, d, buf, 8, 10000000);
        //j = usb_control_msg(udev, 0x80, 0x6, 0xa, 0x03, buf, 8, 10000000);

    //for(i=50; i<53; i++) {
        //fprintf(stderr, "printout\n");
//      n = (256*i)+3;
//      buf[0] = 0x80;
//      buf[1] = 0x6;
//      buf[2] = 0x0e;
//      buf[3] = 0x03;
//      buf[4] = 0x9;
//      buf[5] = 0x4;
//      buf[6] = 0x2;
//      buf[7] = 0x2;
//      buf[8] = 0x0;
//      //j = usb_control_msg(udev, 0x80, 0x6, 0xe03, d, buf, 8, 10000000);
//      j = usb_control_msg(udev, 0x80, 0x6, 0xe, 0x03, buf, 8, 10000000);
//      sleep(1);
//      buf[0] = 0x80;
//      buf[1] = 0x6;
//      buf[2] = 0x0c;
//      buf[3] = 0x03;
//      buf[4] = 0x9;
//      buf[5] = 0x4;
//      buf[6] = 0x2;
//      buf[7] = 0x2;
//      buf[8] = 0x0;
//      //k = usb_control_msg(udev, 0x80, 0x6, 0xc03, d, buf, 8, 10000000);
//      k = usb_control_msg(udev, 0x80, 0x6, 0xc, 0x03, buf, 8, 10000000);
//      sleep(1);
//      buf[0] = 0x80;
//      buf[1] = 0x6;
//      buf[2] = i;
//      buf[3] = 0x03;
//      buf[4] = 0x9;
//      buf[5] = 0x4;
//      buf[6] = 0x2;
//      buf[7] = 0x2;
//      buf[8] = 0x0;
//      l = usb_control_msg(udev, 0x80, 0x6, n, d, buf, 8, 10000000);
//      printf("  reset: %d, %d, %d, %d, %x: \n", m, j, k, l, n);
//      //sleep(2);
//  }

    k = usb_get_descriptor(udev, 3, 0xe, buf, 514);
    k = usb_get_descriptor(udev, 3, 0xc, buf, 514);
    //k = usb_get_descriptor(udev, 3, 0x64, buf, 514);
    k = usb_get_descriptor(udev, 3, numb, buf, 514);

}

Here`s a description of what it does:

Dacal

This is the email i've been sending to everyone who requests it, i know at least one guy has it working with a php website he's working on... i should really release it on freshmeat or something:)

Heya,

Heres the software, its pretty simple though.. cont.c is the actually controller, tlu.c is a program to show whats plugged into the usb ports...

http://home.pjr.cc/dacal.tar.gz

just untar/gunzip the archive, then "make" it... All it does tho is simply send a command to the dacal library to eject the cd, and this is where a driver would be better... if the cd is already ejected, it will only pull the carosel arm back in again (if its the number its currently on)..

i.e. the commands:

"./cont 150" would eject the cd at "150"

"./cont 100" would close 150 and then open 100

"./cont 100" would only close 100 and nothing else..

hope that makes sence. a driver would be better cause the driver would be able to keep track of which cd the carosel is currently "located" at, and also because the cont.c program requires root priv's to run, but i never got around to coding one.. I was thinking for a while that i might just make a carosel daemon to control the thing as that would be slightly easier, but i never got the chance to do that either..

when cont.c starts, it searches for specific usb id... as far as i know, thats the same for all the dacal libraries, however, i wrote tlu.c to check...

the kind of thing your looking for from tlu is something like this:

003/006 4B4/5A9B

- Manufacturer : DACAL Co.

- Product : CD Manager?

003/005 4B4/5203

- Product : Generic USB Hub

003/004 58F/9254

- Manufacturer : ALCOR

- Product : Generic USB Hub

and this line in cont.c should make that first line from the "CD Manager?" list (i.e. 5a9b):

if(dev->descriptor.idProduct == 0x5a9b) controlit(udev, numb);

Good luck with it, i'd like to know what you end up producing!... my email's me@pjr.cc

Regards, Paul

As I don`t have a clue when it comes to coding in C, I`m hoping someone here can convert into something thats usable with Autoit.

Eventually, I plan on adding a slot loading drive to one of these to make it into a Disc JukeBox, which is why I need to control it direct, if possible.

Many Thanks!

P.S Sorry if this is off topic, but I was`nt sure where to post it here...


2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

where is usb.h?

Lar.

I donno, I can ask the Guy, maybe from here? http://libusb-win32.sourceforge.net/

This is his post on the ItechDeals Forum:

Actually, after a while, i just decided to buy one, and havent looked back... after a little work, i even got it working under linux... (i didnt write a driver, i just wrote a libusb extension, i.e., it requires root)..

But its incredibly easy to control..

If anyone wants to see the code, let me know, I was going to write a web-based (php) controller for it, but i decided to just leave it on my windows box... sometimes this annoys me from the simple fact that my windows box isnt always on, and my linux server is.

You can read the original here: http://www.itechdeals.com/phpbb2/viewtopic.php?t=113

Btw: I want to use this on a windows Xp system not linux... :)

P.S. I don`t want to start learning C, all that pointer stuff does my head in...

Edited by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0