1

I want to set DTS and RTS pins to true/false in .NET using SerialPort-Class.

When setting pins to true/false and sniffing COM-Port there are alot of other things send to the COM-Port that I don't want.

Sniff-Log: https://i.stack.imgur.com/1KU7P.png

Code:

SerialPort serialPort = portSelector.SelectedPort;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.DataBits = 8;
serialPort.ReadTimeout = 10;
serialPort.WriteTimeout = 10;
serialPort.BaudRate = 5;
serialPort.Handshake = Handshake.None;

serialPort.Open();
serialPort.DiscardInBuffer();
serialPort.DiscardOutBuffer();
serialPort.DtrEnable = false;

If I do the same thing in C it works and is not sending any garbage I don't want. Can you tell me what I'm doing wrong?

Thank you

Roman R.
  • 68,205
  • 6
  • 94
  • 158
nodna
  • 11
  • 5
  • The question is not about [tag:COM], I removed the tag. [tag:serial-port] is what you need. – Roman R. Apr 27 '15 at 08:13
  • A bit hard to guess what "down" and "up" could mean in that trace. Or why you think it is a problem. But you'll probably feel better if you set the DtrEnable property *before* you call Open(). – Hans Passant Apr 27 '15 at 08:35
  • I want to do a hardware handshake which requires to send multiple DtrEnable RtsEnable to true/false one directly after another. – nodna Apr 27 '15 at 11:03
  • Ended up using unmanaged code importing native DLL functions. http://www.pinvoke.net/ – nodna Apr 28 '15 at 08:43

0 Answers0