Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » [SUCCESS] Struggle with Serial port class
Re: Struggle with Serial port class [message #27839 is a reply to message #27820] Fri, 06 August 2010 05:52 Go to previous messageGo to previous message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Does anyone know why the Serial::Close() followed by Serial::Open command not work? It seems to hang the code and I have to kill the process to regain control. Is this a Windows quirk?

The problem occurs when I try to change com ports wherein I first close the existing open com port, set new parameters and Open the new com port. If I do not do this, the program always works reliably.

this is the relevant code that is causing me grief
void	CommPak::SetupComms()
{
int Cnt;
int Port,Baud;

	WithCommSetup<TopWindow>	CommSetup;

	// stop the timer before changing anything
	if (ExistsTimeCallback(idRxTimer))
	{
		KillTimeCallback(idRxTimer);
		PromptOK("Killed the timer");
	}

	// if the port is open, close it
	if (CommPort.IsOpened())	CommPort.Close();
	
	CtrlLayoutOKCancel(CommSetup, "Setup Comms");
	for (Cnt=1;Cnt < 9;Cnt++)
		CommSetup.dlPort.Add(Format("COM%d",Cnt));
	CommSetup.dlBaud.Add("1200");
	CommSetup.dlBaud.Add("2400");
	CommSetup.dlBaud.Add("4800");
	CommSetup.dlBaud.Add("9600");
	CommSetup.dlBaud.Add("19200");
	
	CommSetup.dlPort = "COM6";	// choose to display COM6
	CommSetup.dlBaud= "9600";	// and 9600 baud
	
	if (CommSetup.Execute() == IDOK)
	{
		Port = CommSetup.dlPort.GetIndex()+1;
		Baud = CommSetup.dlBaud.GetIndex();
		DUMP(Port);
		DUMP(Baud);
		
		// Now open the port at the baud rate
		if (!CommPort.Open(Port,Baud))
			PromptOK(Format("Cannot open COM%d",Port));
		else
		{
			PromptOK(Format("COM%d opened successfully",Port));
			SetTimeCallback(-100,THISBACK(CheckRxTmr), idRxTimer);
		}		
	}
}


Thanks
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: THISBACK
Next Topic: Changing the slider thumb
Goto Forum:
  


Current Time: Wed Aug 20 10:11:57 CEST 2025

Total time taken to generate the page: 0.05738 seconds