Using Arduino and C sharp to Control Relay thru Mega 2560

Hey, I'm new to programming and am trying to use both Arduino and C sharp to run a relay board (R410Pro) off of an Arduino Mega 2560. The set up is the USB connects to the Mega and the Relay is connected to the Mega via RS232.

As of now, the program is set up so that the Console in C sharp opens while the program runs. The user then enters a 0 or 1 which turns on/off the Mega LED (no problems so far). The Arduino is programmed to send whatever is written in the console to the relay. Thus if the correct numbers are entered, it should turn on/off different relays and their respective LED's. Instead, nothing happens.

Ideally the goal would be to control the relays using buttons on the Arduino, so if you have any advice on how to set that instead of/inaddition to help with running it out of the console, I would appreciate it greatly.

Here is the code. C sharp

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Threading;

namespace test
{
    class LED 
    {
        
             static void Main(string[] args)
        {

            SerialPort port = new SerialPort("COM4", 9600);
            port.Open();
            while (true)
            {
                Console.WriteLine("open");
                String s = Console.ReadLine();
                if (s.Equals("exit"))
                {
                    break;
                }
                port.Write(s + '\n');
            }
            string sInput;

            sInput = Console.ReadLine();
            Console.WriteLine(sInput);
            port.Write(input);

            port.Close();
        }
    }
}

Arduino code

#define BAUD_RATE 9600
#define ledPin  13

void setup()
{
pinMode(ledPin, OUTPUT);

// serial communication
Serial.begin(BAUD_RATE);
Serial2.begin(BAUD_RATE); //serial comms with relay board

}

void loop()
{
if(Serial.available()>0){ //available means it is receiving data
  byte(Serial.read);
  Serial2.write(inByte);
//protocol for Mega LED on/off
switch(inByte){
  case '1':
   // led is ON
   digitalWrite(ledPin, HIGH);
   break;
  case '0':
   // led is OFF
   digitalWrite(ledPin, LOW);
   break;
}
}
  
if(Serial2.available()>0){ //check if serial 2 is recieving data 
                        //and have it send it to c sharp to be displayed 
  byte inByte = Serial2.read();
  Serial2.write();
}

}

Thank you.

Your loop code is odd, or maybe just missing variable names?

void loop()
{
if(Serial.available()>0){ //available means it is receiving data
  byte inByte = Serial.read();  // <<<
  Serial2.write(inByte);
//protocol for Mega LED on/off
switch(inByte){
  case '1':
   // led is ON
   digitalWrite(ledPin, HIGH);
   break;
  case '0':
   // led is OFF
   digitalWrite(ledPin, LOW);
   break;
}
}

I pretty much copied the program Arduino gives for MultiSerialMega and am using Serial2 rather than 1 for that section, so I'm not sure how else it should look. That's not to say I'm right/know what I'm doing, however.

/*
  Mega multple serial test

 Receives from the main serial port, sends to the others. 
 Receives from serial port 1, sends to the main serial (Serial 0).

 This example works only on the Arduino Mega

 The circuit: 
 * Any serial device attached to Serial port 1
 * Serial monitor open on Serial port 0:

 created 30 Dec. 2008
 modified 20 May 2012
 by Tom Igoe & Jed Roach

 This example code is in the public domain.

 */


void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte); 
  }
  
  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.write(inByte); 
  }
}

I think you are sending a char from your key board rather than a byte of value 1.

If so change this:

byte inByte

To this:

char inByte