Set DTR pulse using System.IO.Ports.SerialPort

A

Andrew Poelstra

Hey all,

I have my serial port configured with the follow perl script
to pulse the DTR line when you open the port. This resets my
device, which is important during programming. (If the device
is not reset, it can only be programmed by fluke if its state
is correct.)

use Device::SerialPort;
Device::SerialPort->new("/dev/ttyUSB0")->pulse_dtr_on(100);

HOWEVER, on the C# side of things, when I open the port for
communication, it also sends the DTR pulse and resets the
serial device, which I do not want. My test C# code is:

port = new SerialPort("/dev/ttyUSB0", 115200, Parity.None, 8, StopBits.One);
try {
port.Open();
for(int i = 0; i < 3; ++i)
System.Console.WriteLine(port.ReadLine());
}
catch(System.IO.IOException) {
System.Console.WriteLine("Failed to open port.");
}

Whenever I run this code, I can see the device reset (it
has a LED indicator of its program progress), and I see
its three-line boot message appear in the console.


So my question is, can I turn off the DTR pulse from C#? I'm
using System.IO.Ports.SerialPort and portability is a pretty
big concern for this project. (Also, I'm running Mono rather
than .NET so I can't pInvoke or use COM.) (That I know of.)


Andrew
 
A

Andrew Poelstra

Hey all,

I have my serial port configured with the follow perl script
to pulse the DTR line when you open the port. This resets my
device, which is important during programming. (If the device
is not reset, it can only be programmed by fluke if its state
is correct.)

use Device::SerialPort;
Device::SerialPort->new("/dev/ttyUSB0")->pulse_dtr_on(100);

HOWEVER, on the C# side of things, when I open the port for
communication, it also sends the DTR pulse and resets the
serial device, which I do not want. My test C# code is:

port = new SerialPort("/dev/ttyUSB0", 115200, Parity.None, 8, StopBits.One);
try {
port.Open();
for(int i = 0; i < 3; ++i)
System.Console.WriteLine(port.ReadLine());
}
catch(System.IO.IOException) {
System.Console.WriteLine("Failed to open port.");
}

Whenever I run this code, I can see the device reset (it
has a LED indicator of its program progress), and I see
its three-line boot message appear in the console.


So my question is, can I turn off the DTR pulse from C#? I'm
using System.IO.Ports.SerialPort and portability is a pretty
big concern for this project. (Also, I'm running Mono rather
than .NET so I can't pInvoke or use COM.) (That I know of.)

I think I've got it. Before calling port.Open(), if I call

port.DtrEnable = true;

It does not pulse the DTR line and the device does not reset.
I have searched the Internet and not found any help to this
effect (other than the Arduino folks suggesting I cut my
auto-reset line and use the reset button when programming),
so I hope somebody finds this helpful.


Thanks everyone
Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top