How to send bits to a usb port

Nov 11, 2008 at 10:35pm
First of all this is what I'm using-
http://www.electronickits.com/kit/complete/elec/ck1601.htm

I don't have a parallel port on my laptop, so I bought a parallel to USB converter cable. Now I'm tasked with writing code to send the appropriate bits to the board to open up the relays.

I really don't know where to start-

I'm not certain how to write code to talk to the USB port, but once I figure that out I assume I just have to send the write bits after that.

Any help is appreciated. I'm using Windows Vista Home Basic 32 bit and this is the code they gave me to talk to the USB port-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <dos.h>

#define LPT1 0x00400008  /* BIOS printer address entries */
#define LPT2 0x0040000a
#define LPT3 0x0040000c
#define LPT4 0x0040000e


int main(int argc, char *argv[])
{
unsigned int port,data;
unsigned int far *bios_printer_addr;

if (argc>3) exit(1);

  switch(argc)
    {
      case 1:
        exit(1);

      case 2:
        port=*(bios_printer_addr=LPT1);
        if (port==NULL)
          {
            printf("LPT1 does not exist\n");
            exit(1);
          }
        sscanf(argv[1],"%x",&data);
        break;

      case 3:
	if (argv[1][0]=='/')

	  switch(argv[1][1])
	    {
	      case '1':
	        port=*(bios_printer_addr=LPT1);
                if (port==NULL)
                  {
                    printf("LPT1 does not exist\n");
                    exit(1);
                  }
                sscanf(argv[2],"%x",&data);
	        break;

	      case '2':
	        port=*(bios_printer_addr=LPT2);
                if (port==NULL)
                  {
                    printf("LPT2 does not exist\n");
                    exit(1);
                  }
                sscanf(argv[2],"%x",&data);
	        break;

              case '3':
                port=*(bios_printer_addr=LPT3);
                if (port==NULL)
                  {
                    printf("LPT3 does not exist\n");
                    exit(1);
                  }
                sscanf(argv[2],"%x",&data);
                break;

              case '4':
                port=*(bios_printer_addr=LPT4);
                if (port==NULL)
                  {
                    printf("LPT4 does not exist\n");
                    exit(1);
                  }
                sscanf(argv[2],"%x",&data);
                break;

	      default:
                printf("Invalid printer port!\n");
	        exit(1);
	    }

	else exit(1);

    }

   outportb(port, (char)data);

   return 0;
}


Last edited on Nov 11, 2008 at 10:36pm
Nov 12, 2008 at 10:31am
The question is:

After the USB->Parallel adapter has been put in - does your computer now show up as having a parallel port?
Nov 12, 2008 at 10:47am
Ps - that program you have shown us is really for if you are running an old computer under DOS - It seems that you are using Windows as you have bought a USB item.
But first can you provide an answer about whether the usb converter shows up as a LPT port?

(Writing to an LPT port is easy - writing to USB is somewhat more involved);
Last edited on Nov 12, 2008 at 10:49am
Nov 12, 2008 at 11:32am
here is some interesting technical news:
Restrictions on USB to Parallel converter cables
You need to buy the right product - as most USB to Parallel converters will work with printers only.
Nov 12, 2008 at 5:58pm
I haven't actually got it yet, it's still in the mail was just thinking ahead. :)

But as soon as I get it and test it out I'll tell.
Topic archived. No new replies allowed.