This is a program to test stepper motors. The second thread is to check for input to change speed, direction in real-time.
The issue is with
_beginthread(CheckKey, 0 , _ArgList);
Don't know what to put for _ArgList, since it would be void for CheckKey(void)
// Stepper.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "conio.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include <windows.h>
#include <process.h>
#include <iostream>
#include <sstream>
using namespace std;
#define Data 0x378 //Lpt1 Data register
#define Status Data+1 //Lpt1 Status Register
#define Control Data+2 //Lpt1 Control Register
// ----Prototypes of Inp and Outp are contained in sdafx.h---
short _stdcall Inp32(short PortAddress);
void _stdcall Out32(short PortAddress, short data);
//--------------------------------
void CheckKey(void);//function to check for user input
int kb = 1;
int delay = 400;//atoi(argv[2]);
char direction = 'f';//argv[1];
int speed = 1;
int kbv = 0;
int steps = 25;//atoi(argv[3]);
BOOL run = true;
int _main(int argc, _TCHAR* argv[])
{
Out32(Data,0x0000);//Clear Parallel port
_beginthread(CheckKey,0,NULL);//threaded function to check for user input
while(run)
{
if(direction = 'f')//Move stepper forward
{
Sleep(delay/4);
Out32(Data,0x9);
Sleep(delay/4);
Out32(Data,0x5);
Sleep(delay/4);
Out32(Data,0x6);
Sleep(delay/4);
Out32(Data,0xa);
}else if(direction = 'r')//Move stepper in reverse
{
Sleep(delay/4);
Out32(Data,0xa);
Sleep(delay/4);
Out32(Data,0x6);
Sleep(delay/4);
Out32(Data,0x5);
Sleep(delay/4);
Out32(Data,0x9);
}
}
Out32(Data,0x0000);//Clear Parallel port
return 0;
}
void CheckKey(void)
{
cout << "\nDirection: " << direction << "\nSpeed is: " << speed << "\n";
while (_getch() != 'q')//_kbhit != 0)
{
if(_getch() == '+' && delay > 10)
{
delay -= 10;
speed++;
cout << "\nSpeed is: " << speed;
}else if(_getch() == '-' && speed > 1)
{
delay += 10;
speed--;
cout << "\nSpeed is: " << speed;
}else if (_getch() == 'f')
{
direction = 'f';
cout<< "\nDirection is: " << direction;
}else if(_getch() == 'r')
{
direction = 'r';
cout<< "\nDirection is: " << direction;
}else
{
kb = 1;
}
Out32(Data,0x0000);
run = 0;
_endthread();
}
}
Compileing gives this error:
: error C2664: '_beginthread'
: cannot convert parameter 1 from 'void (__cdecl *)(void)' to 'void (__cdecl *)(void *)'
1> None of the functions with this name in scope match the target type
This post has been edited by brycetron: 17 September 2009 - 09:38 AM

New Topic/Question
Reply




MultiQuote





|