|
kcynic wrote: but where would be a assert occur.
somebody would tell me why?
Not without more information. 99.99% of the time the ASSERT() statement itself will tell you exactly what is wrong.
Darker than a black steer's tookus on a moonless praire night
Within you lies the power for good, use it!!!
|
|
|
|
|
what is a virtual key code for number keys.
Like VK_TAB for tab .
for 0 - 9 what is a key code.
|
|
|
|
|
|
|
Hi all,
i have made a worker thread ,that worker thread is called from a function every time a condition is met.So i have several instances of same thread running at same time.So i want to know that if i want to close all instances of that thread, single AfxEndThread will close the threads or i have to use some other method.
thanks in advance
|
|
|
|
|
my problem got solved using TerminateThread. but the new problem is when thread is not running and the function calls TerminateThread it gives debug asserstion failed error. i have also tried using:
if(::GetExitCodeThread(CloseTh->m_hThread,0))
::TerminateThread(CloseTh->m_hThread,0);
but it also gives debug assertion failed may be i m not using it correctly.
Can annybody help me in this
thanks in advance
|
|
|
|
|
No. Never use TerminateThread unless there is a strong reason for that. TerminateThread simply makes the system to kill the thread whereas the thread never gets known about its death.
--
=====
Arman
|
|
|
|
|
|
Actually no need to use AfxEndThread at all. The proper way to exit a thread is to inform it about that. Which in turn will return from the controlling function.
Please see this article[^]. It describes the way how to do what you wonder now.
Sortly, here you have a synchronization issue. Prepare an event which would be listened by all the threads. Then inside some other thread [I guess a UI thread] you would pulse the event and thus let the threads to exit properly.
--
=====
Arman
|
|
|
|
|
I head a derived class from CHeaderCtrl.
But I don't know why it would be draw well only when I click the header.
If I click out of the header's area, it would disappear!
Why?
|
|
|
|
|
|
Thanks,
I will have a try now.And if you would like to tell me how to change the height of the listitems?
|
|
|
|
|
|
I have an urgent question. I'm developing an application for a uni assignment which communicates with a vehicle CAN bus adapter with an FTDI chip, and I only have access to the car for another 2h. I'm trying to read data from the FTDI buffer, but what's returned is in what looks to be the extended character set (basically jibberish), not the standard which I am expecting. I'm spooling it to a csv file using Char::ToString(). My code for FT_read (defined within the driver .dll, http://www.ftdichip.com/Support/Knowledgebase/index.html?programmingguides.htm under Programming guides, D2XX,Classic Interface Functions), is as below:
if(FT_Read(handle, received_buffer, byte_count, &num_bytes_received) != FT_OK)
{
MessageBox::Show("Error: Read Failed"); //unable to open device
//Close_FTDI();
return 0; //Error
}
else
{
return 1; //Success
//debug_output_txt->AppendText(received_buffer); //output received characters
}
where received_buffer is char received_buffer[256], and byte count and num_bytes_received are DWORD(unsigned long).
I just read on the ftdi site pasted above, that the data type for the received_buffer should be lpvoid - which is typedef void * lpvoid. I'm not that good with pointers, so could this be where I'm going wrong? Although, my code is almost a direct copy of their example.
Any idea guys?
Sorry about the lack of structure in my post - I'm a tad on edge at the moment.
Cheers
John
|
|
|
|
|
Not seeing all your code, all I can do is guess.
Did you initialize recieve_buffer before calling FT_Read() ?
Is FT_Read() timing out or was it successful? - According to the docs you provided timeout and success return the same value.
what is the value of byte_count and num_bytes_read both before and after the call to FT_Read() ?
Darker than a black steer's tookus on a moonless praire night
Within you lies the power for good, use it!!!
|
|
|
|
|
Yes receive_buffer is initialised before calling FT_Read (global), FT_Read was successful - byte_count and num_bytes_read return the same values after the read. Some more code is below (is there any way to do attachments?)
//typedefs
typedef unsigned long DWORD;
typedef void * LPVOID;
//globals
char received_buffer [256];
DWORD byte_count = 0;
int Buffer_Count()
{
if(FT_GetQueueStatus(handle, &byte_count) != FT_OK)
{
//MessageBox::Show("Error: Failed to read queue"); //unable to open device
//Close_FTDI();
return 0;
}
else
//MessageBox::Show(byte_count.ToString()); //DEBUG - how many is in the queue?
return 1;
} // END: int Buffer_Count()
int Buffer_Read()
{
DWORD num_bytes_received;
if(Buffer_Count() == 1) // get number of bytes stored in buffer and ensure success
{
if(byte_count > 0)
{
if(FT_Read(handle, received_buffer, byte_count, &num_bytes_received) != FT_OK)
{
MessageBox::Show("Error: Read Failed"); //unable to open device
Close_FTDI();
return 0; //Error
}
else
{
return 1; //Success
//debug_output_txt->AppendText(received_buffer); //output received characters
}
}
else return 2; //No new data
}
else
return 0; //Buffer Count Error
} // END: void Buffer_Read()
I think I may have found the problem, but can't try it until the car comes back in an hour or so. FT_Read wants a pointer to the array ->(LPVOID)received_buffer (then subsequent elements addressed (LPVOID)received_buffer++ I assume), but i'm passing received_buffer, which is different???? Could this explain anything? Perhaps the gibberish is due to incorrect addressing?
Thanks for the help.
|
|
|
|
|
donno1 wrote: FT_Read wants a pointer to the array ->(LPVOID)received_buffer (then subsequent elements addressed (LPVOID)received_buffer++ I assume), but i'm passing received_buffer, which is different????
The way you are doing it should be just fine.
You should initialize recieved_buffer and num_bytes_recieved before you use them. Makes it easier to spot errors.
char received_buffer [256] = {0};
DWORD num_bytes_received = 0;
Also, what kind of data are you expecting to recieve from the device? Is it suppose to be human readable text? Or is the "gibberish" the actual data that has to properly interpreted?
It's not rocket surgery!
Within you lies the power for good, use it!!!
|
|
|
|
|
Ok I'll try that.
Should be receiving human readable chars (upper case letters and numbers).
Cheers
|
|
|
|
|
Unfortunately no luck and the car has gone. I'm still just getting funky characters.
￾￾￾￾￾￾￾￾￾￾￾￾￾￾￾￾￾￾￾￾￾￾￾ï
I also tried appending it to an integer, and just kept getting -2 for each character (0xFE).
Any ideas?
|
|
|
|
|
I'd try printing out a hex listing of the information you receive(maybe with ASCII equivalent for each byte), to see if you can see a pattern. Forcing it to a string can hide information.
Maybe display 2 bytes or 4 bytes per line, if you are expecting multi-byte characters.
|
|
|
|
|
I tried printing out each character individually at one stage, both data_buffer[0].ToString() and Char::ToString(data_buffer[0]), then removing the first element until there were none left (data_buffer is the vector I was referring to in the previous post). The results were -2 and ￾ for the two ToStrings respectively, repeating for each character received.
|
|
|
|
|
What I suggest you try is after you do your FT_Read call, do the following:
printf("Byte values are as follows: ");<br />
for (counter = 0; counter < num_bytes_received; counter++)<br />
printf("%02x ", received_buffer[counter]);<br />
Looking at the numeric values may give you a clue. If they are repeating, it sounds like there is some problem. Or maybe the car CAN bus is waiting for you to send some command - until you do, it just sends its status values (never worked with them, no idea of the concept.)
|
|
|
|
|
hello i work on code that open a file and try to find how many times there is a CString inside this file . (compare fuction work perfectly thanks to Whitesky and prasad )
my problem everything work fine except while loop (when start the reading) and everything above this while (if i type str. it doesnt pop up menu of CString::member fuction
WArray and FArray already declarate before
and Compare (CString , CString) is that a problem ? because i give in this loop as 1 parameter a LPCSTR
CArray<cstring ,="" cstring=""> RArray;
CString FilePathName;
CString LineRead ;
CString str7;
int ntimes=0;
const int sz =100;
char buf[sz];
CString sl , slsl;
sl = "\\" ;
FilePathName = m_FolderName + FArray.GetAt(0);
m_List.AddString(FilePathName);
ifstream FileText(FilePathName);
while(FileText.get(buf,sz))
{
FileText.get();
LineRead = (LPCSTR) buf;
for ( int m = 0 ; m < WArray.GetSize() ; m++)
{
str7 = WArray.GetAt(m);
ntimes = ntimes + Compare(LineRead , str7);
}
}
FileText.close();
return;
CString str13;
str13.Format(_T("%d"),ntimes);
AfxMessageBox(str);
-- modified at 20:12 Friday 18th May, 2007
|
|
|
|
|
Hi,
Even I can see many problem in your code. But the problem you have mention is because of the "FileText.get(buf,sz))" in condition for the while.
Manoj
Never Give up
|
|
|
|
|
I'm reciveing the following warning:
nochkclr.obj : warning LNK4204: 'R:\Visual Studio\\\Debug\libc.pdb' is missing debugging information for referencing module; linking object as if no debug info
How can I solve this?
Thanking you in advance for your help and time.
|
|
|
|