I'm working on a Serial COM Port ANSI Char reading project. I can handle to send data but I can not handle to recieve it. Any help is appriciated.
This is read function:
BOOL ReadString(char *outstring)
{
int *length;
*length = sizeof(int);
BYTE data;
BYTE dataout[8192]={0};
int index = 0;
while(ReadByte(data)== TRUE)
{
dataout[index++] = data;
}
memcpy(outstring, dataout, index);
*length = index;
return TRUE;
}
And Main.cpp is:
int main(void)
{
// Configs
hPort = ConfigureSerialPort("COM1");
if(hPort == NULL)
{
printf("Com port configuration failed\n");
return -1;
}
char* cPTR;
for(;;)
{
ReadString(cPTR);
if(cPTR!=NULL) cout << "Scanned Data: " << cPTR << endl;
else cout << "No data recieved." << endl;
}
ClosePort();
return 0;
}
cPTRis never initialized, so that may be causing problems, but since you haven't clearly stated what goes wrong, it's hard to say.int *length; *length = sizeof(int);This is quite enough for crash.