|
Ok but that doesn't help. Which functions are you using exactly to access the port ?
|
|
|
|
|
Thanks for you reply. I use Inp32 function which is in the inpout32.dll library - a very common used.
|
|
|
|
|
Hi,
I don't know much about LPT signal.
but i got simmiler problem in one of my project.
you do one thing begin main thread once some where in Oninitdialog() or On InitInstance().In main thread function in while(1) loop call child thread
& do your work in child thread & you must end that childthread in that childthread itself.
have a look on given sample....
OnInitInstance()
{
begin MyMainthread()...
}
void MyMainthread()
{
while(1)
{
begin mychildthread()
::Sleep(400);
}
}
void mychildthread()
{
//Do your work here....
........
.....
_EndThread();
}
I hope this will reduce your CPU Uses.....
Rahul Vaishnav
|
|
|
|
|
Thanks for your reply.
But the problem is the thread cannot sleep every 400ms before checking LPT port. The application must ensure that, where the LPT signal changes, it will immediately handle that.
|
|
|
|
|
If the particular pin isn't one of the ones that is monitored by WaitCommEvent, there is no built-in notification mechanism. Short of writing a parallel port driver to implement notification, try putting your busy-wait loop into a seperate thread that runs at a lower priority than the rest of your program.
Judy
|
|
|
|
|
Also, you use the work "immediately" - how immediate is immediate? Windows is not a real-time OS, and as such, does not guarantee response times, even within drivers.
|
|
|
|
|
TPN wrote: This loop cause the CPU usage always 100%...
And rightly so since you are not yielding control of the CPU. Consider a message pump/loop.
"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
|
|
|
|
|
I have used this code in my project for diduction of CPU uses..
it is working fine at my end.
if you dont want to use Sleep() then remove it & add WaitForSingleObject() as shown in given sample.
try it....i hope it will work...
while(1)
{
HANDLE hThread;
hThread = (HANDLE)_beginthread(CallchildFunction,0,NULL);
WaitForSingleObject(hThread, INFINITE);
::Sleep(500);
}
Rahul Vaishnav
|
|
|
|
|
node->next = (struct ListEntry *) malloc(sizeof(struct ListEntry));
what does it mean,i want go get a particular answer,thanks
|
|
|
|
|
void main(void)
{
int i;
struct ListEntry {
int number;
struct ListEntry *next;
} start, *node;
start.next = NULL; /* Empty list*/
node = &start; /* Point to the start of the list*/
for (i = 1; i <= 10; i++)
{
node->next = (struct ListEntry *) malloc(sizeof( ListEntry));
node = node->next; //here the pointer is setted to node?
node->number = i;
node->next = NULL; // what does this mean?
}
/* Display the list*/
node = start.next;
while (node)
{
printf("%d ", node->number);
node = node->next;
}
}
maybe there are some unnecessary sentences,can you help me find out them that let me feel more clear
|
|
|
|
|
what's your question here ?
please reuse the other post, and reply to my answer if you want more...
also, when you post some code samples, please use the <pre></pre> html tags to format your message.
|
|
|
|
|
Mister youbo,
i'm goin to answer you, but before, here some comments i have to say to you, which i want you to take from the good, wise side...
you've been asking several question like this one, which are obviously from a beginner. You still can ask when you don't understand, but a better solution would be to learn the C/C++ languages a bit deeper to get rid of these by yourself.
ok then, let's go:
youbo wrote: node->next = (struct ListEntry *) malloc(sizeof(struct ListEntry));
it seems to me that you have a linked list, and that you code in C (correct me if i'm wrong).
a linked list is compound of nodes; each node stores a value, and has a link (pointer) to the node next to it in the list.
for what i understand here, node might be defined as a struct (ListEntry ), and next is defined inside it to being a pointer to another node (ListEntry* ).
for the right par of the assignment operator, we have a call the the malloc() function.
malloc() is used to allocate memory dynamically on the heap. you give it an integer parameter which tells it the amount of memory to allocate. here, sizeof(struct ListEntry) ; that mean, "allocate the amount which a ListEntry structure regularly takes in memory".
then, as malloc() returns a void* (a pointer to anything), we must translate it to the type of pointer which will store the returned value, by using a cast operation. that's performed with the (struct ListEntry*) prepending the malloc call.
then, once the memory is allocated, the address of that memory is returned, and casted to the type of a "pointer to a node in the list", we can assign this to the next member of the node struct (thus the syntax node->next )
any more questions ?
|
|
|
|
|
I gave you a 5; even though I found your explanation a bit confusing and I know multiple ways to link structures together: Single, Double, Single with parent child, Double with parent child, and various trees.
They really do need to spend some quality time trying to figure it out on their own.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
John R. Shaw wrote: gave you a 5; even though I found your explanation a bit
thanks John.
please, tell me what's confusing you, so that i can modify the most consequently
also, i too know veral kind of linked lists, but as the OP is a beginner, I didn't want to give him too much useless explanations...
|
|
|
|
|
Your wording was confusing (at first glance) and an example would have helped, especially for a beginner. “baeten” gave an example (although it is not a unidirectional list), since I posted, and that combined with what you said should help them figure it out.
If I was not so tired, I probably would have made it simpler (like ‘baeten”):
It is trying to allocate the next node in a linked list, which is equivalent to adding a new link to a chain. The allocation may fail so make sure that malloc does not return NULL.
node : A memory pointer to type ListEntry ; that is the address of a memory block containing a ListEntry structure (a node).
node->next : The next link in the chain; a pointer to the next structure (node).
….
A linked list looks like this in memory node->next->next->next->NULL , where NULL is the end of the list (or chain).
…
Or something like that; I am not in the right frame of mind right now. You did a good job and they need to search for a tutorial and spend time playing with lists.
Good night, or day (5 A.M. here).
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Hi,
that's a unidirectional list.
if your struct ListEntry is :
struct ListEntry {
char value[50];
struct ListEntry * next;
}
you allocate the first element, so you have a string and a blank pointer.
struct ListEntry *First = (struct ListEntry*)malloc(sizeof(struct ListEntry*));
First->next = NULL;
strcpy(First->value,"empty");
now you set the next-pointer to a new allocation of a new struct.
First->next = (struct ListEntry*)malloc(sizeof(struct ListEntry*));
So you can reach the new Element by dereferencing the node->next : node->next->value.
You should always store and save the first element.
Each time you like to add a new element you need to loop from the first element to the last
( which is the element with the next-pointer as NULL )
If you have 5 elements with numbers into it, it can be represented this way :
|"one"|0x4567| ---> |"two"|0x4568| --> |"three"|0x4569| ---> |"four"|0x4570| ---> |"five"|NULL|
|
|
|
|
|
OK,i will remember your idea!toxxct
|
|
|
|
|
If you want to reply to toxcct , than you have to use the reply button at the end of the message comes from toxcct .
This is an hidden rule of this forum-board.
-- modified at 4:57 Thursday 27th September, 2007
Russell
|
|
|
|
|
Russell` wrote: toxxct
misspelt. toxcct
|
|
|
|
|
|
How to identify given image is too dark or light?
Input format of the file is tif and jpg.
|
|
|
|
|
By taking a look at it I suppose...
Please don't mark your topic with the word Urgent.
Waldermort
|
|
|
|
|
WalderMort wrote: Please don't mark your topic with the word Urgent.
'5' for this
|
|
|
|
|
images are made of pixel, then every pixel has got a color, the color is a combination of red-green-blue (RGB).
white is RGB(255,255,255), black is RGB(0,0,0).
Convert your image in a gray scale:
take the color of every pixel (r,g,b) then compute c=(r+g+b)/3, so the gray pixel of a new image can be RGB(c,c,c), but you can simply store c somewhere.
Then compute the mean value of c on all the image and compare it with a treshold.
do something like this:
if c_mean is less then 50 the image is too dark
if c_mean is greater then 200 the image is too light
hope helps
Russell
|
|
|
|
|
Russell` wrote: compute c=(r+g+b)/3,
But the brightness is not simply the average, right? Red has low intensity compared to others. I dont remember the exact ratio.
- NS -
|
|
|
|