-1

I want to make a Desktop application with WPF(.net 5). In this application, I want to connect various hardware devices(sometimes simultaneously) via a USB port, Serial ports/Com port (e.g. RS232), etc.

I want the application to talk both ways. Receiving data from hardware devices with a range of configurations(i.e. baud rate, frequency, data string), and Sending data to display, modify settings of the device.

I don't have any idea about where to start in WPF | .NET | C#. Are there any inbuilt classes, APIs to achieve this?

Devices I want to connect are;

  Serial port: Weight Scales, 7 Segment Displays, Liquid Analyzers
  USB port: USB sticks containing text, JSON files; If one of the above serial port devices has a USB variant then those are too.
E_net4
  • 27,810
  • 13
  • 101
  • 139
rcode
  • 23
  • 5
  • Do you projects step by step. Start for example with the Serial port. Look [here](https://learn.microsoft.com/en-us/dotnet/api/system.io.ports.serialport?view=dotnet-plat-ext-6.0) for information about the SerialPort. – Jeroen van Langen Jan 03 '22 at 12:30
  • The fact that you're developing a WPF application is irrelevant. Write the connection for each device as a standalone module that's distinct from the user interface, and use a console application for development / testing. – Peregrine Jan 03 '22 at 14:43

1 Answers1

1

There is the Serial port class in .Net, but you might want to read some criticism about the class before using it. There are also libraries available to communicate over USB.

But these are fairly low level protocols that does not know what kind of device is on the other end. So your UI would therefore also need to low level, i.e. send/receive raw data. And this would mostly be useful for expert users using very specialized devices. While you could probably make the part that sends and receive data share an interface for both USB and Serial, connection and setup would probably need to be handled differently, since these are handled differently for serial and USB.

If you want a easier to use UI you would need to know more about what kind of device it it. There is a number of standardized USB device classes that specify what kind of device it is, and there are often high level APIs to interface with these devices. But that would require coding a module for each individual device class.

So I would recommend to start with figuring out what you really want to do? Connect to a IO board with some general purpose IO pins? Connect to some specialized device like a PanTilt unit? Read data from a webcam? Read some data from some kind of sensor, do some processing and control some kind of output device?

JonasH
  • 28,608
  • 2
  • 10
  • 23
  • Thanks for the reply! I want to communicate with Weight Scales, 7 Segment Displays, Liquid Analyzers on serial port... And on USB I want to communicate with USB sticks having files.. and In case one of the above serial port devices has a USB variant then those are too... – rcode Jan 04 '22 at 06:13
  • @rcode then you would typically write a class per type of device with appropriate functions for each, and let these classes deal with sending commands and receiving results from the device. For USB sticks, just use the regular file-system functions to read/write files. If needed, there are APIs for checking what drives are removable, and monitor insertion/removal of such drives. – JonasH Jan 04 '22 at 07:39