Position: Index > Control Circuit >

Controlling external devices using COM port communications p

2015-03-01 00:00  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

There are a lot of Radio amateurs that want to control external devices using computer standard ports. One of them is COM poert. Everybody wants things to be ease as people doing electronics are more hardware people not software. COM port is more often used than LPT because COM port is more resistive to bigger loads and there is less chances of failing.

So if you know Visual Basic a little bit then this shouldn’t be very hard to useMSComm Controlcomponent which is located inProject->Components. You should check check boxMSComm Control. Later you have to add this control to form and write some code for it.

Main difficulty with this is that you have to follow RS232 protocol. This is why it is better to use microcontrollers that have built in USART interface. Of course MSComm component allows to read and control single COM pins and this way to control any external devices without using RS232 protocol.

One good example is popular programming software PonyProg (which is programmed in other language than VB, but principals are same). You can see various supported circuits that PonyProg supports and you can see that Rx(2) and Tx(3) signals aren’t used at all. All data transfer is done via CTS(8), DSR(6), DTR(4), RTS(7) (in some places Tx(3) is used).

In order to read pin state of port it is enough to send unipolar positive signals without converting TTL-RS232. Of course this doesn’t comply with RS232 standard but this way works perfectly. But this is only recommended to hobby circuits. Professional hardware should have conversion.

So we can read three pins of COM port: CD, CTS, DSR. Command reading CTS(8) would look as follows:

IfMSComm1.CTSHolding =FalseThen

or

IfMSComm1.CTSHolding =TrueThen

With this command we can read weather logical 0 or 1 is on pin CTS.

COM port pins DTR and RTS are capable to output ( 12V) and (-12V) and this way to light a LED or turn on Relay or other device. For instance output for pin RTS command:

MSComm1.RTSEnable =False( 12v on 7 pin)

MSComm1.RTSEnable =True(-12v on 7 pin)

Thats it. Using these commands it is possible to program simple data transfer or complicated protocols for instance I2C, SPI, MicroWire and so on. One of good examples isDS1621 pc thermometer, developed by Alberto Ricci. He programmed I2C protocol for data transfer between DS1621 thermometer.

You can construct simple circuit in few minutes (you can assemble it directly on DB9 header).

Com_sw.gif

 

Then you can start programCom_deviceto see how program reacts on button press and toggles LED using exactly same commands that we described above.

If your device requires pulse signal this also non difficult task but in this case you should know RS232 protocol a little bit:

rs232.gif

 

Then you can start programCom_deviceto see how program reacts on button press and toggles LED using exactly same commands that we described above.

If your device requires pulse signal this also non difficult task but in this case you should know RS232 protocol a little bit:

rs232_impulse.gif

 

Changing number of impulses for a€?0a€? and a€?1a€? we can change impulse width in ine byte limits with one bit step. So we can send numbers FF, FE, FC, F8, F0, E0, C0, 80, 00 to port to get all awailabe interval of impulse widths. Picture above is F0.

In order to send to port such signal we need to send following command:

MSComm1.Output = “symbol or string”

Using this command you can send any ASCII character to port. So if you want to send F0 (decimal 240), then use following:

MSComm1.Output = Chr(240)

This way we can generate 8 level PWM and control motor speed or LED brightness a€“ just signal has to be amplified, because maximal current driven from port is 25mA.

Port settings can be changed with command

MSComm1.Settings = “1200,N,8,1″

this way we can change baud rate parity, number of bits and number of stop bits.

Source: http://www.schemz.narod.ru

 


Reprinted Url Of This Article:
http://www.scienceprog.com/controlling-external-devices-using-com-port-communications-programmed-using-vb-language/