|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
auto-tune serial portI've been looking at some applications that auto-tune the serial port
settings as a stream of data is sent to it. I want to add this type of function in my software but I can't find any sample code to suggest how I should start to do this. Does anyone know how this works? Do you tune the baudrate first and then databits, handshaking etc? -- Steve Hi,
I have example code in my book. Basically what I do is to Open the port at the highest possible speed (typically 115200 bps), with 8-data bits and No parity. I then wait to see if there are any errors (Framing, Parity, Break, or Overrun). If there are, I assume this is not the correct set of parameters. I close the port, change the parity (to E or O), then repeat. After I've tested each parity setting, I change the number of bits (I only test for 7-bit or 8-bit data). If I still get an error, I reduce the speed to the next lower setting (57600 bps) and repeat all of the previous tests -- I continue to repeat these steps until I have no errors BUT do receive some sort of data. Naturally, if there is no receive data -- even if there is no error, you haven't arrived at an "answer." This works most of the time. It can be fairly slow, because you have to wait a couple of seconds after you have opened the port (if no error is generated), to make sure that, in fact, there is data present. Dick -- Richard Grier, MVP Hard & Software Author of Visual Basic Programmer's Guide to Serial Communications, Fourth Edition, ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March 2006. See www.hardandsoftware.net for details and contact information. Thanks Dick. I ordered your book straight away!
-- Show quoteSteve "Dick Grier" wrote: > Hi, > > I have example code in my book. Basically what I do is to Open the port at > the highest possible speed (typically 115200 bps), with 8-data bits and No > parity. I then wait to see if there are any errors (Framing, Parity, Break, > or Overrun). If there are, I assume this is not the correct set of > parameters. I close the port, change the parity (to E or O), then repeat. > After I've tested each parity setting, I change the number of bits (I only > test for 7-bit or 8-bit data). If I still get an error, I reduce the speed > to the next lower setting (57600 bps) and repeat all of the previous > tests -- I continue to repeat these steps until I have no errors BUT do > receive some sort of data. Naturally, if there is no receive data -- even > if there is no error, you haven't arrived at an "answer." > > This works most of the time. It can be fairly slow, because you have to > wait a couple of seconds after you have opened the port (if no error is > generated), to make sure that, in fact, there is data present. > > Dick > > -- > Richard Grier, MVP > Hard & Software > Author of Visual Basic Programmer's Guide to Serial Communications, Fourth > Edition, > ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March > 2006. > See www.hardandsoftware.net for details and contact information. > > > |
|||||||||||||||||||||||