Failure to have a C# application communicate with Arduino GIGA via serial port

I created an GUI application using C# that connects to Arduino MEGA via serial port which works fine, but I am unable to have it communicate with the Arduino GIGA board.

I can connect to GIGA board using putty terminal with the same PC, but not via the C# application.

Using a serial port sniffer, I can see a reply coming from Arduino,
[13/07/2023 13:01:55] COM4
Direction: UP (STATUS_INVALID_DEVICE_STATE)
107 - IRP_MJ_DEVICE_CONTROL
IOCTL_SERIAL_WAIT_ON_MASK
Mask - 0x00000000
Data length: 4
00 00 00 00

The problem must be somewhere in your code. What, if any, changes did you make to the Mega code to run it on the Giga?

Have you confirmed basic connectivity with simple test sketches on the Giga?

The same code run perfect on the Mega board, using the C# Serial class.

Please post the entire sketch, don't forget to use code tags.

The issue is not with software, the problem is at the hardware handshake. I can exchange data to the Giga from a terminal, but the issue is the Giga behaves different than Mega when called from the C# Application.

Hardware handshake? You have the full RS-232 interface? I.E. RTS, CTS, DTR etc. ???

but the issue is the Giga behaves different than Mega when called from the C# Application.

This is where simplified test programs might help, to isolate the problem so that it is easier to identify.

Here is the response getting when sending packet "7e7e0" from the app:

103 13/07/2023 12:59:51 IRP_MJ_WRITE DOWN 7e 7e 01 ~~. 3 3 COM4
104 13/07/2023 13:01:55 IRP_MJ_WRITE UP STATUS_UNSUCCESSFUL COM4
105 13/07/2023 13:01:55 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_WAIT_ON_MASK) UP STATUS_CANCELLED 00 00 00 00 .... 4 COM4
106 13/07/2023 13:01:55 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_WAIT_ON_MASK) DOWN COM4
107 13/07/2023 13:01:55 IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_WAIT_ON_MASK) UP STATUS_INVALID_DEVICE_STATE 00 00 00 00 .... 4 COM4

I don't know. Good luck. Perhaps if you post more details, someone else will know.

Here is the code in C# to connect to the Arduino. it works on Meta, but not on Giga

private void find_com_port()
{
comm_info.serial_port = new SerialPort();
comm_info.serial_port.BaudRate = baud_rate;
comm_info.serial_port.DataBits = 8;
comm_info.serial_port.Parity = Parity.None;
comm_info.serial_port.StopBits = StopBits.One;

        foreach (string com in com_port.Items)
        {
            comm_info.serial_port.PortName = com;
            try
            {
                comm_info.serial_port.Open();
                com_port.Text = com;
                com_connected = true;
              comm_info.serial_port.WriteLine("~~1");
                return;
            }
            catch //(Exception ex)
            {
                // repeat the search
                continue;
            }
            
        }
        if (!com_connected)
        {
            //if (!com_connected) 
                MessageBox.Show("Start the Arduino board, wait few seconds and click the Restart button", "Arduino board not found");
        }
    }

Resolved.

For Arduino with usb-c port, DtrEnable and RtsEnable need to be set to true:

comm_info.serial_port.DtrEnable = true;
comm_info.serial_port.RtsEnable = true;

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.