Nothing happens because nothing beyond the
return U0RBR;
in the ISR gets executed. All of your conditionals that could do something are in the dead code following the unconditional return.
Likely you need to rethink the architecture of your program, particularly the relationship between the ISR and the main program loop - there are advantages and disadvantages to doing command processing in either place.
Why do you need it to be sent as a string?
Just send a byte value and treat it as so in the Arduino. The serialPort1.Write
method will likely have different overloads for various formats including byte.
If you need to represent a value >255 then you can send it over multiple bytes and concatenate into e.g. an int at the Arduino.
NOTE - you seem to have changed the code in your question since the below was written, but I'll leave it there as the concept is still valid.
EDIT
At the moment you are sending in ASCII format from the PC, so 0 - 0x30, 1 = 0x31 etc. To send in plain binary check the overloads for the method.
Try putting something like:
private void button1_Click(object sender, System.EventArgs e)
{
// Say we want to send 23456 (0x5BA0)
//serialPort1.Write(200); // 200 is "send value" command
//serialPort1.Write(91); // 100 (0x5B) is your upper byte value
//serialPort1.Write(160); // 160 (0xA0) is your lower byte value
// this uses the serialPort1.write overload correctly
// 1st byte is command, 2nd and 3rd are upper and lower bytes of int
byte[] data = new byte[] {200, 91, 160};
serialPort1.Write(data, 0, 3); // 0 is the offset and 3 is the size of array
}
and see if it is recieved correctly at the Arduino (do not read it as a string, e.g. if incoming byte == 200)
Something like the below should work - you will have to adjust accordingly to make it do whatever it is you are trying to do, this is just an example of transferring bytes:
if (incomingByte == 200) {
upper_byte = (unsigned char)Serial.read();
lower_byte = (unsigned char)Serial.read();
// full_value should be 23456
int full_value = (upper_byte << 8) + lower_byte; // reconstruct int
}
Notes:
You can write code to split an int into the two bytes (I just put an example "test value")
Again, there may be overloads for this. Also you can use any multiple byte receive capability in the Serial.read routine.
Best Answer
Check the Wiki page out, particularly this bit:
Control signals are logically inverted with respect to what one sees on the data transmission lines. When one of these signals is active, the voltage on the line will be between +3 to +15 volts. The inactive state for these signals is the opposite voltage condition, between −3 and −15 volts. Examples of control lines include request to send (RTS), clear to send (CTS), data terminal ready (DTR), and data set ready (DSR).