It all went wrong when I wrote a program that simplified some of my grub work (Can't really explain, I signed this NDA for research that's already been done T_T), and now I have to write a program that can control the running of a small motor with a full GUI n' shit. This motor USED to have a program it would use in labVIEW, however I was told this labVIEW program only worked on 1 computer here (?). Before I go any further, let me clarify a little with some pretty pictures.
+ Show Spoiler +
this is the motor controller, the Cyberpak CY-21. Sorry guys, this is the best picture I could find.
as you can tell, this is how the motor system is currently wired. Exactly how it appears on my chart.
So as you can see, I'm using a piece of hardware known as the DB-25 to connect to the CY-21 controller. a little info on the DB-25 for those who don't know:
http://www.nullmodem.com/DB-25.htm
(an explanation is here, scroll down until you reach IBM-PC)
These are the printer port values of the DB-25. Thus, we see that pins 2-9 are the only pins that are good for input/output data (also pins used in wiring schematic), while pins 25-18 are simply grounds (one is used in wiring).
So what data am I trying to transmit? Well, for the ENA pin on the CY-21, I need a 0 to activate and a 1 to disable the motor. for the DIR pin, 0 is clockwise and 1 is counterclockwise (Not sure which is which right now, but it's not really important yet), and then there is the STEP pin. This motor controller is special in that it is a "microstepping motor driver", thus I quote: "The CY-21 has 16 microsteps per full step, which is 3,200 steps/rev with a standard 1.8° motor." I'm not entirely sure on this one, but I'm fairly sure that the STEP pin is to set the speed of the motor, and I think a good value to try would be 16.
one pic of the actual circuit I've got goin on: Is here!
+ Show Spoiler +
note: some guy dis attached my motor. I'll put it back on later.
So now down to code. Unfortunately, a ton of the google results you'd get on parallel port programming are old. reallllly old. Back when your program could access hardware eZpZ old. But times have changed, and the best guide I could find was this one.
you'll notice that for XP and up, a .dll called Inpout32.dll is supposedly critical to success. upon downloading this .dll, the best thing I found was the test program.
test program:
+ Show Spoiler +
/**************************************************/
/*** ***/
/*** TEST.c -- test interface to inpout32.dll ***/
/*** ( [url=http://www.logix4u.net/inpout32.htm]http://www.logix4u.net/inpout32.htm[/url] ) ***/
/*** ***/
/*** Copyright (C) 2003, Douglas Beattie Jr. ***/
/*** ***/
/*** <beattidp@ieee.org> ***/
/*** [url=http://www.hytherion.com/beattidp/]http://www.hytherion.com/beattidp/[/url] ***/
/*** ***/
/**************************************************/
/*******************************************************/
/* */
/* Builds with Borland's Command-line C Compiler */
/* (free for public download from Borland.com, at */
/* [url=http://www.borland.com/bcppbuilder/freecompiler]http://www.borland.com/bcppbuilder/freecompiler[/url] ) */
/* */
/* Compile with: */
/* */
/* BCC32 -IC:\BORLAND\BCC55\INCLUDE TEST.C */
/* */
/* */
/* Be sure to change the Port addresses */
/* accordingly if your LPT port is addressed */
/* elsewhere. */
/* */
/*******************************************************/
#include <stdio.h>
#include <conio.h>
#include <windows.h>
/* Definitions in the build of inpout32.dll are: */
/* short _stdcall Inp32(short PortAddress); */
/* void _stdcall Out32(short PortAddress, short data); */
/* prototype (function typedef) for DLL function Inp32: */
typedef short _stdcall (*inpfuncPtr)(short portaddr);
typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);
int main(void)
{
HINSTANCE hLib;
inpfuncPtr inp32;
oupfuncPtr oup32;
short x;
int i;
/* Load the library */
hLib = LoadLibrary("inpout32.dll");
if (hLib == NULL) {
printf("LoadLibrary Failed.\n");
return -1;
}
/* get the address of the function */
inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
if (inp32 == NULL) {
printf("GetProcAddress for Inp32 Failed.\n");
return -1;
}
oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
if (oup32 == NULL) {
printf("GetProcAddress for Oup32 Failed.\n");
return -1;
}
/***************************************************************/
/* now test the functions */
/* Try to read 0x378..0x37F, LPT1: */
for (i=0x378; (i<0x380); i++) {
x = (inp32)(i);
printf("port read (%04X)= %04X\n",i,x);
}
/***** Write the data register */
i=0x378;
x=0x77;
(oup32)(i,x);
printf("port write to 0x%X, datum=0x%2X\n" ,i ,x);
/***** And read back to verify */
x = (inp32)(i);
printf("port read (%04X)= %04X\n",i,x);
/***** One more time, different value */
i=0x378;
x=0xAA;
(oup32)(i,x);
printf("port write to 0x%X, datum=0x%2X\n" ,i ,x);
/***** And read back to verify */
x = (inp32)(i);
printf("port read (%04X)= %04X\n",i,x);
FreeLibrary(hLib);
system("PAUSE");
return 0;
}
which would return something like this on my comp without a DB-25 hooked up:
port read <0378>= 00FF
port read <0379>= 0078
port read <037A>= 0004
port read <037B>= 0004
port read <037C>= 0004
port read <037D>= 0004
port read <037E>= 0004
port read <037F>= 0004
port write to 0x378, datum=0x77
port read <0378>= 0077
port write to 0x378, datum=0xAA
port read <0378>= 00AA
(I don't have access to the actual computer right now, but the return wasn't very different IRC. I'll update this as soon as I can get in the room!)
So every code attempt I have made has failed. Like everything else, my source file has gone on the run with my supervisor's little hard drive, and he's not coming back. So my broken code is gone.
eDiT: DB-25 clarification: The DB-25 acts as the printer port connection: thus it's default location is LPT1, and the base address for the first data pin is 0x378, whereas the last data pin goes by 0x37f, and the next value for an incremental interger would be 0x380.
Anyway, despite the slightly incomplete blog, I was really hoping to get some assistance doing this program >.< I've run out of ideas and while the logic seems to make sense, I just don't understand how do do it syntactically. Plz help, I will update as soon as I can!