c# - How to auto-detect devices connected to COM ports -
c# - How to auto-detect devices connected to COM ports -
i want auto observe devices connected com ports of computer. beingness able utilize serialport class allows me list of available com ports easily.
i want iterate through them , poll(send command) each port , wait response. seems tutorials suggested utilize datareceived event. lost @ how serial send followed waiting xx amount of seconds till receive response device.
the datareceived event nice when need talk devices can send @ unpredictable time. don't have fire thread blocks , waits device send something.
but that's opposite of you're trying achieve, do expect receive something. don't utilize datareceived, utilize read() readtimeout property set suitably low value. simple. consider using dsrholding property. true when there's device attached port , powered-up.
i should note doing rather dangerous. have no thought kind of devices attached machine, rather tricky send them not designed process. if whatever "are there?" command send happens mean robot controller "go home 1g acceleration" going wound easily. cannot in kind of industrial setting.
by far best way create else's responsibility right. add together alternative menu lets user set port name. , settings, matter lot , there's no way auto-detect them. alternative dialog have "help me find device" button, safe and useful.
c#
Comments
Post a Comment