Accueil > > > COMMANDE DU PORT PARALLELE & MOTEUR PAS A PAS
COMMANDE DU PORT PARALLELE & MOTEUR PAS A PAS
Information sur la source
Description
C’est un programme pour commander un moteur pas a pas par excellence, et de commander les différentes entrées & sorties de l’ordinateur. C’est le début d’un projet de commande des moteur, je suis entrains de modifier cette source pour une commande absolu même au niveau de transmission de mouvement , calcul vitesse ... Je mettrais la suite du projet dans qlq jours ,elle contient environs 800 lignes Je demande votre aide pour continuer ce projet surtout au niveau de lecture &écriture des fichier si par exemple on veut intégrer un tout petit compilateur ,par exemple : On écrit dans un fichier : Move 4 //pour avacer 4 pas ou Move 4deg//pour avancer 4 degrés ou encore IN … La question qui se pose comment lire move et si on trouve le mot move on lit la suite et si tout va bien on avance. **VC++ 6.0**
Source
-
- /***************************
- * (c) YESSINE 30/08/2004 *
- ***************************/
-
- //FREE SOURCE CODE
-
- /*
- THE STEPPER CONTROL 1.0
- */
-
- #include "stdafx.h"
- #include <stdlib.h>
- #include <iostream>
- #include <string>
- #include <windows.h>
- #include <conio.h>
- #include <fstream>
-
- using namespace std;
-
- #define pport 0x378;
-
-
- void move(int tm);
- void move_to4(int step_number,int tm);
- void move_to44(int step_number,int tm);
- //void open_file();
-
- int main(int argc, char* argv[])
- {
-
- string command;
- int pval;
- int stime;
- int snbr;
- printf("<<<<****>>>> & STEPPER CONTROL 1.0 & <<<<****>>>>\n");
- Sleep(500);
- printf(" MSDOS MODE \n");
- Sleep(1000);
- printf(" (c)YESSINE 2004 \n\n");
-
- while(command !="exit")
- {
- cout<<"-";
- cin>>command;
-
-
- // OUT : X PORT
- if ((command=="op")||(command=="OP")||(command=="Op")||(command=="OpenPort")||(command=="openport")||(command=="OPENPORT"))
- {
- unsigned short port_num;
- int port_val;
- printf("PORT NUM : ");
- cin>>port_num;
- printf("VALUE : ");
- cin>>port_val;
- _outp(port_num, port_val);
- }
-
- //HELP
- if ((command=="help")||(command=="HELP")||(command=="Help"))
- {
- int ch ;
- cout<<"[COMMAND]"<<endl;
- cout<<" [PORT OUT ] [1]"<<endl;
- cout<<" [PARALLELE PORT OUT ] [2]"<<endl;
- cout<<" [MOVING THE STEPPER1] [3]"<<endl;
- cout<<" [MOVING THE STEPPER2] [4]"<<endl;
- cout<<" [RETURN ] [5]"<<endl<<endl;
- cout<<">";
- cin>>ch;
- switch(ch)
- {
- case 1:
- cout<<"Syntax : OpenPort(port number ,value)"<<endl;
- cout<<" : OPENPORT(port number ,value)"<<endl;
- cout<<" : openport(port number ,value)"<<endl;
- cout<<" : OP(port number ,value)"<<endl;
- cout<<" : Op(port number ,value)"<<endl;
- cout<<" : op(port number ,value)"<<endl;
- break;
- case 2:
- cout<<"Syntax : ppo(value)"<<endl;
- cout<<" : PPO(value)"<<endl;
- cout<<" : Ppo(value)"<<endl;
- cout<<" : ParallePortOut(value)"<<endl;
- cout<<" : paralle_port_out(value)"<<endl;
- break;
- case 3:
- cout<<"Syntax : move(time_millisecond)"<<endl;
- cout<<" : Move(time_millisecond)"<<endl;
- cout<<" : MOVE(time_millisecond)"<<endl;
- break;
- case 4:
- cout<<"Syntax : move_to(Step_number,time_millisecond)"<<endl;
- cout<<" : Move_To(Step_number,time_millisecond)"<<endl;
- cout<<" : MOVE_TO(Step_number,time_millisecond)"<<endl;
- break;
- case 5:break;
-
- default:break;
-
- }
- //open_file();
-
- }
-
- // OUT : PARALLE PORT
- if ((command=="ppo")||(command=="PPO")||(command=="Ppo"))
- {
-
- printf("OUT NUM [0..1..2..4..8..16..32..64..128]: ");
- cin>>pval;
- _outp(0x378, pval);
- }
-
-
- // OUT : PARALLELE PORT
- if ((command=="ParallePortOut")||(command=="paralle_port_out"))
- {
- printf("OUT NUM [0..1..2..4..8..16..32..64..128]: ");
- cin>>pval;
- _outp(0x378, pval);
- }
-
- // STOP THE CURRENT ACTION
- if ((command=="stop")||(command=="Stop")||(command=="STOP"))
- {
-
- _outp(0x378, 0);
- printf("STOPPED!");
-
- }
-
- // GET PORT
- /*if ((command=="in")||(command=="In")||(command=="IN"))
- {
- DWORD port_number1[5];
-
- printf("PORT NUM : ");
- cin>>port_number1;
- cout<<_inp(port_number1);
- }*/
-
- // MOVING 4 STEPS
- if ((command=="move")||(command=="Move")||(command=="MOVE"))
- {
- printf("SLEEPING TIME : ");
- cin>>stime;
- printf("MOVING . . . . .\n");
- move(stime);
- }
- //MOVING X STEPS
- if ((command=="move_to")||(command=="Move_TO")||(command=="MOVE_TO"))
- {
- printf("STEP NUM : ");
- cin>>snbr;
- printf("SLEEPING TIME : ");
- cin>>stime;
- printf("MOVING . . . . .\n");
-
-
- if (snbr<=4)
- {
- move_to4(snbr , stime);
- }
- if (snbr>4)
- {
- move_to4(snbr,stime);
- move_to44(snbr , stime);
- }
- }
- }
-
- return 0;
- }
-
- //MOVING 4 STEPS
- void move_to4(int step_number,int tm)
- {
- int i;
- for(i=1;i<=step_number;i++)
- {
-
- switch(i)
- {
- case 1:
- Sleep(tm);
- _outp(0x378, 1);
- break;
- case 2:
- Sleep(tm);
- _outp(0x378, 2);
- break;
- case 3:
- Sleep(tm);
- _outp(0x378, 4);
- break;
- case 4:
- Sleep(tm);
- _outp(0x378, 8);
- break;
- }
- }
- }
-
- //MOVING STEP-4
- void move_to44(int step_number,int tm)
- {
- int i;
- for(i=1;i<=step_number-4;i++)
- {
-
- switch(i)
- {
- case 1:
- Sleep(tm);
- _outp(0x378, 1);
- break;
- case 2:
- Sleep(tm);
- _outp(0x378, 2);
- break;
- case 3:
- Sleep(tm);
- _outp(0x378, 4);
- break;
- case 4:
- Sleep(tm);
- _outp(0x378, 8);
- break;
- case 5:
- Sleep(tm);
- _outp(0x378, 1);
- break;
- case 6:
- Sleep(tm);
- _outp(0x378, 2);
- break;
- case 7:
- Sleep(tm);
- _outp(0x378, 3);
- break;
- case 8:
- Sleep(tm);
- _outp(0x378, 4);
- break;
- default:printf("MAX SETEPS = 12 !!");
- break ;
-
- }
- }
- }
- void move(int tm)
- {
- int i;
-
-
- for(i=1;i<=4;i++)
- {
-
- switch(i)
- {
- case 1:
- Sleep(tm);
- _outp(0x378, 1);
- break;
- case 2:
- Sleep(tm);
- _outp(0x378, 2);
- break;
- case 3:
- Sleep(tm);
- _outp(0x378, 4);
- break;
- case 4:
- Sleep(tm);
- _outp(0x378, 8);
- break;
- }
- }
- }
/***************************
* (c) YESSINE 30/08/2004 *
***************************/
//FREE SOURCE CODE
/*
THE STEPPER CONTROL 1.0
*/
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <string>
#include <windows.h>
#include <conio.h>
#include <fstream>
using namespace std;
#define pport 0x378;
void move(int tm);
void move_to4(int step_number,int tm);
void move_to44(int step_number,int tm);
//void open_file();
int main(int argc, char* argv[])
{
string command;
int pval;
int stime;
int snbr;
printf("<<<<****>>>> & STEPPER CONTROL 1.0 & <<<<****>>>>\n");
Sleep(500);
printf(" MSDOS MODE \n");
Sleep(1000);
printf(" (c)YESSINE 2004 \n\n");
while(command !="exit")
{
cout<<"-";
cin>>command;
// OUT : X PORT
if ((command=="op")||(command=="OP")||(command=="Op")||(command=="OpenPort")||(command=="openport")||(command=="OPENPORT"))
{
unsigned short port_num;
int port_val;
printf("PORT NUM : ");
cin>>port_num;
printf("VALUE : ");
cin>>port_val;
_outp(port_num, port_val);
}
//HELP
if ((command=="help")||(command=="HELP")||(command=="Help"))
{
int ch ;
cout<<"[COMMAND]"<<endl;
cout<<" [PORT OUT ] [1]"<<endl;
cout<<" [PARALLELE PORT OUT ] [2]"<<endl;
cout<<" [MOVING THE STEPPER1] [3]"<<endl;
cout<<" [MOVING THE STEPPER2] [4]"<<endl;
cout<<" [RETURN ] [5]"<<endl<<endl;
cout<<">";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Syntax : OpenPort(port number ,value)"<<endl;
cout<<" : OPENPORT(port number ,value)"<<endl;
cout<<" : openport(port number ,value)"<<endl;
cout<<" : OP(port number ,value)"<<endl;
cout<<" : Op(port number ,value)"<<endl;
cout<<" : op(port number ,value)"<<endl;
break;
case 2:
cout<<"Syntax : ppo(value)"<<endl;
cout<<" : PPO(value)"<<endl;
cout<<" : Ppo(value)"<<endl;
cout<<" : ParallePortOut(value)"<<endl;
cout<<" : paralle_port_out(value)"<<endl;
break;
case 3:
cout<<"Syntax : move(time_millisecond)"<<endl;
cout<<" : Move(time_millisecond)"<<endl;
cout<<" : MOVE(time_millisecond)"<<endl;
break;
case 4:
cout<<"Syntax : move_to(Step_number,time_millisecond)"<<endl;
cout<<" : Move_To(Step_number,time_millisecond)"<<endl;
cout<<" : MOVE_TO(Step_number,time_millisecond)"<<endl;
break;
case 5:break;
default:break;
}
//open_file();
}
// OUT : PARALLE PORT
if ((command=="ppo")||(command=="PPO")||(command=="Ppo"))
{
printf("OUT NUM [0..1..2..4..8..16..32..64..128]: ");
cin>>pval;
_outp(0x378, pval);
}
// OUT : PARALLELE PORT
if ((command=="ParallePortOut")||(command=="paralle_port_out"))
{
printf("OUT NUM [0..1..2..4..8..16..32..64..128]: ");
cin>>pval;
_outp(0x378, pval);
}
// STOP THE CURRENT ACTION
if ((command=="stop")||(command=="Stop")||(command=="STOP"))
{
_outp(0x378, 0);
printf("STOPPED!");
}
// GET PORT
/*if ((command=="in")||(command=="In")||(command=="IN"))
{
DWORD port_number1[5];
printf("PORT NUM : ");
cin>>port_number1;
cout<<_inp(port_number1);
}*/
// MOVING 4 STEPS
if ((command=="move")||(command=="Move")||(command=="MOVE"))
{
printf("SLEEPING TIME : ");
cin>>stime;
printf("MOVING . . . . .\n");
move(stime);
}
//MOVING X STEPS
if ((command=="move_to")||(command=="Move_TO")||(command=="MOVE_TO"))
{
printf("STEP NUM : ");
cin>>snbr;
printf("SLEEPING TIME : ");
cin>>stime;
printf("MOVING . . . . .\n");
if (snbr<=4)
{
move_to4(snbr , stime);
}
if (snbr>4)
{
move_to4(snbr,stime);
move_to44(snbr , stime);
}
}
}
return 0;
}
//MOVING 4 STEPS
void move_to4(int step_number,int tm)
{
int i;
for(i=1;i<=step_number;i++)
{
switch(i)
{
case 1:
Sleep(tm);
_outp(0x378, 1);
break;
case 2:
Sleep(tm);
_outp(0x378, 2);
break;
case 3:
Sleep(tm);
_outp(0x378, 4);
break;
case 4:
Sleep(tm);
_outp(0x378, 8);
break;
}
}
}
//MOVING STEP-4
void move_to44(int step_number,int tm)
{
int i;
for(i=1;i<=step_number-4;i++)
{
switch(i)
{
case 1:
Sleep(tm);
_outp(0x378, 1);
break;
case 2:
Sleep(tm);
_outp(0x378, 2);
break;
case 3:
Sleep(tm);
_outp(0x378, 4);
break;
case 4:
Sleep(tm);
_outp(0x378, 8);
break;
case 5:
Sleep(tm);
_outp(0x378, 1);
break;
case 6:
Sleep(tm);
_outp(0x378, 2);
break;
case 7:
Sleep(tm);
_outp(0x378, 3);
break;
case 8:
Sleep(tm);
_outp(0x378, 4);
break;
default:printf("MAX SETEPS = 12 !!");
break ;
}
}
}
void move(int tm)
{
int i;
for(i=1;i<=4;i++)
{
switch(i)
{
case 1:
Sleep(tm);
_outp(0x378, 1);
break;
case 2:
Sleep(tm);
_outp(0x378, 2);
break;
case 3:
Sleep(tm);
_outp(0x378, 4);
break;
case 4:
Sleep(tm);
_outp(0x378, 8);
break;
}
}
}
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
RE : WIN APIRE : WIN API par racpp
Cliquez pour lire la suite par racpp WIN APIWIN API par omarino_007
Cliquez pour lire la suite par omarino_007
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|