Bonjour à tous!
Voilà j' essayes de porter un programme que j'ai réalisé sous DOS en C et qui lui fonctionne trés bien qui gère des moteurs pas à pas ainsi qu'un convertisseur analogique /numérique pour une application scientifique.
J'ai dejà résolu grâce à vous le problème de communication avec les ports sous XP en utilisant la DLL WinIo
que j'ai implementé et qui fonctionne tres bien et dont je vous remercie de m'en avoir fait connaitre l'existance!!
Mon probleme est un probleme de récupéation de la valeur des variables en cours d'execution de la boucle et de les afficher ainsi que de pouvoir par l'intermédiaire d'un contôle (bouton) pouvoir agir sur la variable pour obtenir une action.
Par avance merci de vos idées ...
Ah oui!! JE SUIS DEBUTANT EN Visual C++ ... :)
Je vous joint ci dessous le code tres commenté sur les points qui me semblent obscur:
____________________________________________________________________________
// testobjectDlg.cpp : implementation file
//
#include "windows.h"
#include "stdafx.h"
#include "testobject.h"
#include "testobjectDlg.h"
#include "stdio.h"
#include "conio.h"
#include "winio.h"
#include "testobjectDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//int m_ctr;
int m_limit = 1000;
int m_ctr;
double m_speed = 500000;
double a;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestobjectDlg dialog
CTestobjectDlg::CTestobjectDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestobjectDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestobjectDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestobjectDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestobjectDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestobjectDlg, CDialog)
//{{AFX_MSG_MAP(CTestobjectDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_START_1, OnButtonStart1)
ON_BN_CLICKED(IDC_BUTTON_OFF_2, OnButtonOff2)
ON_BN_CLICKED(IDC_BUTTON_RUN_MOTOR_1, OnButtonRunMotor1)
ON_BN_CLICKED(IDC_BUTTON_STOP_MOTOR_2, OnButtonStopMotor2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestobjectDlg message handlers
BOOL CTestobjectDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// -------------------------------------------------------------------------------
// Call InitializeWinIo to initialize the WinIo library.
/////////////////////////////////////////////////////////////////////////
InitializeWinIo(); // INITIALISATION DRIVER PORTS
// Under Windows NT/2000/XP, after calling InitializeWinIo,
// you can call _inp/_outp instead of using GetPortVal/SetPortVal
//EXEMPLE:
//GetPortVal(0x378, &dwPortVal, 4);
//SetPortVal(0x378, 10, 4);
//_outp (888,255);
// m_valport _inp(889);
///////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------------------------
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestobjectDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestobjectDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestobjectDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestobjectDlg::OnButtonStart1()
{
// TODO: Add your control notification handler code here
_outp(888,255);
}
void CTestobjectDlg::OnButtonOff2()
{
// TODO: Add your control notification handler code here
_outp(888,0);
}
void CTestobjectDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
void CTestobjectDlg::OnCancel()
{
// TODO: Add extra cleanup here
////////////////////////////////////////////////////////////////////////
RemoveWinIoDriver(); // DESINSTALLE LE DRIVER
////////////////////////////////////////////////////////////////////////
CDialog::OnCancel();
}
void CTestobjectDlg::OnButtonRunMotor1()
{
// TODO: Add your control notification handler code here
//////////////////////////////////////////////////////////////////////////////////
//JE VEUX POUVOIR EN COURS D'EXECUTION DE LA BOUCLE: do while
//AGIR SUR LA VARIABLE: m_speed "ICI m_speed EST BLOQUE COMME CONSTANTE
//MAIS QUI DANS L'APPLICATION REELLE SERA ISSUE DU RESULTAT D'UN TRAITEMENT
//PAR CALCUL (CHAQUE PAS FAISANT APPEL A UNE AQUISITION DE MESURE ICI NON DECRITE
//QUI EN FONCTION DE SA VALEUR JOUERA SUR LA VARIABLE m_speed DE FACON A REGULER
//LA VITESSE DU MOTEUR EN FONCTION DE CETTE VALEUR)
////////////////////////////////////////////////////////////////////////////////////
//
// TOUT CA FONCTIONNE TRES BIEN SOUS DOS EN C ET EN BASIC !!!!!!!!!!!!!!!!
//
////////////////////////////////////////////////////////////////////////////////////
//
//J'AI ESSAYE AUSSI AVEC UNE SIMPLE BOUCLE WHILE .... PAS MIEUX... :(
//
////////////////////////////////////////////////////////////////////////////////////
do
{
{
for (a=0;a<=m_speed;a++); // temps entre step
_outp (888,1); //ordre commande moteur
m_ctr = m_ctr+1;
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//JE VEUX AFFICHER SUR UN CONTRÔLE LA VALEUR DE: m_ctr ; //
//J'AI ESSAYE AVEC UN IDC_EDIT EN PROTOCOLE DDV/DDX EN //
//UTILISANT UpdateData(TRUE)/UpdateData(FALSE)... //
//CA ME MARCHE PAS LE COMPILATEUR REFUSE MEME DE ME GENERER //
//L'EXE ... //
//PAR CONTRE SANS AFFICHAGE CA MARCHE MON MOTEUR TOURNE MAIS//
//EN "AVEUGLE SE LIMITANT AU VALEURS PREDEFINIES EN DUR SANS//
//MOYEN DE VOIR NI D'AGIR DESSUS PENDANT L'EXECUTION.......// //
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
{
for (a=0;a<=m_speed;a++); // temps entre step
_outp (888,2); //ordre commande moteur
m_ctr = m_ctr+1;
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//JE VEUX AFFICHER SUR UN CONTRÔLE LA VALEUR DE: m_ctr ; //
//J'AI ESSAYE AVEC UN IDC_EDIT EN PROTOCOLE DDV/DDX EN //
//UTILISANT UpdateData(TRUE)/UpdateData(FALSE)... //
//CA ME MARCHE PAS LE COMPILATEUR REFUSE MEME DE ME GENERER //
//L'EXE ... //
//PAR CONTRE SANS AFFICHAGE CA MARCHE MON MOTEUR TOURNE MAIS//
//EN "AVEUGLE SE LIMITANT AU VALEURS PREDEFINIES EN DUR SANS//
//MOYEN DE VOIR NI D'AGIR DESSUS PENDANT L'EXECUTION.......//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
{
for (a=0;a<=m_speed;a++); // temps entre step
_outp (888,4); //ordre commande moteur
m_ctr = m_ctr+1;
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//JE VEUX AFFICHER SUR UN CONTRÔLE LA VALEUR DE: m_ctr ; //
//J'AI ESSAYE AVEC UN IDC_EDIT EN PROTOCOLE DDV/DDX EN //
//UTILISANT UpdateData(TRUE)/UpdateData(FALSE)... //
//CA ME MARCHE PAS LE COMPILATEUR REFUSE MEME DE ME GENERER //
//L'EXE ... //
//PAR CONTRE SANS AFFICHAGE CA MARCHE MON MOTEUR TOURNE MAIS//
//EN "AVEUGLE SE LIMITANT AU VALEURS PREDEFINIES EN DUR SANS//
//MOYEN DE VOIR NI D'AGIR DESSUS PENDANT L'EXECUTION.......//
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
{
for (a=0;a<=m_speed;a++); // temps entre step
_outp (888,8); //ordre commande moteur
m_ctr = m_ctr+1;
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//JE VEUX AFFICHER SUR UN CONTRÔLE LA VALEUR DE: m_ctr ; //
//J'AI ESSAYE AVEC UN IDC_EDIT EN PROTOCOLE DDV/DDX EN //
//UTILISANT UpdateData(TRUE)/UpdateData(FALSE)... //
//CA ME MARCHE PAS LE COMPILATEUR REFUSE MEME DE ME GENERER //
//L'EXE ... //
//PAR CONTRE SANS AFFICHAGE CA MARCHE MON MOTEUR TOURNE MAIS//
//EN "AVEUGLE SE LIMITANT AU VALEURS PREDEFINIES EN DUR SANS//
//MOYEN DE VOIR NI D'AGIR DESSUS PENDANT L'EXECUTION.......// //
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
}
while (m_ctr < m_limit);
m_ctr = 0;
}
void CTestobjectDlg::OnButtonStopMotor2()
{
// TODO: Add your control notification handler code here
///////////////////////////////////////////////////////////////////////////
// JE VEUX POUVOIR FORCER LA VARIABLE m_limit A 1000 DANS LE
// DEROULEMENT DE LA FONCTION: void CTestobjectDlg::OnButtonRunMotor1()
// DE FACON A STOPPER LA PRECESSION DES PAS DU MOTEUR ET AINSI LE STOPPER
///////////////////////////////////////////////////////////////////////////
m_limit = 1000;
}