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 the COM port. Everybody wants things to be easy 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 are fewer chances of failing.

So if you know Visual Basic a little bit, then this shouldn’t be tough to use the MSComm Control component, located in Project->Components. You should check box MSComm Control. Later you have to add this control to the form and write some code for it.

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

One good example is popular programming software PonyProg (which is programmed in another language than VB, but the principals are the 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 the pin state of the port, it is enough to send unipolar positive signals without converting TTL-RS232. Of course, this doesn’t comply with the RS232 standard but this way works perfectly. But this is only recommended to hobby circuits. Professional hardware should have a 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 of output (+12V) and (-12V), and this way to light a LED or turn on Relay or another device. For instance, output for pin RTS command:

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

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

That’s it. Using these commands, it is possible to program simple data transfer or complicated protocols, such as I2C, SPI, MicroWire, etc. One good example is the DS1621 pc thermometer, developed by Alberto Ricci. He programmed the I2C protocol for data transfer between the DS1621 thermometer. https://korepetitoriai.intellectus.lt/fizikos-korepetitoriai/ fizikos korepetitoriai, vaikų stovyklos Vilniuje, Kaune, Klaipėdoje, anglų ir ispanų kalbos kursai gera kaina

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

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

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

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

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

Changing the number of impulses for 0 and 1 can change impulse width in one-byte limits with a one-bit step. So we can send numbers FF, FE, FC, F8, F0, E0, C0, 80, 00 to port to get all available interval of impulse widths. The 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 the port. So if you want to send F0 (decimal 240), then use the following:

MSComm1.Output = Chr(240)

This way, we can generate 8 levels PWM and control motor speed or LED brightness – just signal has to be amplified because maximal current-driven from the port is 25mA.

Port settings can be changed with command

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

This way, we can change baud rate parity, the number of bits, and some stop bits.

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

5 Comments:

  1. VB_NET2003 doesn’t support Com port , but VB_NET2005 does, you just need to install Framework2.0.

  2. 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?…

  3. 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.

  4. This is analogous to connecting a dual-supply input to the minus power rail. This requirement for biasing the op amp inputs to achieve the desired output voltage swing complicates single-supply designs.

Leave a Reply