0

I am writing a python project to control a device with PyVisa over a USB cable. I am having a lot of success. I noticed that the device datasheet supported 9600, 19200, 38400, 57600, 115200, 230400, 460800 baud rates so I created some functions for changing the baud rate.

But I wanted a nifty way to detect which baud rate the device is set to so I can automatically connect to it without magically knowing what baud the device is on. The device "remembers" the last baud you set it to - it does not reset to a default baud on power loss. The device seems like it doesn't respond at all if you have the wrong baud rate set. So, given a random baud rate, I cycle through all the supported ones and send a short command. If the device answers, THAT'S the baud rate currently set and I use that to talk to the device more.

However, during stress testing I noticed that when the device was randomly set on 38400 baud and I went to detect it, my program would fail to detect that baud rate. (The device wouldn't answer a call on this baud.) When I removed it from the list of supported bauds, the device worked fine.

Is there something about 38400 baud rate that makes it more unstable than other bauds?

I also thought that this use-case was interesting. If you are having problems like this, try dropping support for certain bauds and see if that fixes your errors. Hope it helps.

EDIT: The code really doesn't matter but there was a request for it so...

import visa
BAUDRATES = [
    9600,
    19200,
    38400,
    57600,
    115200,
    230400,
    460800,
]
rm = visa.ResourceManager('@py')
dev = rm.open_resource('ASRLCOM7:INSTR')
for i in range(1, 101): # run 100 tests
    # select a random baud rate from the list
    rand_baud = BAUDRATES[randrange(0,len(BAUDRATES))]
    dev.write('SETBAUD' + str(rand_baud)) # Device response with 'OK'
    print('The random baud was {0}'.format(rand_baud))

# now detect the random baud by sending commands to the instrument and looking for a response
detected_baud = None
for baudrate in BAUDRATES:
    dev.baud_rate = baudrate # sets the com port baud rate
    resp = dev.query('GETINFO')
    if resp != '':
        detected_baud = baudrate
        break
print('The detected baud was {0}'.format(detected_baud))

This code is abbreviated from the real code but the idea is the same. Just loop through, send a command, and listen for a response. The instrument will not send a response over the com port if a message is sent with the incorrect baud or the command is unintelligible. This detection method ALWAYS failed on 38400 and never fails on any other baud rate. The only way in which this method can fail is that it never receives a response on ANY baud, which is exactly what it was doing. This makes me think maybe there is a clock mismatch only at that baud rate or similar. I was curious to know if certain bauds have higher rate of errors than others.

boymeetscode
  • 805
  • 1
  • 9
  • 26
  • 1
    Without knowing what device you're talking about, nobody will be able to tell you if that device has some kind of known problem with 38,400 bps serial communications. Not that "does my device have some kind of bug in its serial chip?" is a programming question anyway... – kindall Mar 13 '17 at 20:37
  • I might suggest trying the rates in the opposite order, however. – kindall Mar 13 '17 at 20:43
  • @kindall My question was not about the device. It was intentionally about the baud rate. I would find it hard to believe that a device that can operate at 460800 baud just fine would have a problem with 38400. But even still I can ask the device manufacturer if they know of any problem at that rate. Also, I am randomly setting the baud from the list of supported ones and then disconnecting and detecting again. So order seems to not matter either. But always after setting baud to 38400 and then attempting a detection. – boymeetscode Mar 13 '17 at 20:47
  • How are you setting the baud rate? Where's the code you use for detecting the baud rate? – SoreDakeNoKoto Mar 13 '17 at 21:54
  • @boymeetscode If your question isn't about the device, it seems like you're literally asking if transmitting data at 38400 baud is somehow *inherently* less stable than other transmission rates of data transmission, regardless of which device is sending/receiving or what kind of signal is involved. If that's the case then the question's too vague to give an answer more specific than "no". – Chris H Mar 14 '17 at 14:08
  • 1
    @Chris H, No is an acceptable answer. – boymeetscode Mar 14 '17 at 14:33
  • @boymeetscode in that case, I've turned it into one – Chris H Mar 14 '17 at 14:58

1 Answers1

2

No.

There's nothing special about 38400 baud that makes it less stable than other transmission rates. It's possible that specific devices or transmission methods may experience problems more often or exclusively at this (or any other) rate due to hardware, software, or physical limitations, but these would be device- and/or method-specific limitations and aren't inherent to 38400 baud communication in general.

Chris H
  • 790
  • 9
  • 19