0

I'm using .NET 4.5.2. In one of my ViewModels, I need to access serial port COM8, which is connected to my device, a sensor that provides a continuous stream of data. I can access and send commands to the serial port via Tera Term, Windows Command Prompt, and a LabView application, so the port is not occupied by another process - I know that is usually the case with these posts, but I'm very sure that is not the case here. I've tried sending a command to the port via C# using the Process() class, but that does not work, so it seems to be something with C#.

I saw this post: Force a COM port to close, but that does not seem to be the issue either.

Other things I've tried:

  • Uninstalling the COM8 device via Device Manager.
  • Running the application in "Release" mode via Visual Studio.
  • Running Visual Studio in Administrator mode.
  • Switching to .NET 4.5.2.

And a few other things that I'm not recalling right now. Any advice about this situation would be appreciated! I'm happy to provide any more information you may need.

Code to open the port:

if (port == null)
{
    port = new SerialPort(location, baudRate);
    port.ReadBufferSize = 16384;
}     
if (!port.IsOpen)
{
    port.Open();
}

Update:

If I copy the above code into the startup method, it works fine. It just doesn't seem to work where it is in my ViewModel. I thought it was a threading issue, but I was able to call the code in the main thread and it did not work. Hopefully this will get me closer to a solution!

Update 2:

The code above also works fine in the codebehind of my login method, but in no other codebehind. Super confused right now.

adjordan
  • 39
  • 2

0 Answers0