Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING
Free library / Schemes of radio-electronic and electrical devices

Controlling the Ke-USB24A module from Excel. Encyclopedia of radio electronics and electrical engineering

Free technical library

Encyclopedia of radio electronics and electrical engineering / Computers

Comments on the article Comments on the article

The first part

The whole charm of programming the Ke-USB24A USB module can be appreciated when the question arises of the need to write a program in some not very widespread language or for any environment that, it would seem, does not provide for the ability to work with USB devices. How to be here? - deal with connecting libraries, calling system functions, etc.? All this is often difficult. The Ke-USB24A module is a completely different matter! Due to the fact that the programming interface is implemented in the form of a serial port, it is possible to program the module in almost any language. Let's demonstrate this with an example. In this article, we will look at how you can control the module outputs from Excel! Yes, yes, it is from it, where you usually make tables and build graphs.

In order for Excel to communicate with the COM port, we need to install a special component from Microsoft in the system - the MSComm ActiveX element. For this download files for this article. There is an ActiveX folder there.

Controlling the Ke-USB24A module from Excel

To install the component, just execute the file Install.bat - he himself will perform all the necessary work to install and register the component in the system. During the process, you will be asked the following question:

Controlling the Ke-USB24A module from Excel

Click Yes. A successful installation message will appear. We press "Ok".

Controlling the Ke-USB24A module from Excel

All components are installed, you can take it directly for Excel. We start the program. We need to enable the execution of Excel macros as the next step, because they are most likely disabled by default. To do this, go to the menu Tools -> Macro -> Security...

Controlling the Ke-USB24A module from Excel

Set the low security option - because we are sure that our own program is safe.

Controlling the Ke-USB24A module from Excel

Now let's decide what we actually want to get from Excel: Let the sheet contain controls that will allow us to open access to the device and write a low or high voltage level to the I / O line we specified.

Let's move on to setting up the controls. To do this, call the appropriate window, for example, by right-clicking on the main menu of the program and selecting "Controls" in the list that appears.

Controlling the Ke-USB24A module from Excel

We drag the necessary controls onto the sheet: three labels, three input boxes and two buttons. You can change the text of elements by clicking the right mouse button in the element properties editor. The result should look like this:

Controlling the Ke-USB24A module from Excel

Now it's time to get down to programming. The Excel program, as well as other office programs from Microsoft (for example, Word, Acsess, etc.) have built-in support for the VBA (Visual Basic For Application) programming language. It is a somewhat extended Visual Basic. To go to the program editor, double-click on the Open Port button, because it will start the program execution process from it.

We get into the VBA editor, where we see an empty code blank for handling the button click event.

Controlling the Ke-USB24A module from Excel

Before we start writing the program directly, we need to connect the MSComm component (the one that we just installed in the system a little higher). To do this, in the VBA editor in the menu, select Tools -> References....

Controlling the Ke-USB24A module from Excel

Push the button Browse .... In the file selection window that appears, find our component MSCOMM32.OCX - it must be in the directory C: \ Windows \ system32 \... Push Open, then the button Ok.

Controlling the Ke-USB24A module from Excel

We write the following code. What is he doing? We create an instance of the component to work with the port, configure its parameters, and finally open the port.

'Create an instance of the component to work with the port
Dim KeUSB As New MSCommPrivate Sub CommandButton1_Click()
'Configure the port
KeUSB.CommPort = Val(TextBox1.Value)
KeUSB.Settings=9600,N,8,1"
KeUSB.Handshaking = comNone
KeUSB.InputLen = 0
KeUSB.InBufferSize = 40
KeUSB.OutBufferSize = 40
KeUSB.RThreshold = 0
'Open the port
KeUSB.PortOpen = True
End Sub
 

Next, we return to the Excel sheet. Double click on the button Write down. Add the following code:

Private Sub CommandButton2_Click ()
'Form the command $KE,WR
KeUSB.Output =$KE,WR," & TextBox2.Value &," & TextBox3.Value & Chr(13) & Chr(10)
End Sub

All done with programming. You can close the VBA editor (do not forget to save before exiting). Now we need to switch from control editor mode to run mode on the Excel sheet. To do this, on the "Controls" horse, you must press the corresponding button in the form of a triangle bar so that it becomes inactive (not highlighted).

Controlling the Ke-USB24A module from Excel

Now you can assemble the circuit - I don’t change anything here, I use it as in the last article: LEDs are connected to all input / output lines of the Ke-USB24A module. All lines are set to output. That's actually the whole circuitry.

Controlling the Ke-USB24A module from Excel. Scheme

So, we indicate the number of the COM port of the module, press the button open port. Then, specify the number of the desired line and the value for the record (0 or 1). We press the button Write down - Blink LEDs.

Controlling the Ke-USB24A module from Excel

And here is a photo of the structure. The circuit is typed on a breadboard - very convenient, you do not need to solder anything. Not all 24 LEDs are installed here, but less.

Controlling the Ke-USB24A module from Excel. Assembled circuit on breadboard

So, we indicate the number of the COM port of the module, press the button open port. Then, specify the number of the desired line and the value for the record (0 or 1). We press the button Write down - Blink LEDs.

Of course, the program needs to be modernized - here we do not analyze either execution errors or the entered data itself. However, despite the simplicity, this example shows that you can work with the Ke-USB24A module from almost any environment that supports ActiveX components and at least some programming language (even scripting). For example, work with the module can be integrated into the Microsoft Acsess program and maintain a database, you can integrate this concept into the 1C program, for example, and perform any actions on external events from sensors (keys), etc. - the possibilities are endless. And you can continue to develop the topic with Excel - for example, use it to automatically plot graphs according to the data received from the module's ADC.

Author: Dmitry Ivanov (Grirog); Publication: cxem.net

See other articles Section Computers.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Artificial leather for touch emulation 15.04.2024

In a modern technology world where distance is becoming increasingly commonplace, maintaining connection and a sense of closeness is important. Recent developments in artificial skin by German scientists from Saarland University represent a new era in virtual interactions. German researchers from Saarland University have developed ultra-thin films that can transmit the sensation of touch over a distance. This cutting-edge technology provides new opportunities for virtual communication, especially for those who find themselves far from their loved ones. The ultra-thin films developed by the researchers, just 50 micrometers thick, can be integrated into textiles and worn like a second skin. These films act as sensors that recognize tactile signals from mom or dad, and as actuators that transmit these movements to the baby. Parents' touch to the fabric activates sensors that react to pressure and deform the ultra-thin film. This ... >>

Petgugu Global cat litter 15.04.2024

Taking care of pets can often be a challenge, especially when it comes to keeping your home clean. A new interesting solution from the Petgugu Global startup has been presented, which will make life easier for cat owners and help them keep their home perfectly clean and tidy. Startup Petgugu Global has unveiled a unique cat toilet that can automatically flush feces, keeping your home clean and fresh. This innovative device is equipped with various smart sensors that monitor your pet's toilet activity and activate to automatically clean after use. The device connects to the sewer system and ensures efficient waste removal without the need for intervention from the owner. Additionally, the toilet has a large flushable storage capacity, making it ideal for multi-cat households. The Petgugu cat litter bowl is designed for use with water-soluble litters and offers a range of additional ... >>

The attractiveness of caring men 14.04.2024

The stereotype that women prefer "bad boys" has long been widespread. However, recent research conducted by British scientists from Monash University offers a new perspective on this issue. They looked at how women responded to men's emotional responsibility and willingness to help others. The study's findings could change our understanding of what makes men attractive to women. A study conducted by scientists from Monash University leads to new findings about men's attractiveness to women. In the experiment, women were shown photographs of men with brief stories about their behavior in various situations, including their reaction to an encounter with a homeless person. Some of the men ignored the homeless man, while others helped him, such as buying him food. A study found that men who showed empathy and kindness were more attractive to women compared to men who showed empathy and kindness. ... >>

Random news from the Archive

Disposable digital camera 20.10.2003

Cheap disposable film cameras have become a common commodity for those who shoot one film a year - on vacation.

And now the American company "Ritz" has launched disposable digital cameras on the market. The 11-megapixel Dakota Digital camera costs only $200 and produces photos of the same quality as similar "reusable" cameras costing at least $XNUMX. True, it has neither an electronic display nor a jack for connecting to a computer, so it is impossible either to view the pictures taken on the camera itself or to transfer them to the computer's hard drive on your own. But there is a flash and self-timer.

In total, 25 photos fit in the camera's memory. You can erase the last shot if you think it will fail. After the memory is full, the camera is taken to a photo center, where for another $ 11 they make 25 prints 10 by 15 in size, an overview print of all 25 frames on one sheet and give a CD with recorded images for viewing on a computer and self-printing on a home printer.

The manufacturer claims that it is possible to print images up to 18 by 24 centimeters in size with decent quality. For comparison, a disposable film camera costs about $8 in the US, and a printout from film of 25 frames with an overview print and burning to a CD costs $14.

The used camera is returned to the company, the memory is cleared in it and the battery is replaced, after which the device goes on sale again.

Other interesting news:

▪ Samsung PRO Plus and EVO Plus Memory Cards

▪ Pedestrians are safer with robot cars

▪ solar wind magnetometer

▪ Honda hearing robot

▪ Depression and anxiety change brain volume

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ site section Electrician's tool. Article selection

▪ article The concept of drifting continents. History and essence of scientific discovery

▪ article What unique abilities did the prototype of the protagonist of the movie Rain Man have? Detailed answer

▪ article Head of the retail network. Job description

▪ article Voltage indicator with sound indication. Encyclopedia of radio electronics and electrical engineering

▪ article Remote control systems for locking/unlocking doors. Encyclopedia of radio electronics and electrical engineering

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024