C#, COM Port, Serial Monitor !???

:slight_smile:
Dear all,
I am facing a very unique problem.

I am reading a text file in C# environment, and sending data(line by line, in number format) to my arduino board on COM3.
Now , I really want to see what Arduino has received from computer.
To do that, When I turn-on the Serial Monitor, an Error is thrown in C# environment, and it says:

Access denied to COM3.

Now I know the reason behind it, but I really need to see what I receiving from Computer(and sending to another board).

Is there any way I can display what I am receiving from computer, in this case?

Thanks and regards

I think you have two options. The best one IMHO is to add code to your C# program to display any messages it receives from the Arduino.

The other is to use a USB-TTL cable to create a separate connection between the Arduino and the Arduino Serial Monitor. You have not said what Arduino board you are using, but if it is an Uno then you can use SoftwareSerial to create a second serial port.

...R

tahirsengine:
I am facing a very unique problem.

There is nothing unique about it :wink:

A serial port on the PC can only be used by one application at a time.

See Robin's reply above; adding a textbox to your C# application to show received data makes most sense to me.

It sounds like you need some com port sharing software that allows 2 PC applications to share the same port. Something like this may work for you.

Robin2:
I think you have two options. The best one IMHO is to add code to your C# program to display any messages it receives from the Arduino.

The other is to use a USB-TTL cable to create a separate connection between the Arduino and the Arduino Serial Monitor. You have not said what Arduino board you are using, but if it is an Uno then you can use SoftwareSerial to create a second serial port.

...R

Hi,
That solved half problem. Here is the situation:

COM3 is in communication with Arduino and C#. When I plugged in the USB-TTL cable and connected that to my Arduino UNO board, COM4 also becomes visible.
So I am receiving data from COM3, but howI will write same received data on COM4?

My code is as follows:

void loop() {
if((Serial.available())){
String data = Serial.readString();
if(data != NULL) {
String IntermediateData = data.substring(0,4);
sendData = strtoul(IntermediateData.c_str(),&ptr,16);
SPITransactionSettingsA(sendData);
sendData1 = sendData;
Serial.println(sendData1); // Will print values in Hexadecimal
}
}
}

tahirsengine:
So I am receiving data from COM3, but howI will write same received data on COM4?

You have not told us how you have connected the USB-TTL cable to your Uno. In the code snippet in Reply #4 I can't tell whether you are using SoftwareSerial (as I suggested in Reply #1) to create a second serial port for use with the USB-TTL cable.

Always post a complete program so we can see all the definitions.

...R

Robin2:
You have not told us how you have connected the USB-TTL cable to your Uno. In the code snippet in Reply #4 I can't tell whether you are using SoftwareSerial (as I suggested in Reply #1) to create a second serial port for use with the USB-TTL cable.

Always post a complete program so we can see all the definitions.

...R

Hi, Lets suppose I have following code(actually which is my main problem from actual code, which I gave above ):

//A variable to hold the level of coolness

#include <SoftwareSerial.h> // This feature is for second serial port
SoftwareSerial mySerial(0,1); // RX, TX

void setup() {

Serial.begin(9600);
mySerial.begin(9600);

}

void loop() {

Serial.println("111"); // Trying to write COM3
mySerial.println("22222"); // Trying to Write COM4
delay(500);
}

I have two COM ports which are being shown in Arduino IDE. COM3(where Arduino is connected), COM4(an extra USB -TTL cable, that I have connected to pin 0 and 1 of Arduino).

Now lets say, I want to write different data to these two different ports. The above program is writing "111" on both the ports.

If this thing solved, so will my main problem.

By the way, I have also shortened the RESET and GND pins to enable USB-TTL.

You should not use pins 0 and 1 for SoftwareSerial because they are the pins for HardwareSerial. The purpose of SoftwareSerial is to allow you to create a second serial port on different I/O pins.

And then connect the USB-TTL cable to the pins chosen for SoftwareSerial.

...R

Robin2:
You should not use pins 0 and 1 for SoftwareSerial because they are the pins for HardwareSerial. The purpose of SoftwareSerial is to allow you to create a second serial port on different I/O pins.

And then connect the USB-TTL cable to the pins chosen for SoftwareSerial.

...R

Thanks for your support man.
So I switched I/O from 0 and 1 to 2 and 3.

Problem seems to be solved.
:slight_smile: