One of Beidou serial programming with C#: get Beidou card number

The Beidou Satellite Navigation System (hereinafter referred to as Beidou System, English abbreviation BDS) is a global satellite navigation system built and operated independently by China focusing on the needs of national security and economic and social development. It provides users around the world with all-weather, all-weather, high-precision An important national spatio-temporal infrastructure for positioning, navigation and timing services.

Beidou-3 has been officially opened in 2020 and is expected to be opened to civilian use in 2021. Here we can learn about the programming technology of the second generation of Beidou in advance, and the programming principles of the third generation are similar.

The equipment you need

1) A Beidou terminal with serial port
I am using a Beidou terminal on-board from Chengdu Guoxing.
Insert picture description here

2) There is a serial port or U-to-serial cable on the computer

Nowadays computers are generally not equipped with serial ports. You can buy a USB-to-serial adapter cable. I bought a green connection from the Internet, and the quality is quite good. After connecting, install the corresponding driver.
Insert picture description here

The first step is to check the available serial ports

After installing the U-to-serial driver, you can see the available serial port in the computer management, my name is COM5.
Insert picture description here

The second step is to receive a line of text from the serial port

Create a new console project in Visual Studio, and provide a SerialPort class in System.IO.Ports, which can facilitate serial communication. The baud rate of the serial port of Beidou equipment is generally 115200, depending on the manufacturer’s equipment manual.

//using System.IO.Ports;
SerialPort port = new SerialPort("COM5", 115200);
port.Open();
string line = port.ReadLine();
Console.WriteLine(line);
port.Close();

After running, my program receives a line of data from the serial port:

$GNRMC,074126.087,V,,,,,0.00,260.32,250121,,,N*5A

It means that the Beidou equipment is normal, and the information you receive may be different from mine.

The third step is to obtain the Beidou card number

Code first.

SerialPort port = new SerialPort("COM5", 115200);
port.Open();
port.Write("$CCICA,0,0*4B\r\n");
for (int i = 0; i < 10; i++)
{
    
    
    string line = port.ReadLine();
    if (line.StartsWith("$BDICI"))
    {
    
    
        Console.WriteLine(line);
    }
}

If the Beidou equipment is normal, you can get a line of information similar to the following, 925867 is the Beidou card number.

$BDICI,0925867,2204536,1934946,6,60,3,N,0*0F

Briefly explain:

$CCICA,0,0*4B\r\n

It is a line of command sent to the serial port. If the command complies with the grammatical rules of Beidou communication, the serial port will receive a feedback message of $BDICI. Many parameters are separated by commas. The first parameter is the Beidou card number.

Okay, let’s introduce it here today. The most basic Beidou serial communication is that simple. I will share other content later.

Guess you like

Origin blog.csdn.net/slofslb/article/details/113109337