LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Read status of CTS while serial port is opened by another application

I need to read status of CTS line of an RS232 port while port is opened by another application. Port is already open and I do not have direct access to the port lines via CVI functions.

Is there anyway to do this? I am not sure If I can read port registers using inp function.

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 1 of 9
(6,043 Views)

I think best way to find out is to try it.

Write a small application that uses the inp function and reads the memory range of the COM port (can be found from the Device Manager).

 

Before running that executable, open the COM port using the interactive execution.

Manually apply voltages on the pins, or just apply some jumpers and observe the results.

 

Btw, I realized I didn't know the signal level for control signals, are they TTL or like the TX/RX signals?

I'd be glad if you could post the resuts here  :smileywink:

 

 

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 9
(6,025 Views)

Hi Thanks for your suggestion. I am using USB to serial cable and in my device manager I don't have Resources tab which list address range for that port.

My comport number is 3.

Any other idea?

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 3 of 9
(6,017 Views)

Hey test_man,

 

The function viGetAttribute can be called for the VI_ATTR_ASRL_CTS_STATE attribute using the NI-VISA driver. This returns the status of the CTS line. If the port is opened by a non-VISA call, then you won't be able to do this. Like you said, using the inp function would work if you were able to find the address space of the USB device. I'll have to research into this a bit more to see if I can find where the USB device's I/O range is.

Justin E
National Instruments R&D
0 Kudos
Message 4 of 9
(6,003 Views)

test_man,

 

I wasn't able to find where the I/O range for this device is set, but you might be able to do something with the Windows API. You'd have to research into that more to figure out if that's a possibility though

Justin E
National Instruments R&D
0 Kudos
Message 5 of 9
(5,992 Views)
What about having a second USB to Serial convertor and wiring just the CTS line to that. You can then  open the second port and will have full control of it.
0 Kudos
Message 6 of 9
(5,970 Views)

Justin_E wrote:

"you might be able to do something with the Windows API"

 

Let's have a look at the Windows SDK, in "About Communications resources/Communications resource handle":

"When the process uses CreateFile to open a communications resource, it must specify certain values for the following parameters: [...] The fdwShareMode parameter must be zero, opening the resource for exclusive access. "

 

this line taken from the SDK tells us that anybody willing to open a COM port must have exclusive access over it. the only calls allowing to read the status of the CTS line needs a file handle to do so. so i can conclude that to read the status of the CTS line, you should have opened the port yourself.

 

in any case, reading the status of a flow control line when you are not part of the conversation is not clean. ho, and i forgot: when will people stop using the serial and parallel ports as a general purpose i/o board? these ports were never intended for this, but there are boards made specifically for this kind of stuff.

0 Kudos
Message 7 of 9
(5,945 Views)

Serial port monitors do monitor status of RTS and CTS lines when port is opened by another application. So solution is out there...I just don't know how to do it.

For example, I tried HHD Free serial port monitor. It successully monitored all of the lines of serial port while serial port was opened my another application at the same time.

 

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 8 of 9
(5,938 Views)

i can bet that a serial port monitor is a special driver loaded on top of microsoft driver.

 

on Windows, most driver type allows for filters or mini-drivers which sit between the real driver and the kernel to perform special processing. personally, i would implement it this way. unfortunately, this means really low level development, with extra care because this kind of drivers run in kernel-mode, and a special communication pipe between the kernel-mode driver and the user-mode application. you may find more informations about driver development in the Windows Driver Development Kit, which is available from Microsoft's website.

0 Kudos
Message 9 of 9
(5,931 Views)