Prasanna
Prasanna

Reputation: 4703

Swich on external device using COM port

Is it possible to on/off an external relay using serial port's control signals? I know that is its possible using UART. But here I need to do that without using a micro-controller.

Its better somebody can give a sample code in C#

Thanks.

//Here is my code
serialPort1.BaudRate = 9600;
serialPort1.PortName = "COM3";

serialPort1.Open();
serialPort1.DtrEnable = true; //High (On)

Thread.Sleep(1000); //Delay a Second
serialPort1.DtrEnable = false; //Low (Off)
serialPort1.Close();

Upvotes: 0

Views: 1696

Answers (4)

Ed van Hengel
Ed van Hengel

Reputation: 1

I've done this in Visual Basic 6. I made a form and added the Microsoft comm control (mscomm32.ocx). Basically what I do is put the comm port open and quit it when I quit the form. When the comm port is open there is 5v power to pin 4 (Data Terminal Ready) of the comm port. Together with te ground I connected this to a relay. This has a 5V connection witch is able to switch another power connection up to 250V 5A. So you can turn every device on off if you wish.

The relay I use is an Omron G5NB-1A-E PCB Relay. The 2 pins on 1 small site is 5V. The other on the longer side is for switching external devices

This is my code

Private Sub Form_Load()

    MSComm1.PortOpen = True 'Not MSComm1.PortOpen

    If Err Then MsgBox Error$, 48

End Sub


Private Sub Form_Unload(Cancel As Integer)

    MSComm1.PortOpen = 0  '(=False)

    End

End Sub

Update: May 25. I've noticed that when your PC is booting and you're logging in the relay switches a few times on. In my case i wanted to reboot another PC with the relay. I wanted this cross-wise. The other PC must be able to reboot this PC. So i can't have a relay switching on while logging in. I have to search further. Tha means with data transmission or i.ve found somewhere an USB switcher. It's here: http://sigma-shop.com/product.php?ProductID=7

Upvotes: 0

dbasnett
dbasnett

Reputation: 11773

As long as the voltage and current rating needed to turn the relay on/off doesn't exceed the serial ports specifications, it should work, but this is at your own peril. I would have a driver circuit.

Ask the question at https://electronics.stackexchange.com/questions

Upvotes: 0

Jeff
Jeff

Reputation: 1362

It's been a long time, but I remember, some of the control change state when the port is opened and closed. If you add a transistor to one of those lines it cam provide enough current to turn the relay on/off by opening and closing the port.

Upvotes: 0

Coding Flow
Coding Flow

Reputation: 21881

You can send info via the serial port using System.Io.Ports.Serialport but frankly how are we supposed to know what signal is required to turn on your external device?

Upvotes: 1

Related Questions