|
-
June 1st, 2006, 08:13 AM
#1
[RESOLVED] Re-Init a serial port after a comm crash
Hi,
I'm coding a software witch communicate with a terminal through the COM1. No problem with this, all is right.
Porblems appear when phisical link is disconnected between the terminal and the PC while communication is running,
After that, it's impossible to use the COM1 for any program (mine, hyper terminal...) even after X reboot.
The software sold with the terminal which is used to set a binaire into the terminal is abble to re-init the com1, when it's is failed, simply transfering the binaire to the terminal re-init the COM1, so, it is running for each program it doesn't before.
But I haven't the source code of this soft, so I don't know how doing this,
Could you help me ?
here is the latest try i did to re-init COM1:
Code:
// ***** OUVERTURE DU PORT *****
m_hCom = CreateFile( "COM1", // Choix du port « COMx »
GENERIC_READ | GENERIC_WRITE, // accès pour lire et écrire sur le port
0, // accès exclusif au port de COM
NULL, // sécurité par défaut
OPEN_EXISTING, //Doit être * cette valeur car se n’est pas un fichier
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, // mode synchrone asynchrone
NULL
);
ClearCommError(m_hCom, &dwErrors, NULL);
GetCommProperties(m_hCom, &prop);
err = (m_hCom == INVALID_HANDLE_VALUE) || (!SetupComm(m_hCom, 4096, 4096));
if (!err){
GetCommTimeouts (m_hCom, &gct);
gct.ReadIntervalTimeout = 0;
gct.ReadTotalTimeoutConstant = 0;
gct.ReadTotalTimeoutMultiplier = 0;
gct.WriteTotalTimeoutConstant = 5000;
gct.WriteTotalTimeoutMultiplier = 0;
if ( !SetCommTimeouts(m_hCom,&gct) ) err = 1;
}
if (!err){
memset(&m_Ov,0,sizeof(m_Ov));
// ***** CONFIGURATION DU PORT *****
m_config.DCBlength = sizeof( DCB );
GetCommState(m_hCom,&m_config);
m_config.BaudRate = 115200;
m_config.fBinary = 1;
m_config.fParity = 0;
m_config.fOutxCtsFlow = 0;
m_config.fOutxDsrFlow = 0;
m_config.fDtrControl = 1;
m_config.fDsrSensitivity =0;
m_config.fTXContinueOnXoff = 0;
m_config.fOutX = 0;
m_config.fInX = 0;
m_config.fErrorChar = 0;
m_config.fNull = 0;
m_config.fRtsControl = 1;
m_config.fAbortOnError = 0;
m_config.fDummy2 = 0;
//m_config.wReserved = 0;
m_config.XonLim = 2048;
m_config.XoffLim = 512;
m_config.ByteSize = 8;
m_config.Parity = 0;
m_config.StopBits = 0;
m_config.XonChar = 0;
m_config.XoffChar = 0;
m_config.ErrorChar = 0;
m_config.EofChar = 0;
m_config.EvtChar = 0;
//m_config.wReserved1 = 0;
err = SetCommState(m_hCom,&m_config) == 0;
// Purge
if (!err){
PurgeComm(m_hCom, PURGE_TXABORT|PURGE_RXABORT|
PURGE_TXCLEAR|PURGE_RXCLEAR);
GetCommMask(m_hCom, &old_mask);
SetCommMask(m_hCom, 0);
SetCommMask(m_hCom, old_mask);
}
}
What's wrong ?
-
June 1st, 2006, 09:27 AM
#2
Re: Re-Init a serial port after a comm crash
Ok,I got my answer by the seller of the terminal,
in fact, when terminal support is disconnected, communication speed is re initialised.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|