|
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
this is all the code i have in stdafx.h!!!
I have not add anything to it!!!!
This is the default file when you want to build a form.net application... and i dont undrestand the pupose of it entirlt.
|
|
|
|
|
hold on a sec
the program will not run
but in the comments it says:
fatal error C1084: cannot read CLR runtime data file c:....stdafx.obj
|
|
|
|
|
I'd do a clean and rebuild all, it's compiling the individual files but cannot read one of them for some reason.
And you should check the 'do not treat <'s as HTML tags' box below when you post anything that could be mistaken for a tag.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Thanks Christan. I dont know why it happens sometimes but I copied another sdfxa.cpp file from another project and it works fine now ;)
|
|
|
|
|
|
Hi, I would appreciate any help here: I have written a program to read data from a serial input and display the character value one at a time. I would like to alter the program to read binary data from the serial input, store the data as an array, and display the entire array at once. The new data should be integers. Right now, the data is displayed one at a time. I have very limited knowledge of Visual C++ and really need some help. Thanks.
|
|
|
|
|
Are you have trouble with stopbits or 7bit characters? What do you mean by "display" are you talking bout plotting it as you mentioned in the subject line or just displaying it numerically?
My neighbours think I am crazy - but they don't know that I have a trampoline. All they see my head bobbing up and down over the fence every five seconds
|
|
|
|
|
I guess my question is really: How do I read binary data from serial port into an array? I would like to have the array displayed on screen according to pixel value, as soon as the array is full, so they should be in an int array.(?) When array is full, it should clear and start reading again. Thank you.
|
|
|
|
|
Open the serial port using CreateFile. Read the data using ReadFile. Close the port using CloseHandle.
Here is some code to open the port:
class COMPort
{
public:
COMPort() {
m_bOpened=FALSE;
m_hCom=INVALID_HANDLE_VALUE;
}
~COMPort() {
if ( m_hCom != INVALID_HANDLE_VALUE ) {
CloseHandle(m_hCom);
}
}
BOOL OpenSerialPort();
public:
BOOL m_bOpened;
HANDLE m_hCom;
};
COMPort::OpenSerialPort()
{
if(!m_bOpened)
{
DCB dcb;
BOOL fSuccess;
COMMTIMEOUTS CommTimeouts;
m_hCom = CreateFile("COM2",
GENERIC_READ | GENERIC_WRITE,
0, NULL,
OPEN_EXISTING,
0, NULL);
if(m_hCom == INVALID_HANDLE_VALUE)
{
return FALSE;
}
fSuccess = GetCommState(m_hCom, &dcb);
if(!fSuccess)
{
return FALSE;
}
dcb.BaudRate = CBR_57600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
dcb.fBinary = TRUE;
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fDsrSensitivity = FALSE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
dcb.fParity = FALSE;
dcb.fNull = FALSE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fAbortOnError = FALSE;
fSuccess = SetCommState(m_hCom, &dcb);
if(!fSuccess)
{
return FALSE;
}
GetCommTimeouts(m_hCom, &CommTimeouts);
CommTimeouts.ReadIntervalTimeout = 20;
CommTimeouts.ReadTotalTimeoutMultiplier = 20;
CommTimeouts.WriteTotalTimeoutMultiplier = 0;
CommTimeouts.WriteTotalTimeoutConstant = 100;
fSuccess = SetCommTimeouts(m_hCom, &CommTimeouts);
if(!fSuccess)
{
return FALSE;
}
PurgeComm(m_hCom, PURGE_TXABORT | PURGE_RXABORT);
m_bOpened = TRUE;
}
return m_bOpened;
} Here is code to read the data:
COMPort::SomeMemberFunction()
{
DWORD num;
unsigned char data[10];
if(m_bOpened) ReadFile(m_hCom, &data[0], 1, &num, NULL);
} John
|
|
|
|
|
If you don't know the number of int's arriving than you should declare it as a templated vector, or CDWordArray and use SetAtGrow() to add the values. You also need to know if they are 16 bit or 32 bit integers although I suspect that they are 32 bit. If they are 32 bit and are in the correct byte order (look up little endian and big endian) you can just cast them into a memory space containing the data
for example if you read the data into a character array called sData and if you know the integer starts at sData[37], you can just go
int nBuf = (int*)(&(sData[37]));
then increment 4 bytes if it is 32 bits, for the next one, and so on.
Then to transfer it to a CDWordArray dwarData
dwarData.SetAtGrow(nNumValue++, nBuf);
You may be able to find some plotting routines in the MFC / Graphics section of Code Project to plot it.
My neighbours think I am crazy - but they don't know that I have a trampoline. All they see my head bobbing up and down over the fence every five seconds
|
|
|
|
|
BTW you seem to be under the impression that this is a half hour job and it sounds more like the better part of a week job, expecially if you are a beginner programmer in VC++.
My neighbours think I am crazy - but they don't know that I have a trampoline. All they see my head bobbing up and down over the fence every five seconds
|
|
|
|
|
http://www.codeproject.com/printing/prntscreen.asp
This article explains how to print a whole window, or the client area of the window. You should just modify the code and pass the handle to your cotrol in question instead of the handle to the whole window.
Peter Molnar
|
|
|
|
|
Please help me write a function for a dynamic array of Car objects.
In function I need to dynamicly allocate array size for the Car objects.
Thanks
|
|
|
|
|
|
You don't need to write a dedicated function just to allocate memory. See the new operator.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Shouldn't you be doing the homework by yourself?
--
I can't resist a touch of evil.
|
|
|
|
|
Seeing as you want me to do your homework, you'll first need to send me $20 via paypal. THEN when your next assignment comes in ( which may require THREE actual lines of code ), you won't have a clue what to do, because you didn't do this homework. That'll be $30. And so on, and so on.
Or you could do your own homework.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I'll give you a hint.
int* AllocateIntArray(int size)
{
return new int[size];
}
John
|
|
|
|
|
Now why did you go and do that ? Now he'll never do his homework, and we'll have another wanna be programmer who can't write 'hello world' on our hands.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I was in a sympathetic mood. Besides he/she will have to figure out what to change to get it to work...
John
|
|
|
|
|
John M. Drescher wrote:
Besides he/she will have to figure out what to change to get it to work
I'm curious what that would be. The function looks completely intact.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
My function deals with integers.
John
|
|
|
|
|
|
Hi,
Here's a puzzle. I have a linked list which may or may-not be circular. Using 2 pointers which have to be moving at any given point of time how do i determine if the linked list is circular?
-Mel
|
|
|
|
|
(mmmm, smells like homework)
Given you don't know whether it is or not, I would suggest you need to have a "slow" pointer and a "fast" pointer. For each time you move the slow pointer a single node along the linked list, you move the fast pointer on two nodes.
If there is a circle, once both pointers are inside it the fast pointer will eventually "catch up" to the slow one, and they will both point at the same node (note that this isn't necessarily the "start" node of the circle, just a node within it).
If the fast pointer reaches a terminating node, then there is (obviously) no circle.
The performance characteristics aren't fantastic, but the algorithm should be sound.
--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
|
|
|
|