|
i saw it, but why didn't he just updated his post ?
|
|
|
|
|
|
see me wrote: hey toxcct...am not a selfish guy
i didn't see the answer posted by Naveen.
hum, well, even you didn't see it, why have you deleted it, as you reasked it 10 minutes later... moreover, you're on a forum to share, ,not only to get an answer... what's been asked and answered can be found back if someone roam on the forum and search for what or what topic.
edit your posts, but don't delete them when you ask a question.
|
|
|
|
|
toxcct wrote: edit your posts, but don't delete them when you ask a question.
Ok
Dream bigger... Do bigger...Expect smaller
aji
|
|
|
|
|
|
Hello,
I am having troubles with sending data through RS232. I am using the class from Ramon de Klein:
http://www.codeproject.com/system/serial.asp
There I am working with the simple Serial Class (Overlapped).
My problem is that I can only send 16 Byte all together. If I try to send more than 16 Byte, its sending an empty message and I get a NAK from the other side ( I monitored this with a monitoring tool).
This is what the Overlapped structure is set to after sending data:
<br />
Internal 258 unsigned long<br />
InternalHigh 16 unsigned long<br />
Offset 0 unsigned long<br />
OffsetHigh 0 unsigned long<br />
Pointer 0x00000000 void *<br />
hEvent 0x00000780 void *<br />
As you can see, InternalHigh is set to 16. I dont know why. I cant figure out why I am only allowed to send 16 Byte. The dwInQueue as well as the dwOutQueue is big enough to hold more data.
The problem is that I absolutely have no clue where to search for that problem.
Is there anything that restricts the number of bytes to send?
Which codepart can be relevant for you?
This the write method:
<br />
LONG CSerial::Write (const void* pData, size_t iLen, DWORD* pdwWritten, LPOVERLAPPED lpOverlapped, DWORD dwTimeout)<br />
{<br />
CheckRequirements(lpOverlapped,dwTimeout);<br />
<br />
_ASSERTE(!lpOverlapped || pdwWritten);<br />
<br />
m_lLastError = ERROR_SUCCESS;<br />
<br />
DWORD dwWritten;<br />
if (pdwWritten == 0)<br />
{<br />
pdwWritten = &dwWritten;<br />
}<br />
<br />
*pdwWritten = 0;<br />
<br />
if (m_hFile == 0)<br />
{<br />
m_lLastError = ERROR_INVALID_HANDLE;<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Device is not opened\n");<br />
return m_lLastError;<br />
}<br />
<br />
#ifndef SERIAL_NO_OVERLAPPED<br />
<br />
if (!m_hevtOverlapped && (lpOverlapped || (dwTimeout != INFINITE)))<br />
{<br />
m_lLastError = ERROR_INVALID_FUNCTION;<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Overlapped I/O is disabled, specified parameters are illegal.\n");<br />
return m_lLastError;<br />
}<br />
<br />
OVERLAPPED ovInternal;<br />
if (!lpOverlapped && m_hevtOverlapped)<br />
{<br />
memset(&ovInternal,0,sizeof(ovInternal));<br />
ovInternal.hEvent = m_hevtOverlapped;<br />
<br />
lpOverlapped = &ovInternal;<br />
}<br />
<br />
_ASSERTE(!m_hevtOverlapped || HasOverlappedIoCompleted(lpOverlapped));<br />
<br />
char bla[255] = {0x0};<br />
strcpy(bla, (char*)pData);<br />
<br />
if( bla[iLen-1] == 0x03 )<br />
iLen++;<br />
<br />
if (!::WriteFile(m_hFile,pData,iLen,pdwWritten,lpOverlapped))<br />
{<br />
long lLastError = ::GetLastError();<br />
<br />
if (lLastError != ERROR_IO_PENDING)<br />
{<br />
m_lLastError = lLastError;<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Unable to write the data\n");<br />
return m_lLastError;<br />
}<br />
<br />
if (lpOverlapped == &ovInternal)<br />
{<br />
switch (::WaitForSingleObject(lpOverlapped->hEvent,dwTimeout))<br />
{<br />
case WAIT_OBJECT_0:<br />
if (!::GetOverlappedResult(m_hFile,lpOverlapped,pdwWritten,FALSE))<br />
{<br />
m_lLastError = ::GetLastError();<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Overlapped completed without result\n");<br />
return m_lLastError;<br />
}<br />
break;<br />
<br />
case WAIT_TIMEOUT:<br />
CancelCommIo();<br />
<br />
m_lLastError = ERROR_TIMEOUT;<br />
return m_lLastError;<br />
<br />
default:<br />
m_lLastError = ::GetLastError();<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Unable to wait until data has been sent\n");<br />
return m_lLastError;<br />
}<br />
}<br />
}<br />
else<br />
{<br />
if (lpOverlapped)<br />
::SetEvent(lpOverlapped->hEvent);<br />
}<br />
<br />
#else<br />
<br />
if (!::WriteFile(m_hFile,pData,iLen,pdwWritten,0))<br />
{<br />
m_lLastError = ::GetLastError();<br />
<br />
_RPTF0(_CRT_WARN,"CSerial::Write - Unable to write the data\n");<br />
return m_lLastError;<br />
}<br />
<br />
#endif<br />
<br />
return m_lLastError;<br />
}<br />
This is how I initialize the com port:
<br />
lLastError = rfi->serial.Open(_T("COM1"),10000,10000,true);<br />
if (lLastError != ERROR_SUCCESS)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to open COM-port"));<br />
<br />
lLastError = rfi->serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);<br />
if (lLastError != ERROR_SUCCESS)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port setting"));<br />
<br />
lLastError = rfi->serial.SetupHandshaking(CSerial::EHandshakeOff);<br />
if (lLastError != ERROR_SUCCESS)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port handshaking"));<br />
<br />
lLastError = rfi->serial.SetMask(CSerial::EEventBreak |<br />
CSerial::EEventCTS |<br />
CSerial::EEventDSR |<br />
CSerial::EEventError |<br />
CSerial::EEventRing |<br />
CSerial::EEventRLSD |<br />
CSerial::EEventRecv);<br />
if (lLastError != ERROR_SUCCESS)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port event mask"));<br />
<br />
lLastError = rfi->serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking);<br />
if (lLastError != ERROR_SUCCESS)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port read timeout."));<br />
<br />
HANDLE hevtOverlapped = ::CreateEvent(0,TRUE,FALSE,0);;<br />
if (hevtOverlapped == 0)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to create manual-reset event for overlapped I/O."));<br />
<br />
OVERLAPPED ov = {0};<br />
ov.hEvent = hevtOverlapped;<br />
<br />
HANDLE hevtStop = ::CreateEvent(0,TRUE,FALSE,_T("Overlapped_Stop_Event"));<br />
if (hevtStop == 0)<br />
rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to create manual-reset event for stop event."));<br />
I am searching for a solution for some days now, and it would be really really great to get some help, at least getting a starting point where to look at.
DKT
|
|
|
|
|
You can write more than 16 Bytes, I think the setup of the port.
Or the endpoint of the RS232 (the HArdware) is only liking 16 Bytes.
Can you write in 16 Byte loopes? If not there is big trouble.
Greetings from Germany
|
|
|
|
|
From germany? Nice, me too
No, the endpoint can handle more than 16 Bytes definetly.
I managed to write a total simple communication class which can write more than 16 Bytes. And I cant find the difference between them. I dont know where to search, and what to search for.
DKT
|
|
|
|
|
I believe you to change the Setup/Initialization of the Port. Compare every single value. There are some samples at CP try different to get it work.
Have you tried to write in loops???
//Meta-Code
while( DataToSend() )
{
Send16Bytes();
}
GetLastError() is also your friend!!!
Serial Port is a legacy problem so not so many know how to handle.
Greetings from Germany
|
|
|
|
|
We can execute a program by CreateProcess function,
but how can we limit the memory used by that program
(i.e. stop the program if it uses too much memory)?
|
|
|
|
|
You could limit the stack and heap sizes for the application, or even write your own memory manager for it.
Darka [ Xanya]
"When you're taught to love everyone, to love your enemies, then what value does that place on love?"
|
|
|
|
|
hi all i had made a service that beeps after a specified time interval.now i want that this service should be depend upon the some other services like RPC so that user cannot turn it off.
or like RPC service whose stop button does not work or is disabled.
Tasleem Arif
|
|
|
|
|
You cannot prevent them stopping your service this way, try handling SERVICE_CONTROL_STOP and not shutting down although I suspect Windows will just terminate your service as it will detect its failure to shut down.
why do this, I couldn't think of anything more annoying than a beeping service, especially one you cannot stop.
If the Service runs in the local system account, then ordinary users cannot stop it anyway as they do not have the correct permissons.
regards,
Darka [ Xanya]
"When you're taught to love everyone, to love your enemies, then what value does that place on love?"
|
|
|
|
|
i will make another application rather then simple beep.thanks for the answer i will try to implement it and tell the result of that.
Tasleem Arif
|
|
|
|
|
hi what i did is the remove all code from event handler function of the service and it works fine.
Tasleem Arif
|
|
|
|
|
cool
Darka [ Xanya]
"When you're taught to love everyone, to love your enemies, then what value does that place on love?"
|
|
|
|
|
Hi All,
i have one question related with CRichEditCtrl.
How can we identify the word underlying he mouse pointer?
means if i have some text in richedit.
1) programming window's is not easy.
2) Subclassing is tec*hnique by which you can process the messages
before the controll processes it.
* word is where mouse pointer is.
i want to get that word means i need to get the technique word when
mouse pointer is on it!!
how can i achieve this?
any help will be appreciated
Thanks and Regards
Harshal
|
|
|
|
|
CRichEditCtrl::CharFromPos()..?
nave
|
|
|
|
|
harsha_1234 wrote: identify the word underlying the mouse pointer
You will have to subclass the CRichEditCtrl.
Here is what I did in the MouseMove message. Just a crude idea on how you could proceed with this.
int i=CharFromPos(point);
SetSel (i,i+3);
char *mySel=new char[100];
GetSelText (mySel);
AfxMessageBox(mySel);
delete[] mySel;
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
i alway's get error that
error C2065: 'CharFromPos' : undeclared identifier
i mean CharFromPos is member msdn show's in that way
but it gives error
|
|
|
|
|
Did you subclass the richeditControl?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
int i = SendMessage(EM_CHARFROMPOS,0,LPARAM(&point));
SetSel (i,i+3);
char *mySel=new char[100];
GetSelText (mySel);
//AfxMessageBox(mySel);
delete[] mySel;
this is working fine
actually in sendmessage LPARAM requires the address of point structure
Thanks now i can proceed
|
|
|
|
|
How do you use CharFromPos its in CRichEditCtrl and in this error it seems you dont use from CRichEditCtrl
|
|
|
|
|
i will give you class definition
class CMyRichEdit : public CRichEditCtrl
{
// Construction
public:
CMyRichEdit();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyRichEdit)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMyRichEdit();
// Generated message map functions
protected:
//{{AFX_MSG(CMyRichEdit)
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnChange();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
void CMyRichEdit::OnMouseMove(UINT nFlags, CPoint point)
{
//int i=CharFromPos(point);// gives error
int i = SendMessage(EM_CHARFROMPOS,0,MAKELPARAM(point.x,point.y));
SetSel (i,i+3);
char *mySel=new char[100];
GetSelText (mySel);
AfxMessageBox(mySel);
delete[] mySel;
CRichEditCtrl::OnMouseMove(nFlags, point);
}
both fails
|
|
|
|
|
I dont have any error with this code
<br />
class CMyRichEdit : public CRichEditCtrl<br />
{<br />
public:<br />
CMyRichEdit();<br />
<br />
public:<br />
<br />
public:<br />
<br />
<br />
public:<br />
virtual ~CMyRichEdit();<br />
<br />
protected:<br />
afx_msg void OnMouseMove(UINT nFlags, CPoint point);<br />
<br />
DECLARE_MESSAGE_MAP()<br />
};<br />
CMyRichEdit::CMyRichEdit()
{
}
CMyRichEdit::~CMyRichEdit()
{
}
BEGIN_MESSAGE_MAP(CMyRichEdit, CRichEditCtrl)
END_MESSAGE_MAP()
void CMyRichEdit::OnMouseMove(UINT nFlags, CPoint point)
{
int i=CharFromPos(point);
i = SendMessage(EM_CHARFROMPOS,0,MAKELPARAM(point.x,point.y));
SetSel (i,i+3);
char *mySel=new char[100];
GetSelText (mySel);
AfxMessageBox(mySel);
delete[] mySel;
CRichEditCtrl::OnMouseMove(nFlags, point);
}
|
|
|
|
|