ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING Controlling the Ke-USB24A module from Excel. Encyclopedia of radio electronics and electrical engineering Encyclopedia of radio electronics and electrical engineering / Computers 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. 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: Click Yes. A successful installation message will appear. We press "Ok". 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... Set the low security option - because we are sure that our own program is safe. 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. 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: 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. 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.... 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. 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
Next, we return to the Excel sheet. Double click on the button Write down. Add the following code: Private Sub CommandButton2_Click ()
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). 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. 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. 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. 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. Latest news of science and technology, new electronics: Artificial leather for touch emulation
15.04.2024 Petgugu Global cat litter
15.04.2024 The attractiveness of caring men
14.04.2024
Other interesting news: ▪ Samsung PRO Plus and EVO Plus Memory Cards ▪ Pedestrians are safer with robot cars ▪ 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 Head of the retail network. Job description
Leave your comment on this article: All languages of this page Home page | Library | Articles | Website map | Site Reviews www.diagram.com.ua |