|
Hello,
I have a difficulty regarding my project. I want to set or reset the data pins on parallel port 'lpt1'.Is there is any function to do this?
Also I want to monitor the printer port like, what is the status of it,i.e. which data pins are set and which are reset and then I want to store these values in a database to take further action.
Rohit Deshpande-
atotalgeek@gmail.com
|
|
|
|
|
The parallel port is accessed through I/O calls. The lpt1 address is usually 0x378 (data), 0x379 (status), 0x37a (control). You can use these assembly functions to write and read the port:
inline char inportb(short port)
{
char rtn;
__asm {
mov dx, port
in al,dx
mov rtn, al
}
return rtn;
}
inline void outportb(short port, char data)
{
__asm {
mov al, data
mov dx, port
out dx, al
}
}
But keep in mind that "in" and "out" are priviledged instructions and will cause an exception on NT/2000/XP. To use them you'll need to grant the process special priviledges using an installed service or similar. If you can't find info on that I may be able to dig up my old code.
Do some google searches on the above and it should answer most of your questions. I also recommend the book "Parallel Port Complete" by Jan Axelson. I used it extensively years ago and it is indeed complete
Nicholas
|
|
|
|
|
Thanks Nicholas,
Well I will definately do some google searches for that special priviledges.But do you have some code written in C++ so that i can easily implement it in VC++?
And also help regarding monitoring the lpt1.
Rohit Deshpande-
atotalgeek@gmail.com
|
|
|
|
|
Hi again-
Regarding monitoring you'll need to use the 'status' IO address. Some ports also are bi-directional and you can read the data on the D0-D7 pins using the data IO address. Read up on all these things to learn more. It's all out there...
Regarding giving your program IO access, here's a solution that should work for you. My solution was implemented the same way:
http://pages.zoom.co.uk/andyc/ntdriver.htm
Good luck,
Nicholas
|
|
|
|
|
|
u will also find the function outportb() and inportb(); a useful one for thiz(just mention the port name "0x378" and the databyte to be sent/to be recieved.....
as said before u can use thiz for the control and status port as well.....
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
Hi, there. It really depends on what kind of interaction you need. If you are using the standard printer protocols like Nibble mode or EPP mode etc, you should use the WIN32 API to read/write from the port. Or if u want to access the raw port registers directly, one good free source is the one provided by beyondlogic. Just google for it , its called INPOUT32.DLL.It has a driver that allows direct access to the parallel port. I hope this will help you.
there's no such thing as a stupid programmer...
|
|
|
|
|
It's a stupid question, I know, but anyway..
Suppose, I have some MDI application with a modeless property sheet. In one of the property pages classes (CInput: public CPropertyPage) I have a public function AddEditBox() (which creates and displays Edit Boxes). I want to call that function on some event, which I handlе in my View class.. what shoul I do?
|
|
|
|
|
Obtain pointer to that property page and call function using it making sure this page is an active one.
If you gave more details as where property sheet exists I could give you a hint on how to obtain that pointer.
JohnCz
|
|
|
|
|
Please, tell me, what's wrong here:
class CInput : public CPropertyPage<br />
{...<br />
void AddEditBox();<br />
...<br />
}<br />
<br />
<br />
void CInput::AddEditBox()<br />
{<br />
<br />
CRect rect( 8, 25, 28, 45 );<br />
int ID = 4000;<br />
<br />
CEdit *p = new CEdit;<br />
<br />
p->Create( WS_CHILD | WS_VISIBLE | WS_TABSTOP |<br />
ES_AUTOHSCROLL | WS_BORDER | WS_DISABLED, rect, this, ID );<br />
<br />
}
Now, I want to call this function from my View class (on WM_LBUTTONUP event)
void CMyView::OnLButtonUp(UINT nFlags, CPoint point) <br />
{<br />
...<br />
CInput inp;<br />
...<br />
inp.AddInputEdit();<br />
...<br />
}
but Create function returns 0..? why? what I did wrong..?
|
|
|
|
|
It imperative that if you post code post all relevant parts.
You are instantiating object of the CInput type.
Your . . . do not allow me to see if you call Create member of the page. Therefore the first thing is that raises question is that you are calling member function (AddInputEdit) that requires valid window handle.
Even if you were successful creating edit control, this page is not a part of property sheet anyway and on the top of it will be destroyed when OnLButtonUp goes out of scope.
You have to obtain pointer to existing page, make sure that window is attached to it and then call AddInputEdit.
Page has no window attaché until is activated.
JohnCz
|
|
|
|
|
Thanks a lot! I've fixed the error like You told me and now everything works properly and I'm very happy about that
|
|
|
|
|
hi guys
i need help on this real bad....
i posted this messege earlier but didnt solve the problem .. will someone plese respond to this .. please...........
I have a MFC application dialog based.. has 2 dialog forms say dialog1 and dialog 2.. in dialog1 i have a picture holder (IDC_HOLDER). what i need to do is get the "Rect" value of that holder from dialog2 .. i can do that from dialog1 with
CRect rc;
GetDlgItem(IDC_HOLDER)->GetWindowRect(rc);
but how to access that from dialog2....
i tried
CDialog1* dlg;<br />
dlg->GetDlgItem(IDC_HOLDER)->GetWindowRect(rc);
doesnot work...
my whole project has come to HALT by this ... please help .. someone !!!!!
thanks
zm
where are all the GURUS???
|
|
|
|
|
|
Does dialog1 open dialog2? If it does, try the following:
1. Give dialog2 a member variable - HWND m_hWnd1;
2. Before dialog1 opens dialog2 use - dialog2.m_hWnd1 = m_hWnd;
Then use:
RECT r;
::GetWindowRect(::GetDlgItem(m_hWnd1, IDC_HOLDER), &r);
|
|
|
|
|
Admission of guilt
This is a shameless ploy to get my fellow CPians help this sleep deprived developer meet yet another (self-imposed) insanely aggressive deadline.
Anyone care to provide the implementation of (or a pointer to) this word wrap method?
void wordWrap
(CString strText,
int nWrap,
CPtrArray& lines);
Example:
CString strText = "The quick brown fox jumps over the lazy dog";
CPtrArray lines;
wordWrap (strText, 17, lines);
ASSERT (lines.GetSize() == 3);
ASSERT (lines[0] == "The quick brown");
ASSERT (lines[1] == "fox jumps over");
ASSERT (lines[2] == "the lazy dog");
Many thanks!
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Best I can do on short notice is this article[^].
Two problems with it.
1) It's in VB, so some translation is needed
2) It pads lines with spaces, so some truncation is needed
I would guess that doing those two is less effort than developing it from scratch!
|
|
|
|
|
Thanks, Graham! I'd come across that one as well as a couple of implementations in Java. PJ Arends rose to the occasion and (not surprisingly) crafted a great solution.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
nWrap is the maximun number of characters in the line?
Does lines have to be CPtrArray, or can it be redeclared as a CStringArray instead?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
void wordWrap (CString strText, int nWrap, CStringArray &lines)
{
int count = 0;
TCHAR *ptr = strText.GetBuffer(strText.GetLength() + 1);
TCHAR *EndofLine = ptr;
TCHAR *StartofLine = ptr;
while (*ptr)
{
while (*ptr && !_istspace(*ptr))
{
ptr = _tcsinc(ptr);
++count;
}
if (count <= nWrap)
EndofLine = ptr;
if (!*ptr || count > nWrap)
{
ptr = EndofLine;
TCHAR temp = *ptr;
*ptr = 0;
lines.Add(StartofLine);
*ptr = temp;
StartofLine = _tcsinc(ptr);
count = -1;
}
if (*ptr)
{
ptr = _tcsinc(ptr);
++count;
}
}
strText.ReleaseBuffer();
}
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
PJ Arends wrote:
Honoured as one of The Most Helpful Members of 2004
And well deserved. Thanks, PJ!
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hmm, the algorithm sometimes goes into an infinite loop. I worked out an alternate implementation which seems to work. Time will tell...
void wrap
(CString strString,
int nWrap,
CStringArray& lines)
{
int nStart = 0;
int nEnd = 0;
do {
nEnd = nStart + nWrap;
if (nEnd >= strString.GetLength())
nEnd = strString.GetLength() - 1;
if (nEnd != strString.GetLength() - 1)
while ((nEnd >= 0) && (strString.GetAt (nEnd) != _T(' ')))
nEnd--;
CString strNextLine;
if ((nEnd - nStart) > 0) {
strNextLine = strString.Mid (nStart, (nEnd - nStart) + 1);
lines.Add (strNextLine);
}
nStart = nEnd + 1;
} while (nStart < strString.GetLength());
return;
} /ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
PJ Arends wrote:
nWrap is the maximun number of characters in the line?
Yes, nWrap is the wrap boundary, i.e. the longest length of the resulting lines.
PJ Arends wrote:
Does lines have to be CPtrArray,
Gak! I told you I was sleep deprived.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hi all,
I have a server and some clients,
I wamt a good solution to send messages to this
clients together.
Best Wishes,
Thanks.
|
|
|
|
|