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   |
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
|
|
|
 |
|
[SUCCESS] Struggle with Serial port class
By: jerson on Thu, 05 August 2010 07:55
|
 |
|
Re: Struggle with Serial port class
By: kohait00 on Thu, 05 August 2010 09:00
|
 |
|
Re: Struggle with Serial port class
By: mrjt on Thu, 05 August 2010 10:00
|
 |
|
Re: Struggle with Serial port class
By: kohait00 on Thu, 05 August 2010 10:17
|
 |
|
Re: Struggle with Serial port class
By: jerson on Thu, 05 August 2010 11:22
|
 |
|
Re: Struggle with Serial port class
By: mrjt on Thu, 05 August 2010 11:42
|
 |
|
Re: Struggle with Serial port class
By: jerson on Thu, 05 August 2010 11:49
|
 |
|
Re: Struggle with Serial port class
By: mrjt on Thu, 05 August 2010 12:04
|
 |
|
Re: Struggle with Serial port class
By: jerson on Fri, 06 August 2010 05:52
|
 |
|
Re: Struggle with Serial port class
By: mrjt on Fri, 06 August 2010 11:22
|
 |
|
Re: Struggle with Serial port class
By: jerson on Fri, 06 August 2010 11:31
|
 |
|
SUCCESS : Struggle with Serial port class
By: jerson on Fri, 06 August 2010 19:29
|
 |
|
Re: [SUCCESS] Struggle with Serial port class
By: jibe on Fri, 15 March 2013 14:44
|
 |
|
Re: [SUCCESS] Struggle with Serial port class
|
 |
|
Re: [SUCCESS] Struggle with Serial port class
By: deep on Sat, 16 March 2013 16:39
|
 |
|
Re: [SUCCESS] Struggle with Serial port class
|
 |
|
Re: [SUCCESS] Struggle with Serial port class
By: deep on Sun, 17 March 2013 17:14
|
 |
|
Re: [SUCCESS] Struggle with Serial port class
By: Didier on Tue, 19 March 2013 09:56
|
Goto Forum:
Current Time: Wed Aug 20 10:11:57 CEST 2025
Total time taken to generate the page: 0.05738 seconds
|