sina sinaei
sina sinaei

Reputation: 11

Sending at commands to sim7600 and not receiving a response on Raspberry Pi Zero

I have been searching for a few days but I have not found any results. I have a Raspberry Pi Zero 2 W and a sim7600 hat and I want to send at commands to it using a program I wrote. When I use minicom as sudo minicom -D /dev/ttyUSB2, the at command response is sent from sim7600 to Raspberry Pi just fine. But when I run my program, I do not receive any response from sim7600 when sending at commands. I know that the at commands are working properly in my program because if I enter the AT+CRESET command in my program, the module is reset and then if I close my program and immediately run the program again, I can see the response to the at commands I send but again after a few seconds there is no response.

this is my c# code:

class Program
{
    static SerialPort portUSB;

    static void Main()
    {
        
        Console.Write("select Port:");
        string port = Console.ReadLine();
        portUSB = new SerialPort(port, 115200);
        

            Console.WriteLine("connecting to ttyUSB2 ...");
            portUSB.Handshake = Handshake.None;
            portUSB.DtrEnable = true;
            portUSB.RtsEnable = true;
            portUSB.ReadTimeout = 2000;
            portUSB.WriteTimeout = 2000;
            
            portUSB.DataReceived += PortUSB_DataReceived;
            portUSB.Open();


        Console.WriteLine("Write and Enter to send Message and press ctrl+c to exit");


        while (true)
        {

            if (Console.KeyAvailable)
            {
                string message = Console.ReadLine();
                if (!string.IsNullOrEmpty(message))
                {
                    SendMessage(message);
                }
            }

            Thread.Sleep(100);
        }
    }

    private static void PortUSB_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        SerialPort sp = (SerialPort)sender;
        string indata = sp.ReadExisting();

        Console.WriteLine("Data Received:");
        sp.DiscardInBuffer();
        sp.DiscardOutBuffer();
        Console.Write(indata);
    }

    static void SendMessage(string message)
    {
        try
        {
            if (portUSB.IsOpen)
            {
                portUSB.Write(message + "\r\n");

                Console.WriteLine("Command Sent " + message);
            }
            else
            {
                Console.WriteLine("ttyUSB2 Not open!");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            Environment.Exit(0);
        }

    }
}

https://i.sstatic.net/gwzRpx1I.png

1- First, to ensure the correct connection, I used minicom and opened the ttyUSB2 port and sent at commands and received responses. 2- I connected the sim7600 to the windows system using a micro usb cable and ran the program I had written on it (on COM7). The commands were sent well and the responses were received. 3- I connected the sim7600 hat to the Raspberry Zero and ran my program (/dev/ttyUSB2). The at commands were sent but no response was received.

Upvotes: 1

Views: 90

Answers (0)

Related Questions