![]() ![]() 1, 2, 3, 4 for COM1 - COM4 Dim lngStatus As Long intPortID = 1 ' Open COM port lngStatus = CommOpen(intPortID, 'COM' & CStr(intPortID)'baud=9600 parity=N data=8 stop=1') End Sub It opens COM1, at a baud rate of 9600, no parity, 8 data bits and one stop bit. The code for realizing this is: Private Sub CommandButton1Click Dim intPortID As Integer ' Ex. For this, we will be using the CommOpen function, defined above, which takes as parameters the ID of the COM port you want to open (COM1, COM2 etc) and a few strings that define the baud rate, the parity and the number of data and stop bits. In order to do this, click on the first button you created, and from the pop-up menu, choose the View Code option: This will open again the scripting environment, adding a new function to the code it will mark the beginning of the function: Private Sub CommandButton1Click End Sub This is the place where you will write the code to initialize the serial port. Now it is time to start adding code to your buttons. This will change the label on the first button to this very text: Once you do this for the first button, repeat the operation and change the labels on the other three buttons to “Write”, “Read” and “Close”. Click on the Command Button control from the recently activated toolbar, and then draw 4 similar buttons anywhere on the surface of your excel worksheet (it will be a challenge to draw them all of the same size!). In order to do all these, you will need to create four windows-style buttons, each of them performing one of the tasks that I have enumerated before. As a goal for this article, I would intend to demonstrate how you open the serial port, how you write a few bytes, how you read some bytes, and then how you close the serial port. This will, in turn, make available a number of new other buttons that will allow you to build the mentioned controls. ![]() In order to make these available on the main toolbar, you need to activate the Control Toolbox button, from the small toolbar activated at the previous step. These buttons will enable you to launch the editor in which you will be able to write the Visual Basic Code and will also allow you to directly create windows-style controls like textboxes, push buttons, labels, radio buttons, checkboxes etc. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |