Controlling external devices using COM port communications programmed using VB language
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 use MSComm Control component which is located in Project->Components. You should check check box MSComm 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:
If MSComm1.CTSHolding = False Then
or
If MSComm1.CTSHolding = True Then
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 is DS1621 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).

Then you can start program Com_device to 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:

Then you can start program Com_device to 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:

Changing number of impulses for “0” and “1” 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 – 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
Blogsphere: TechnoratiFeedsterBloglines
Bookmark: Del.icio.usSpurlFurlSimpyBlinkDigg
RSS feed for comments on this post | TrackBack URI for this post
New on WinAVR Tutorial
Running TX433 and RX433 RF modules with AVR microcontrollers,Sometimes in embedded design you may want to go wireless. Might be you will want to log various readi …Programming AVR ADC module with WinAVR,Most of AVR microcontrollers have Analog to Digital Converter (ADC) integrated in to chip. Such solut … |
New on WinARM Tutorial
What are differences between WinARM and WinAVR,Everyone who is working with AVR microcontrollers knows this powerful tool – WinAVR (http://win …LPC2000 watchdog timer,As in all microcontrollers watchdog timers purpose isto reset microcontroller after reasonable amount … |

March 7th, 2007 at 2:42 pm
VB_NET2003 doesn’t support Com port , but VB_NET2005 does, you just need to install Framework2.0.
December 10th, 2007 at 7:08 am
Hello there where did you listen about the amateurs?…I think I am on the top of them hehe.
I am working on the lpt but this serial seems interesting, so working on rs232 what kind of hardware should i get?…
December 10th, 2007 at 7:13 am
Also one little help if you know something…do you know, after mscomm has dialed a number and the other person answers the phone, how to send a touch tone like eight or three through the line?. I suppose there is a command for the modem.
July 15th, 2008 at 4:27 am
[...] Controlling external devices using COM port communications programmed using VB language - Scientific… __________________ Vinay Is Cool.. ha ha ha [...]