Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can C++ give output voltage at serial port 1 ?

Status
Not open for further replies.

warik

Programmer
Jun 28, 2002
169
ID
Dear all,

Can C++ give output voltage (for trigger transistor) at pin 5 at serial port (com port 1) ?

I ever do this, but using PPI Card and Turbo Pascal for trigger external device.

Thank you in advance.
 
As far as I am aware, you should be able to do this. You will need to look at the hardware (UART registers etc) and see what corresponds with pin 5. Then you will need to program the register (via its address) to get a result on the pin you are after.

You can certainly do this in C++ (or any other language) but you are programming at a very low level (ie - the hardware). Your operating system will be the major factor here as it has control of all the devices (the serial port being just one of them).

There are many 3rd party libraries (as runtime DLLs, compile time inclusions etc) that will handle all the "messy" low level details for you. If you want to do it yourself with C++ then check out the Microsoft WinSDK help files. The old methods such as outportb(), inportb() etc are no longer supported as far as I am aware (but probably still usable).

Hope this answers your query.
 
Mattcs, thank you for your respon.
I'll try it again...

Thank's
 
I think you may want to open the COM port, then use the EscapeCommFunction function to send a modem signal, whichever one corresponds to pin 5 ( I think its Data terminal ready pin?). So like this:

DWORD Escape = SETDTR;

HANDLE PortHandle = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

EscapeCommFunction(PortHandle, &Escape);

// Wait a second
Escape = CLDTR;
EscapeCommFunction(PortHandle, &Escape);

CloseHandle(PortHandle);

 
5 is DTR on a 25 pin serial.
5 is ground on a 9 pin serial.

What are you trying to do with the voltage?
Perhaps the parallel port might work better for what you are trying to do?

What is a PPI card?
 
Supernat03,
Thank you for the code, I still try it.

c567591,
PPI card is peripheral interface between IBM Computer to I/O device using IC Paralel Peripheral Interface 8255. So we can control the I/O device from IBM-PC.
I used Pascal to give output to each pin at that PPI port output.

But as I know, we also could use Serial Port (Com 1 & Com 2) to do the samething with PPI Card.

So, maybe anybody could give idea about using C++ to give output to each pin at serial port. There is a lot of thing we can do with that, let say :
- Open the drawer from register cash from Serial Port.
- Controling Motor Stepper from Serial Port.
- etc.

 
There is a problem with this approach: Win NT (i.e. 2000, ME, XP(aka: eXtra Problems) does NOT allow direct access to hardware in the"good old DOS"-fasion, with these OS you have to use a driver. I would personally build a Serial-to-Paralell device controlled by commands on the serial port but then again i'm building devices allowing that on a daily basis.
The problem with direct access remains on the PPI-card but You could get a few "pins" in and out on each COM port.

Totte
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top