Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the BaudRate of the device?

Tags:

c#

hardware

rfid

I'd like to know if there is a way to get the Baud Rate when it's connected on the RS232 port
BEFORE you initialize the SerialPort class and set it's values. Let me try to explain the reason for that...

Today, I'm working with two different RFID Reader devices, each one works on a different BaudRate, so if I set a wrong baudrate when I create the SerialPort class, it will read the card id all wrong, instead get the real card's id, it will get something like ????|W2???.
Also, there's a possibilite that the device have a USB port.

That's why I'd like to know the device's baud rate before I instantiate the SerialPort class.

like image 823
PlayHardGoPro Avatar asked May 16 '13 14:05

PlayHardGoPro


People also ask

How do you find the baudrate?

So, you divide the bit rate, which means the number of bits per second, by the total number of bits in a baud, and the result is the baud rate in bauds per second.

What is Baudrate in serial port?

The baud rate is the rate at which information is transferred in a communication channel. In the serial port context, "9600 baud" means that the serial port is capable of transferring a maximum of 9600 bits per second.

How do I find baudrate on Raspberry Pi?

After the system has restarted use the command ls -l /dev/ser* once again to show the revised serial device settings. The default baud rate of the serial port is 9600. If the baud rate of the GPS receiver is 9600, like the L80, then you can proceed to test the serial port.

What is USB baudrate?

The baud rate is a term for the number of bits per second that are transmitted over the wire. A common baud rate is 9600 bits per second. In that case, one bit takes up 1∕9600 of a second, or 104µs. The sending party flips the signal every 104µs, and the receiving party checks the voltage on the line every 104µs.


2 Answers

I tried for my serial usb devices. Keep changing the baud rate and check. ComboBox contains series of possible baudrates.

    public void initConfig(SerialPort serialPort)
    {
        // you can assign these values in a combo box
        string[] ports= "{COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8"};

        //you can assign these values in a combo box in a string format
        int[] baudRate = { 4800, 9600, 19200, 38400, 57600, 115200, 230400 };

        serialPort.PortName = ports[0]; //else get from combobox  : portCombobox.SelectedItem
        serialPort.BaudRate = baudRate[0];
        //serialPort.BaudRate = Int32.Parse(speedComboBox.SelectedItem.ToString());

        //you can have controls to store and change these values if required
        serialPort.Handshake = System.IO.Ports.Handshake.None;
        serialPort.Parity = System.IO.Ports.Parity.None;
        serialPort.DataBits = 8;
        serialPort.StopBits = System.IO.Ports.StopBits.One;
        serialPort.ReadTimeout = 200;
        serialPort.WriteTimeout = 50;
    }

change the strings into respective types and call open.

finally:

    public void callingMethod() //or your connect event attached control
    {
        SerialPort serialPort = new SerialPort();

        initConfig(serialPort);

        try
        {
            serialPort.Open();
        }
        catch
        {
            MessageBox.Show("Error: Unable to Open the serial interface !");
            return;
        }
    }
like image 56
KbManu Avatar answered Sep 27 '22 20:09

KbManu


Depending upon the details of what you connect to etc. You can loop through a list of baud rates, attempt to connect and then perform an echo test. If you connect at the wrong rate, your echo will be returned as garbage instead of the string you sent. This methodology is working for me.

like image 38
BuvinJ Avatar answered Sep 27 '22 20:09

BuvinJ