|
|
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
|
|
|
|
|
|
|
Re: [SUCCESS] Struggle with Serial port class [message #39446 is a reply to message #39394] |
Sat, 16 March 2013 15:53   |
|
If anybody find linux working example...
I developed Linux analog CommPack and used in my projects.
(but it normal work only under root user)
So if needed, I'll prepare to upload my variant of CommPack.
SergeyNikitin<U++>( linux, wine )
{
under( Ubuntu || Debian || Raspbian );
}
|
|
|
|
|
|
Re: [SUCCESS] Struggle with Serial port class [message #39474 is a reply to message #39446] |
Tue, 19 March 2013 09:56  |
Didier
Messages: 725 Registered: November 2008 Location: France
|
Contributor |
|
|
sergeynikitin wrote on Sat, 16 March 2013 15:53 | If anybody find linux working example...
I developed Linux analog CommPack and used in my projects.
(but it normal work only under root user)
So if needed, I'll prepare to upload my variant of CommPack.
|
You can make it work for any user if you add the group 'dialout' to the user that needs access to the serial port
|
|
|
Goto Forum:
Current Time: Sun Apr 27 00:29:33 CEST 2025
Total time taken to generate the page: 0.01130 seconds
|
|
|