|
Check out the ISensNetwork interface.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
How do i use the button fucntion to activate the LEDS?
The source code below is for the checkbox method:
Hope to hear from you soon!
P.s: ( Im using pin 2,4,6,and 8 of the parallel port btw to connect to the LEDs)
// ParallelPortDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ParallelPort.h"
#include "ParallelPortDlg.h"
#define DATA 0x378
#define STATUS 0x379
#define CONTROL 0x37a
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CParallelPortDlg dialog
CParallelPortDlg::CParallelPortDlg(CWnd* pParent /*=NULL*/)
: CDialog(CParallelPortDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CParallelPortDlg)
m_pin2 = FALSE;
m_pin4 = FALSE;
m_pin6 = FALSE;
m_pin8 = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CParallelPortDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CParallelPortDlg)
DDX_Check(pDX, IDC_Pin2, m_pin2);
DDX_Check(pDX, IDC_Pin4, m_pin4);
DDX_Check(pDX, IDC_Pin6, m_pin6);
DDX_Check(pDX, IDC_Pin8, m_pin8);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CParallelPortDlg, CDialog)
//{{AFX_MSG_MAP(CParallelPortDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
//}}AFX_MSG_MAP
//Code added by me from here.
ON_COMMAND_RANGE(IDC_Pin2, IDC_Pin9, ChangePin)
ON_COMMAND(IDC_Pin1, ChangeControl)
//Code added by me till here
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CParallelPortDlg message handlers
BOOL CParallelPortDlg::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//App.Wiz generated code
// TODO: Add extra initialization here
short _stdcall Inp32(short portaddr);
void _stdcall Out32(short portaddr, short datum);
SetTimer(1,200,NULL);
Out32(CONTROL, Inp32(CONTROL) & 0xDF);
UpdatePins();
return TRUE; // return TRUE unless you set the focus to a control
}
void CParallelPortDlg::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 CParallelPortDlg::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 CParallelPortDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CParallelPortDlg::UpdatePins()
{
short _stdcall Inp32(short portaddr);
void _stdcall Out32(short portaddr, short datum);
int reg;
reg=Inp32(STATUS);
if((reg & 0x40)==0) m_pin10=0; else m_pin10=1;
if((reg & 0x80)==0) m_pin11=0; else m_pin11=1;
if((reg & 0x20)==0) m_pin12=0; else m_pin12=1;
if((reg & 0x10)==0) m_pin13=0; else m_pin13=1;
if((reg & 0x08)==0) m_pin15=0; else m_pin15=1;
//////////
reg=Inp32(DATA);
if((reg & 0x01)==0) m_pin2=0; else m_pin2=1;
if((reg & 0x04)==0) m_pin4=0; else m_pin4=1;
if((reg & 0x10)==0) m_pin6=0; else m_pin6=1;
if((reg & 0x40)==0) m_pin8=0; else m_pin8=1;
//////
}
void CParallelPortDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// TODO: Add your message handler code here and/or call default
}
void CParallelPortDlg::ChangePin()
{
int data_register, new_register;
short _stdcall Inp32(short portaddr);
void _stdcall Out32(short portaddr, short datum);
UpdateData(TRUE);
data_register=Inp32( DATA );
new_register=0;
if( m_pin2==TRUE ) new_register |= 0x01;
if( m_pin4==TRUE ) new_register |= 0x04;
if( m_pin6==TRUE ) new_register |= 0x10;
if( m_pin8==TRUE ) new_register |= 0x40;
Out32(DATA, new_register);
}
void CParallelPortDlg::ChangeControl()
{
int control_register, new_register;
UpdateData(TRUE);
short _stdcall Inp32(short portaddr);
void _stdcall Out32(short portaddr, short datum);
control_register = Inp32( CONTROL );
new_register = control_register;
Out32(CONTROL, new_register);
}
|
|
|
|
|
Would you mind shortening this code ? specific to your "exact" probelm.
Use <pre> tags to post code.
Prasad
MS MVP - VC++
|
|
|
|
|
Do you really expect anyone to wade through all of this code? Post only the relevant portion, which is usually less than a dozen lines.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
A Class To Read from Text File(.txt) and Write to New Table in Design Visual C++
|
|
|
|
|
Sounds like a good header for an article on iostreams. It's obviously not a question, so what is it ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Ok.
1) How to read data in text file and
2) Write data to new table(this table is create or design in Visual C++ form)
I want coding to read and write in Visual C++
|
|
|
|
|
To Read Data, use CFile or CStdioFile class.
For more information try msdn library.
Importing it into your own designed table completely depends on the way you have designed the table.
Anurag Gandhi.
|
|
|
|
|
To read data, use ifstream whenever possible.
Depends what you mean by table, in a database ? Then it depends on how you're getting DB access.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
What does the following code do?????????
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
NT
|
|
|
|
|
if _DEBUG has been defined elsewhre, it defeines DEBUG_NEW and undefines THIS_FILE, then sets it to the current file namae. It's not C++, it's nasty C preprocessor stuff. Avoid if you can.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hence he has also to avoid the MFC Application Wizard!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Christian Graus wrote: it's nasty C preprocessor stuff. Avoid if you can
Maybe, but it's really handy for debugging MFC apps
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
For debug builds, it tells the compiler to use the crt debug "new" operator instead of the normal
one. The debug version adds leak detection and maybe some other stuff.
It also, as metioned, sets the THIS_FILE define to the current file. This information
is used when dumping memory leak info.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
When i derive a class from CWinThread from wizard its constructor and destructor are in protected. So i have to put them in public so as to create an object for that.
When the class is created why they are in protected as we cannot create an object?
Thank you
KIRAN PINJARLA
|
|
|
|
|
kiran.pinjarla wrote: When i derive a class from CWinThread from wizard its constructor and destructor are in protected. So i have to put them in public so as to create an object for that.
There's no need to since you don't create CWinThread derivatives that way: they are always created with a call to ::AfxBeginThread() and a opinter to the running instance is returned.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: There's no need to since you don't create CWinThread derivatives that way: they are always created with a call to ::AfxBeginThread()
But I can create a thread using the CWinThread::CreateThread() also. In that case we need an object right?
nave
|
|
|
|
|
Naveen R wrote: But I can create a thread using the CWinThread::CreateThread() also. In that case we need an object right?
Not quite.
Have a look at the arguments for CWinThread::CreateThread() . You have no way of specifying whether the thread is supposed to be a worker thread or a UI-thread. You specify this in the call to ::AfxBeginThread() .
MSDN on CWinThread::CreateThread: Use AfxBeginThread to create a thread object and execute it in one step. Use CreateThread if you want to reuse the thread object between successive creation and termination of thread executions.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: Have a look at the arguments for CWinThread::CreateThread()
That wasnt our discussion point Roger. you said we have no use creating a CWinthread object. But for this function, it needs a CWinThread object.
And about the GUI/Worker thread....who wants a worker thread using the CWinThread?
nave
|
|
|
|
|
Naveen R wrote: That wasnt our discussion point Roger. you said we have no use creating a CWinthread object. But for this function, it needs a CWinThread object.
Please read my post again and you will find I wrote that the CWinThread object is created with a call to ::AfxBeginThread() . Thats the way to create the object, it's also clearly stated by the MSDN documentation. This is also why the wizard doesn't declare the constructor as public, which was the OP's question from the beginning.
I have never implied that the CWinThread object doesn't need to be created.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Interesting. I personally have never used the AfxBeginThread() function. I always use the
two step method. Fits into my code better
"Use AfxBeginThread to create a thread object and execute it in one step. Use CreateThread if you
want to reuse the thread object between successive creation and termination of thread executions."
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thank you
Roger Stoltz wrote: they are always created with a call to ::AfxBeginThread()
So, Is it a bad practive deriving a class from CWinThread and calling CreateThread().
I have been doing like that.
KIRAN PINJARLA
|
|
|
|
|
kiran.pinjarla wrote: So, Is it a bad practive deriving a class from CWinThread and calling CreateThread()
Let's just say that from the MFC framework point of view you're supposed to use ::AfxBeginThread() . This is also why the constructor is not publically declared in the CWinThread dervied class created by the wizard.
Doing it the way you have been doing it will work; it will spawn a UI-thread.
But you have to alter the CWinThread derived class to make the constructor public. You will also need to write the error handling that ::AfxBeginThread() would help you with, such as freeing up memory.
I recommend you to follow the MSDN guidelines on this: use ::AfxBeginThread() .
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
kiran.pinjarla wrote: CWinThread from wizard its constructor and destructor are in protected
You are supposed to use CWinThread derived class, hence it is protected.
-- modified at 4:49 Tuesday 22nd May, 2007
See Rogers reply.
Prasad
MS MVP - VC++
|
|
|
|