Question

I access my COM port using the manufacturer hardware DLL in C# .Net 4. Connected to my COM port I have a Nanotec stepper motor control SMCI 33.

The manufacturer provides a flag "SetSendStatusWhenCompleted" to send a Status byte, when the movement of the hardware stepper motor is completed. Unfortunately there is no function to listen to this status byte. I want to add this functionallity.

Goal: Send a movement command using hardware driver. Wait for: Listen to the response "status byte" before sending next movement command.

using System.IO; using System.IO.Ports;
(... access same com Port via driver of hardware manufacturer. ...)
sp = new SerialPort();
    sp.PortName = "COM4";
    sp.BaudRate = 115200;
    sp.DataBits = 8;
    sp.StopBits = System.IO.Ports.StopBits.One;
    sp.Parity = System.IO.Ports.Parity.None;
    sp.Handshake = System.IO.Ports.Handshake.None;
sp.Open();

Obviously I get an UnauthorizedAccessException, because my code started the driver and tries to access the same COM Port. A similar SO Question treats the COM access from another program: A Port sniffer (Portmon) is the solution. But my question demands simple code.

I could stop the hardware driver. Currently the issue is time costly re-initialisation. Is there an other way to listen to the COM Port, than to shut the previous hardware driver down?

Was it helpful?

Solution 2

The hub4com from Nullmodem com0com project provides requested multiplexing. Hub4com implements multiplexing and manages the requests on a com port. This allows both a) driver and b) the OP's code to access the same COM port.

OTHER TIPS

You should use a Monitor tool, to better understand what your other application really does and what comes on the wire. Additionally you can set up two virtual com ports to test reading and writing on one machine (even within the same application), to have a better control about when will which data be send.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top