Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(Serial port) How to switch between parity modes without speed loss ?

Status
Not open for further replies.

sidocsaba

Programmer
Jul 24, 2003
6
RO
I have to switch (when using the serial port) between parity modes(mark->space parity) wery often in my application. The problem is, that I have to close and reopen the port, or change the Dcb(it is not working by changing it, don't know why) to do that, and this takes a lot of time (>200ms). This slows down my comunication considerably.
Does anibody have a sugestion, how to switch parity without speed penalization ?
 
I'm not sure that you can as you are re-programming the UART. Why do you need to switch parity during a connection?

If you absolutely need to do this could you perhaps set the UART to 8 bith - no parity and then handle the parity checking yourself in your code rather than leaving it up to the UART.
 
The problem is, that the sent data is espected to be sent in different parity modes(the first byte in mark, the rest in space parity). I'm comunicating with some kind of equipment (fuel pomp), so I can't make changes on that side.
I was trying to fool him somhow, by sending with no parity, and setting a 9th bit, but it didn't work. I suspect because the stop bit. I can send max 8 bit at a time, so the 9th bit passes to the second byte, and so on. In final I don't get a 8 * x bit number.

Speed would be essential, so I don't know what to do.
 
hi,
I have not experience with changing comm parameter running.
But seeing my code, I see that the schema is

Open (CreateFile)
Set (SetCommState,SetCommTimeouts)
loop
Send (WriteFile)
Receive (ReadFile)
endloop
Close (CloseHandle)

Are you sure cannot change DCB parameters
redo a SetCommState without close and reopen ?

Open
loop
dcb.Parity = EVENPARITY // or other
SetCommState,
SetCommTimeouts
WriteFile
ReadFile
endloop
Close

bye
 
My code looks like this. Without "The modification" part, at least worked. I don't know why the dcb can't be changed. But anyway the obtained time is not better. (A single SetCommState takes about 200ms)

port.Close()
port.Open(1, 9600, CSerialPort::MarkParity, 8, CSerialPort::OneStopBit, CSerialPort::NoFlowControl);
port.Write(sCod, 1);
//port.Close();

//The modification
DCB dcb;
GetCommState(port.m_hComm,&dcb);
dcb.Parity=SPACEPARITY;
SetCommState(port.m_hComm,&dcb);

//port.Open(1, 9600, CSerialPort::SpaceParity, 8,
CSerialPort::OneStopBit, CSerialPort::NoFlowControl);
port.SetTimeouts(lpCommTime);
port.Write(sBuf, 8);
port.Read(sRead,4);
port.Close()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top