Я использую следующий код для взаимодействия с устройством: < /p>
using System;
using System.IO.Ports;
using System.Windows.Forms;
namespace DEVICE_INFO
{
public partial class Form1 : Form
{
SerialPort serialPort;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string portName = "COM6"; // Specify your COM port (change if needed)
int baudRate = 115200; // Try different baud rates (9600, 38400, 115200)
serialPort = new SerialPort(portName, baudRate)
{
ReadTimeout = 5000, // Timeout for reading data (5 seconds)
WriteTimeout = 3000, // Timeout for writing data (3 seconds)
DtrEnable = true, // Some devices require this setting
RtsEnable = true, // Some devices require this setting
Encoding = System.Text.Encoding.ASCII
};
serialPort.DataReceived += SerialPort_DataReceived;
serialPort.Open(); // Open the serial port
// Send AT commands to request SIM card and device information
serialPort.WriteLine("AT\r\n");
MessageBox.Show("Reading data from device...", "Device Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message, "Device Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// Event handler for receiving data
private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
string rawData = serialPort.ReadExisting(); // Read incoming data
// Display the response in the RichTextBox in the UI thread
this.Invoke((MethodInvoker)delegate
{
richTextBox1.AppendText(rawData + "\n"); // Append response to the RichTextBox
});
}
catch (Exception ex)
{
MessageBox.Show("Read Error: " + ex.Message, "Device Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
< /code>
Я получаю ошибку < /p>
[L610_cldsd_load.c] -DR_RecvData_Analysis- Line=1292:, the
iRet=-5006
[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:, the
iRet=-5006
[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:, the
iRet=-5006
[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:, the
iRet=-5006
[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:, the
iRet=-5006
[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:, the
iRet=-5006
[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:, the
iRet=-5006
[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:, the
iRet=-5006
[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:, the
iRet=-5006
[L610_cldsd_load.c] -DR_RecvData
_Analysis- Line=1292:, the
iRet=-5006
[L610_cldsd_uart.c]
-DR_Uart0_Handle- Line=88:DR_Rec
vData_Analysis iRet=-5006
< /code>
Это сообщение об ошибке, похоже, поступает из прошивки устройства. Я попробовал различные подходы для отправки по командам, но устройство не отвечает, как ожидалось.
- Проверка подключения COM -порта. li> Отправка разных команд, таких как «AT+GMR» для версии прошивки и «AT+CGSN» для IMEI. /li>
< /ol>
Вопрос -< /strong> < /p>
Как правильно получить IMEI, серийный номер и другие данные устройства с устройства, подключенного через USB COM -порт в C#? ?
Я буду признателен за любую помощь или предложения. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/794 ... -port-in-c