Click here to Skip to main content
16,004,969 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: add two functions for a button Pin
toxcct13-Sep-05 21:27
toxcct13-Sep-05 21:27 
Questioncalculating function time,Interesting Pin
logicaldna13-Sep-05 1:03
logicaldna13-Sep-05 1:03 
AnswerRe: calculating function time,Interesting Pin
Cedric Moonen13-Sep-05 2:11
Cedric Moonen13-Sep-05 2:11 
AnswerRe: calculating function time,Interesting Pin
John R. Shaw13-Sep-05 2:44
John R. Shaw13-Sep-05 2:44 
QuestionRe: calculating function time,Interesting Pin
logicaldna13-Sep-05 18:42
logicaldna13-Sep-05 18:42 
QuestionNobody??WMI,set Ip Address,Doesn't work! Help!!! Pin
Tcpip200513-Sep-05 0:51
Tcpip200513-Sep-05 0:51 
QuestionI got runtime error when I am moving toolbars in my program. Pin
G Haranadh13-Sep-05 0:14
G Haranadh13-Sep-05 0:14 
QuestionSerial communication Pin
Aditi48412-Sep-05 23:59
Aditi48412-Sep-05 23:59 
Hello..

I'm a beginner with Visual C++.. (have only done very very basic C++ programming).. I'm trying to communicate with a microcontroller using serial communication.. I tried to do it from scratch using the Windows functions..this is what my code looks like..
 #include "stdafx.h"<br />
<br />
int _tmain()<br />
{<br />
<br />
HANDLE h =	CreateFile("COM3", GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);<br />
	if (h == 0)<br />
	{<br />
		printf("Can't open com port (1)\n");<br />
		return 1;<br />
	}<br />
	DCB dcb;<br />
	memset(&dcb, 0, sizeof(DCB));<br />
	dcb.DCBlength = sizeof(DCB);<br />
	dcb.BaudRate = 19200;<br />
	dcb.fBinary = TRUE;<br />
	dcb.fParity = FALSE;<br />
	dcb.ByteSize = 8;<br />
	dcb.Parity = NOPARITY;<br />
	dcb.StopBits = ONESTOPBIT;<br />
	BOOL result = SetCommState(h, &dcb);<br />
	if (!result)<br />
	{<br />
		printf("Can't set com port state(2)\n");<br />
		return 1;<br />
	}<br />
<br />
	if (result)<br />
		printf("Have Set com port state\n");<br />
<br />
	char buffer[100];<br />
	DWORD bytesRead = 0;<br />
	while (true)<br />
	{<br />
		printf("In while\n"); <br />
			<br />
		memset(buffer, 0, sizeof(buffer));<br />
		if (ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, 0))<br />
		{<br />
			printf("Read file has a result\n"); <br />
			if (bytesRead != 0)<br />
			{<br />
				printf("Got some bytes\n"); <br />
				printf ("%s", buffer);<br />
			}<br />
			<br />
			else {<br />
				printf("No bytes read\n"); <br />
			}<br />
		}<br />
<br />
		else {<br />
			printf("Readfile didnt give proper result \n"); 	<br />
		}<br />
		Sleep(200);<br />
	}<br />
<br />
	// Close session<br />
	CloseHandle(h);<br />
<br />
	return 0; 


he micro is continously sending characters to the serial port.. when i run the program.. the port does gets initialized properly (debug statement printed ) then some characters are recieved but they are unintelligble.. i've checked the speed and all other settings for the com port and they are the same as the micro and the micro's usart is working fine.. can anyone see why i'm getting garbage..

Thank you for the help..
AnswerRe: Serial communication Pin
MailtoGops13-Sep-05 3:15
MailtoGops13-Sep-05 3:15 
GeneralRe: Serial communication Pin
Aditi48413-Sep-05 3:50
Aditi48413-Sep-05 3:50 
AnswerRe: Serial communication Pin
John R. Shaw13-Sep-05 4:06
John R. Shaw13-Sep-05 4:06 
AnswerRe: Serial communication Pin
Roger Stoltz13-Sep-05 6:35
Roger Stoltz13-Sep-05 6:35 
GeneralRe: Serial communication Pin
Aditi48413-Sep-05 23:26
Aditi48413-Sep-05 23:26 
AnswerRe: Serial communication Pin
Roger Stoltz14-Sep-05 1:00
Roger Stoltz14-Sep-05 1:00 
AnswerRe: Serial communication Pin
Aditi48414-Sep-05 1:36
Aditi48414-Sep-05 1:36 
GeneralRe: Serial communication Pin
Roger Stoltz14-Sep-05 5:00
Roger Stoltz14-Sep-05 5:00 
AnswerRe: Serial communication Pin
Aditi48415-Sep-05 21:51
Aditi48415-Sep-05 21:51 
QuestionHow to add a Scheduled Task to the Task Scheduler Pin
PravinSingh12-Sep-05 23:55
PravinSingh12-Sep-05 23:55 
AnswerRe: How to add a Scheduled Task to the Task Scheduler Pin
prasad_som13-Sep-05 0:03
prasad_som13-Sep-05 0:03 
AnswerRe: How to add a Scheduled Task to the Task Scheduler Pin
David Crow13-Sep-05 2:30
David Crow13-Sep-05 2:30 
Questionmemory management Pin
Ali Tavakol12-Sep-05 23:55
Ali Tavakol12-Sep-05 23:55 
Questionserver and client Pin
Member 216100412-Sep-05 23:54
Member 216100412-Sep-05 23:54 
QuestionCDC::SelectObject Pin
Nishad S12-Sep-05 23:33
Nishad S12-Sep-05 23:33 
AnswerRe: CDC::SelectObject Pin
ThatsAlok12-Sep-05 23:48
ThatsAlok12-Sep-05 23:48 
AnswerRe: CDC::SelectObject Pin
John R. Shaw13-Sep-05 5:48
John R. Shaw13-Sep-05 5:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.