Go Down

Topic: Csharp playground (Read 1 time) previous topic - next topic

AWOL

Code: [Select]
if (Serial.available() == 5) I'm not keen on that construct, particularly when there are long delays in a sketch.
Is that one of the bazillion errors?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

The .cs file that you posted is only one of the files in a C# project. I'm not inclined to want to reproduce (by guessing) those other files. You can zip up your whole solution directory (then delete the pdb files from the zip file) and attach that zip file to your post.

Is that C# file the code with the errors or the fixed code? If it is the fixed code, what changes did you need to make?

Adding some calls to Console.WriteLine() and running the C# code in debug mode would tell you whether the Arduino's serial port is detected and what, if any response is received.

Which Arduino are you trying to detect? That code would detect a Leonardo, for instance.

fulminator


Code: [Select]
if (Serial.available() == 5) I'm not keen on that construct, particularly when there are long delays in a sketch.
Is that one of the bazillion errors?


No, actually it works. The code posted by me is corrected and it's running with no errors. But it doesn't provide results.
It's comparing the serial data length (which is 5 bytes), I guess. There is no debug mode in Arduino GUI, so I can't really know what's going on   on that line. BTW, in my previous post I have added a zip containing the source.

PaulS

AWOL's point (very subtle, but very important) is that == is not a good choice. What would happen if 6 characters arrived? Your code would never do anything. The test for == 5 should be >= 5, so that 6 characters will cause some to be read, too.

PaulS

Quote
edit: I have attached the full code here:

I don't think I'll go there for code.

Go Up