Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Problem with Leonardo serial port in .NET (Read 5767 times)
roger co
Junior Member
**
Offline



Posts: 14
Problem with Leonardo serial port in .NET
May 13th, 2015 at 2:47pm
 
I have a sketch running on the Arduino which sends text over the serial port to the PC and responds to commands from the PC

Using a Uno or Leonardo the text is displayed correctly in terminal or monitor window (eg built in serial monitor or TeraTerm)

However using a VB.NET (or C#) Windows forms application nothing is recieved or can be sent to the serial port if a Leonardo is used, but it all works fine with a Uno (exactly the same code at both ends in both cases).

The VB programme scans the available serial ports and finds the one with "Arduino Leonardo" name ok, it opens ok, but the programme can't write to the port (timeout error) and nothing is recieved from the port. Works fine with a Uno.

This is probably not a Visual Micro problem; it appears to be a Visual Studio problem. I just wondered if anyone else has encountered it and if there is a fix/workaround.

When the Leo is connected Windows device manager is reporting it as a keyboard and a mouse and a gamepad and a serial port - are the other functions interferring? But only for an app compiled in Visual studio!
Puzzled of Plymouth
Back to top
« Last Edit: May 13th, 2015 at 2:47pm by roger co »  
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: Problem with Leonardo serial port in .NET
Reply #1 - May 13th, 2015 at 4:05pm
 
So just to be clear. You are not trying to use visual micro to upload but you have your own .net windows program that you want to communicate with the Leonardo?
Back to top
 
WWW  
IP Logged
 
roger co
Junior Member
**
Offline



Posts: 14
Re: Problem with Leonardo serial port in .NET
Reply #2 - May 13th, 2015 at 4:12pm
 
Visual Micro (inside Visual Studio) is used to compile and upload the sketch to the Arduino.

The problem is with the application that then communiates with the Arduino running the sketch over the USB virtual serial port. A Uno works fine. A Leo only works with a teminal emulator (eg TeraTerm). The application sees the port but can't write or read to it. The application works fine for a Uno (or a Mega2560)

As I said this is 99% certain not a VM problem, more a general enquiry whether anyone else has this problem with a Windows Forms application produced in Visual Studio.

It looks like a problem in .NET v4.5 Framework
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: Problem with Leonardo serial port in .NET
Reply #3 - May 13th, 2015 at 4:26pm
 
Okay so you are using a different app. The visual micro serial monitor works okay?

It could be a few things.

1) You might be picking up the wrong port for the Leo. It uses one for normal serial and one for upload. Normally the upload port is only detectable when it boots or if you connect to the normal serial port at 1200 baud causing a reboot.

2) The leo requires a short delay before the serial comes up. In the setup() of the arduino code you should have "while (!Serial) {}" which is waiting for the usb to come up.

3) The windows app also needs to wait for the port.

Does your code only attempt to open once. Did you add a button to try manual connect?

Did you try hard coding the port name that visual micro manages to use? That way you can see if your port detection code is getting the wrong port?

I don't think it's a problem with .net

Sorry can't be more help
Back to top
 
WWW  
IP Logged
 
roger co
Junior Member
**
Offline



Posts: 14
Re: Problem with Leonardo serial port in .NET
Reply #4 - May 13th, 2015 at 5:39pm
 
Nope, none of those I'm afraid.
I now have the minimal sketch - ouputs a count every half second - and a minimal windows app - opens a serial port and display numbers recieved.
Uno works, Leo port opens ok but nothing recieved.
In a terminal both Leo and Uno work - numbers dislayed

Attached doc has the minimal sketch and form code if anyone is interested in spotting the error.

(no it doesn't, website error - Could not open a new file on the server, check the paths and chmods D:/Domains/visualmicro.com/www/public_html/yabbfiles/Attachments)
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: Problem with Leonardo serial port in .NET
Reply #5 - May 13th, 2015 at 5:43pm
 
I've altered the attachment permissions please try again
Back to top
 
WWW  
IP Logged
 
roger co
Junior Member
**
Offline



Posts: 14
Re: Problem with Leonardo serial port in .NET
Reply #6 - May 13th, 2015 at 5:52pm
 
Amazingly in the meantime (5mins) Smiley I have stumbled upon the cause of the problem.

For Leonardo when opening the COMport you have to set both DtrEnable and RtsEnable properties true.

Unlike the Uno or Mega2560. The default is that they are false, and many code examples out there set them false explicitly.

Hope this saves someone else some headbanging.

RogerCO
Back to top
 
 
IP Logged
 
RFEFX
Newbies
*
Offline



Posts: 1
Re: Problem with Leonardo serial port in .NET
Reply #7 - Jun 23rd, 2019 at 10:08pm
 
roger co wrote on May 13th, 2015 at 5:52pm:
For Leonardo when opening the COMport you have to set both DtrEnable and RtsEnable properties true.
se explicitly.

Hope this saves someone else some headbanging.

RogerCO



unfortunately i have been banging my head on the desk trying to figure out why my leonardo would not send anything to my VB program.

Thank you oh so very much !!
Genius in my book !! Cheesy
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: Problem with Leonardo serial port in .NET
Reply #8 - Jun 24th, 2019 at 1:17pm
 
Hi both,

You will see that in the Visual Micro serial monitor the default sets DTR and RTS to true. THis is the case for all Arduino boards. In fact I think it is only the ESP boards that do not use this system but they have a config setting to tell us not to enable DTR.

The only time you should see an external code example that does not enable DTR is when triggering the bootloader for certain boards that require a 1200 baud connect to reset the chip and put it on programming mode. The Leonardo is a board that uses this special reset and those are the code examples you might have seen, all relate to upload.

Your own VB programs will not want to upload, instead just use the Serial to the board. In this case you should always set the DTR for all Arduino boards.



Back to top
 
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print