|
RMLPilot wrote: The problem is how do I stop the current read operation
Have you looked at SetCommTimeouts() ?
|
|
|
|
|
Hans Dietrich wrote: Have you looked at SetCommTimeouts()?
I tried a look at SetCommTimeouts() but it did not work. Perhaps I had the parameters wrong. I used the following:
COMMTIMEOUTS Timeouts;
ZeroMemory(&Timeouts, sizeof(COMMTIMEOUTS));
Timeouts.ReadIntervalTimeout = 20;
Timeouts.ReadTotalTimeoutMultiplier = 0;
Timeouts.ReadTotalTimeoutConstant = 20;
Timeouts.WriteTotalTimeoutMultiplier = 0;
Timeouts.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(Timeouts);
My understanding of these values is the I shouldn't get the event unless either 20 ms has passed between input bytes or (0 ms * 1400 bytes) + 20 ms has passed. This did not seem to work, I got about a second delay between events. Did I misinterpret the documentation on this call?
|
|
|
|
|
|
How about using async I/O, aka overlapped I/O, to talk to the serial port and, then if your timer expires, cancel the ReadFile using the CancelIo.
One thing to consider is if a partial block of data comes in when your timer expires. What will you do if 500 bytes have come in when your timer expires?
Assuming the source of the data always puts the data onto the serial line in 1400 byte chunks, another idea to consider is to not use a continuous retry loop to read the data. Instead, use the WaitCommEvent function to detect when a byte has been read by the port and then calling the ReadFile to read the 1400 bytes.
Judy
|
|
|
|
|
i have been mad on my code it give me results i cant fingure out how they come
i want to find how many words there are in a string
yes123ok2 no but !@#$ ok <=== 5 words
my code
int CInfoRecoverDlg::WordDocu(CString line)
{
int y= 0;
int x = line.GetLength();
for ( int i = 0 ; i < x ; i++)
{
if ( x >1)
{
if ( !_istalpha((line.GetAt(i)) && _istalpha(line.GetAt(i-1))))
{
y = y +1;
}
}
}
return y;
}
void CInfoRecoverDlg::OnButton1()
{
CString str1;
CString str = "yes";
CString line = "2d1s";
CString str2;
str2.Format(_T("%d"),WordDocu(line));
AfxMessageBox(str2);
}
i dont care so much to correct the code but for how much stupid f***ing retard i could be
the AfxMessageBox appear me 4 while
i try to say with my code if index = not character and (index-1) = character then there will be 1 word
|
|
|
|
|
I guess first of all, how do you define a word?
What separates words? Any non alphabetic character including whitespace?
Just whitespace?
How many words are in this string - "yes123ok2"
How many do you expect in this string "!@#$ ok" ?
I thought I read in other post that you're looking for words like google search line.
If so, looking for whitespace seems the way to go.
So a string like "yes no maybe" is 3 words.
Is that what you are trying to do?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
i am trying to do yes123ok2 = 2 words
!@#$ok = 1 word !!@#$ ok = 1 word
yes no maybe = 3 words
|
|
|
|
|
Also
Hello !My name is Papas, John Papas!
i want to take as words My Papas and Papas too (not only the words between whitespace)
|
|
|
|
|
well the code work fine (once again) but only for the CString i intiallize and valued inside my code
when i try to read a file.txt
file.txt :
yes ok i will say "yes"
and i want to compare with CString str = "yes"; it doesn't work find
but if i want to compare CString str1 = "yes ok i will say \"yes\"" with CString st2 = "yes" then it work fine :/
|
|
|
|
|
Immunity18 wrote: well the code work fine (once again) but only for the CString i intiallize and valued inside my code
In that case, don't touch anything! Look at the string you read from the file in the debugger.
What's different about it?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I think you want if(i>1) not if(x>1) in the for loop. (Or just start the loop with i =1 since you don't do anything in the i =0 iteration.)
|
|
|
|
|
After I split the main frame into 2 row x 1 column. Standard AfxMessageBox no longer displaying and hang the program in MFC. What is the problem?
|
|
|
|
|
How did you split the window?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
I have a SDI application in MFC. I split the main frame to 2 rows and 1 columm, then further split first row of the main frame to 1 row and 2 columns statically. the following code is added to OnCreateClient().
// split main frame
m_mainSplitterFrame.CreateStatic(this,2,1);
// further split top main frame to one row and 2 columns
m_childSplitterFrame.CreateStatic(&m_mainSplitterFrame,2,1, WS_CHILD | WS_VISISBLE,m_mainSpitterFrame.IdFromColRow(0,0));
//Create view for sub frame
m_childSplitterFrame.CreateView(0,0,RUNTIME_CLASS(CMyChildView),CSize(100,100),pContext);
m_childSplitterFrame.CreateView(0,1,RUNTIME_CLASS(CMyChildView),CSize(100,100),pContext);
// create bottom view
m_mainSplitterFrame.createView(1,0,RUNTIME_CLASS(CMyMainView),CSize(100,100),pcontext);
retrun TRUE;
|
|
|
|
|
Well, Im not sure about... It can be an intern conflict with the frames/windows. Does the MessageBox (NULL, "Message", "Caption", MB_OK); work?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
i got this warning when i try to use isletter() in my WordDocu()
{
CString p[26];
CString v[26];
p[0] = "A";
p[1] = "B";
......
p[24] = "Y";
p[25] = "Z";
v[0] = "a";
v[1] = "b";
....
v[24] = "y";
v[25] = "z";
for (int i = 0 ; i <26 ; i++)
{
if ( v[i] == str || p[i] == str)
{
return FALSE;
break;
}
else if ( i==25 &&( v[i] != str && p[i] != str))
{
return TRUE;
}
else
{
return TRUE;
}
}
}
is there any path i dont wrote return TRUE/FALSE ? :/
|
|
|
|
|
It doesn't look like it.
Maybe you fooled the compiler by putting a break; after a return.
And why have a for() loop if it always exits the first iteration?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
i want to know when a GetAt(i) is not letter (a-z A-Z) so it would be 1234567890!@$#^%^ etc
i want this so i can find how many words exist in a string
|
|
|
|
|
Immunity18 wrote: want to know when a GetAt(i) is not letter (a-z A-Z) so it would be 1234567890!@$#^%^ etc
if (0 == _istalpha(str.GetAt(...)))
{
}
I don't know what the problem with isalpha/iswalpha was...
Regardless, look at your for loop - no matter what the condition, the function returns.
To the compiler there's no return after the for loop. If the for loop condition fails before the
first iteration, then no value is returned. We know the for loop will always execute (because
for (int i = 0 ; i <26 ...) but the compiler doesn't.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
the _istalpha create me a problem and while it work fine for CStrings intiliaze and valued in code
it dont work for CString (buf) from File.txt
|
|
|
|
|
hmm well I never saw that code so I'm not sure why but it should work on any character you pass
to it.
There's nothing wrong with using your own function, but you probably want to fix it so
it works properly
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
you can see my code with alpha in below post
Different results when , compare 2 strings and 1 str with 1 str from file
|
|
|
|
|
can i ask something the isalpha how it works?
i mean i want only A-Z a-z i dont want numbers and !@#$~>time
isalpha work for that?
|
|
|
|
|
That's exactly what it does. It returns non-zero if the character is A-Z or a-z.
To find something NOT alphabetic then look for it to return 0.
From the posts below, it doesn't seem that this is the problem. It looks like you need to step
through your code and see exactly what's going on and in what order
If you are looking for matching words then why are you looking for non-alpha characters.
Don't you want to look for whitespace?
MArk
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
whitespaces = " " ?
That means this site (Codeproject) wouldn't reveal in my search because it is between ( ) ?
i thought an alorithm if the letter in i isn't character + letter in (i-1) is character then we got a word
"yes i think works correctly but not in my code
so here with that algorith it would find 10 words
Well i will alt tab back to Visual studio and alchemy with isalpha
To find something NOT alphabetic then look for it to return 0. i think this helped me
|
|
|
|