Driving DTR with System.IO.Ports.SerialPort in .NET

南笙酒味 提交于 2019-12-06 01:31:21

i wrote this to test DTR. it works as expected using my USB serialport adapter. i checked it by attaching the cable to my DataTracker (RS232 breakout box, with LED's). DTR does change.

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    SerialPort1.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    SerialPort1.PortName = "COM5"
    SerialPort1.Open()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    SerialPort1.RtsEnable = True

    Debug.WriteLine("DTR +")
    System.Threading.Thread.Sleep(1000)

    SerialPort1.DtrEnable = True 'DTR -
    Debug.WriteLine("DTR -")
    System.Threading.Thread.Sleep(1000)

    SerialPort1.DtrEnable = False 'DTR +
    Debug.WriteLine("DTR +")
    System.Threading.Thread.Sleep(1000)

    SerialPort1.RtsEnable = False
End Sub

Check the pinout of the cable. It might be contributing to the problem.

Cable Pinouts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!