Display reading data

Hi all,

I would like to read serial data from c# and send them a port.

I wrote a basic c# code for testing;

protected void Page_Load(object sender, EventArgs e)
        {
            serialPort1 = new SerialPort();
            serialPort1.PortName = "COM12";
            serialPort1.BaudRate = 9600;
            serialPort1.Open();
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            serialPort1.Write("1001");  
        }

And then, i would like to read them,

int incomingByte = 0;	// for incoming serial data
void setup() {
	Serial.begin(9600);	// opens serial port, sets data rate to 9600 bps
}
void loop() {
	// send data only when you receive data:
	if (Serial.available() > 0) {
		// read the incoming byte:
		incomingByte = Serial.read();

		// say what you got:
		Serial.print("I received: ");
		Serial.println(incomingByte, DEC);
	}
}

I would like to display reading data.
However, when i start serial monitor, the error code appears "Serial port 'COM12' already in use" (by c#).
How can i display the reading data? and how can i sent them to port?

How can i display the reading data?

A couple of ways. Attach an LCD and show the data there. Or, add code to the C# application to read from the port, to see what the Arduino had to say.

how can i sent them to port?

You are already doing that. That's what Serial.print() does.