LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the other pins in a serial port?

Hi there.
In the DB-9 serial connector there are 9 pins, im currently using only 3 pins (Tx, Rx and Ground).
Can i use the others?

My situation is this:
I have a PIC application, the PIC is used for measure and controlling purpose. I will send the parameter using the serial port of the PC.
The problem is, if i put the instruct in the PIC to read the serial port data, it will stop everything until it reads something.  So if no data was sent then it would wait forever and do nothing else.
So i thought, if i could use another pin in the serial cable i could tell the PIC that there is data to be read from the serial.
Something like:
on the PC
make pin? = 1 (5v)
send serial data
when the output queue becomes 0 (data was read) then make pin? = 0.

on the PIC
if data in pin? = 1 then read serial port.

The PIC doesnt have buffers so i cant use hardwarehandshaking for this.
0 Kudos
Message 1 of 10
(5,392 Views)
Hi Malanar,

we use the ccs compiler to write pic programm in c. There is a function
called kbhit() that can be used to check if there is a byte received at the
com port. So you can check this with a timer or within your program loop.
Another way is to use the Interrupt. If there is a byte comming in you get
an interrupt and can write the incomming data into a software buffer.

Maybe the dtr signal is also useful. Within CVI use the function
"ComSetEscape" to set or clear the dtr (data terminal ready) signal.

Then u can connect the DTR signal pin on a port pin on your PIC and check it
within a loop or timer:

I prefer to use the serial interrupt, because its a direct way to get
informed about incomming data.

Greetings from Bremerhaven (Germany)

Norbert Rieper






"Malanar" <x@no.email> schrieb im Newsbeitrag
news:1147812014897-366081@exchange.ni.com...
> Hi there.
> In the DB-9 serial connector there are 9 pins, im currently using only 3
> pins (Tx, Rx and Ground).
> Can i use the others?
>
> My situation is this:
> I have a PIC application, the PIC is used for measure and controlling
> purpose. I will send the parameter using the serial port of the PC.
> The problem is, if i put the instruct in the PIC to read the serial
> port data, it will stop everything until it reads something.&nbsp; So
> if no data was sent then it would wait forever and do nothing else.
> So i thought, if i could use another pin in the serial cable i could tell
> the PIC that there is data to be read from the serial.
> Something like:
> on the PC
> make pin? = 1 (5v)
> send serial data
> when the output queue becomes 0 (data was read) then make pin? = 0.
>
> on the PIC
> if data in pin? = 1 then read serial port.
>
> The PIC doesnt have buffers so i cant use hardwarehandshaking for this.


0 Kudos
Message 2 of 10
(5,376 Views)

As stated by Malanar, ComSetEscape() can be used to control the DTR or RTS signals.  The logic level of a standard PC serial port is pulse and minus 12V not 0-5V, but since you are feeding RX and TX to the PIC you obviously have this covered.   Implementing it the way you describe is really just creating you own method of hardware handshaking.  It should not be a problem.

You can read the CTS and DSR signals with GetComLineStatus(), but it is probably too difficult to generate the correct logic levels for the signals from the PIC side of things.

Message Edited by mvr on 05-17-2006 09:11 AM

0 Kudos
Message 3 of 10
(5,362 Views)
Thanks for the reply, i will try that. I will need to change te -12V to a 5V signal to apply it to the PIC, shouldnt be a problem.

Message Edited by Malanar on 05-20-2006 10:00 AM

0 Kudos
Message 4 of 10
(5,323 Views)

Hello to all,

 

I am new & have simple question,  how to see DTR & RTS value on the pin (someone may pull it down) ??

 

        ComSetEscape(4,SETDTR);
        ComSetEscape(4,CLRDTR);

 

This two lines  realy change the signal on the DTR pin, but I can read it back ? or have to make DTR image in the variable?

 

        status = GetComLineStatus(4);

 

Status does not contain DTR signal ! or it does?, where is function to give me the DTR value in return ,  who will give me the asnwer ? 

 

p.s. better, if exist read modify write function for DTR pin ..  

 

 

                                                      regards      Smile_
 

0 Kudos
Message 5 of 10
(4,907 Views)

on a serial cable, every signals which goes in one direction has a counter-part which goes in the reverse direction. in this case, the couterpart to DTR is called DSR. you can read the state of the DSR signal by using the GetComLineStatus() function.

 

(please, create a new thread for posting a new question)

0 Kudos
Message 6 of 10
(4,876 Views)

Hi to all,  

 

- PC 16550D is common COM serial standard controller on PC computers ...

- MCR modem control register, MSR moden status register, Echo mode

 

- There deep in 16550 in MCR is bit 4 , when it is set  the 16550 is in echo mode

                                  

- MCR  bit4 = 0 :     MSR   bit 4 = CTS,          bit 5 = DSR    ( non Echo mode)            

- MCR  bit4 = 1 :     MSR   bit 4 = RTS,          bit 5 = DTR     ( Echo mode, means the loop back mode output signals are tied back , input signals cts&dsr are cut off)       

 

That means I can read status of RTS & DTR on same controller in echo mode of itself.

 

Q: The question is how to do this job in CVI with CVI instructions ..   

 

 

                                                             regards Smile_

0 Kudos
Message 7 of 10
(4,842 Views)

The CVI libraries are, for the most part, layers over the Win32 API (or Linux equivalent).  CVI can therefore only do what windows allows it to.  Windows provides a set of functions for writing/reading to serial ports, and controlling their handshake lines manually if desired.  If you want to access the registers of 16550 directly, you'll have to bypass drivers, etc.  Probably not the most graceful or easy solution.....I don't know what you're doing, but I would suspect there is a better way to accomplish it:

 

As previously mentioned, the serial ports have some output signals, and some input signals.  The Windows abstraction layer seems to assume that since you're controlling the serial port, you should already know the state of the output signals (I've never stumbled across a function to read back RTS or DTR signals after you set them).  The output signals are, however, set to well defined values when the port is opened, and if you're using manually handshaking, then your software should know the values of the lines and be able to keep track of when you set/clear them.  As for the input signals, you can read them with the GetComLineStatus function.

 

If you want to review the Win32 API functions that are likely used by CVI to perform all of this, check out http://msdn.microsoft.com/en-us/library/aa363194(VS.85).aspx 

0 Kudos
Message 8 of 10
(4,827 Views)

Well, the real world is defferent.

Set DTR, CTS not always means that the DTR,CTS goes high.

Usualy on start stuff not works, what is wrong? expect the software tell

me what, cable, Hw Sw ?

I have idea how to test this lines, maybe make DLL somewhere and use

functions..

 

                                              regards Smile_

 

 

0 Kudos
Message 9 of 10
(4,804 Views)
I know very well how serial ports work in the real world, and have used them literally hundreds of times through CVI and Windows calls.  Not to mention writing 16550 emulated ports in verilog for CPLDs and FPGAs.  If you're dead-set on reading and writing to the 16550 registers, then you'll need to use the CVI functions inp() and outp().  You can look up the ioport location for your serial port through the resources tab of the com port in the device manager.  I would NOT suggest going this route, as you'll probably just cause yourself a bunch of headaches, and your code will probably not work with USB serial adaptors (which are becoming more and more the defacto serial port devices on newer laptops and desktops).
0 Kudos
Message 10 of 10
(4,796 Views)