data matrix vb.net USING VISUAL BASIC TO PROGRAM THE RCX in Software

Creation Data Matrix 2d barcode in Software USING VISUAL BASIC TO PROGRAM THE RCX

USING VISUAL BASIC TO PROGRAM THE RCX
Data Matrix ECC200 Reader In None
Using Barcode Control SDK for Software Control to generate, create, read, scan barcode image in Software applications.
Generate Data Matrix In None
Using Barcode generator for Software Control to generate, create Data Matrix image in Software applications.
7. Change the name of the Spirit Control you ve added to PBrickCtrl. (This step is optional;
DataMatrix Scanner In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
Data Matrix ECC200 Generator In Visual C#
Using Barcode maker for VS .NET Control to generate, create Data Matrix ECC200 image in VS .NET applications.
however, it conveniently conforms to the examples provided in the PBrick documentation provided by LEGO.) 8. Click on any blank area of the form, and change the name of the form (in the Properties box) to RCXFrm. While you can choose any name for the form, the sample programs that follow later in this chapter use the name RCXFrm to reference the PBrickCtrl control. Adding the Spirit Control (spirit.ocx) component to the form allows you to write VB code so as to interface with the RCX. You are now ready to begin programming:
DataMatrix Generation In VS .NET
Using Barcode encoder for ASP.NET Control to generate, create Data Matrix ECC200 image in ASP.NET applications.
DataMatrix Encoder In .NET Framework
Using Barcode generator for .NET Control to generate, create Data Matrix image in .NET framework applications.
1. Create a new code module by choosing Insert, Module. 2. Type the BasicTest code shown below. Be on the lookout for typographical errors.
Data Matrix 2d Barcode Printer In Visual Basic .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create DataMatrix image in VS .NET applications.
Code-128 Generator In None
Using Barcode generator for Software Control to generate, create ANSI/AIM Code 128 image in Software applications.
Sub BasicTest() RCXFrm.PBrickCtrl.InitComm RCXFrm.PBrickCtrl.PlaySystemSound (2) End Sub
European Article Number 13 Encoder In None
Using Barcode maker for Software Control to generate, create EAN13 image in Software applications.
Printing Barcode In None
Using Barcode encoder for Software Control to generate, create barcode image in Software applications.
3. Verify that your RCX is on and that it is positioned no more than about a foot from the
UPC Symbol Creator In None
Using Barcode maker for Software Control to generate, create GTIN - 12 image in Software applications.
Paint Bar Code In None
Using Barcode drawer for Software Control to generate, create bar code image in Software applications.
infrared tower.
Create International Standard Serial Number In None
Using Barcode encoder for Software Control to generate, create ISSN - 13 image in Software applications.
Encoding USS Code 39 In None
Using Barcode printer for Online Control to generate, create Code 3/9 image in Online applications.
4. In VB/VBA, run the BasicText program (choose Run, Run Sub, or press F5). (Note: you
Generate Bar Code In .NET
Using Barcode maker for .NET Control to generate, create bar code image in VS .NET applications.
UPC-A Creation In Visual C#.NET
Using Barcode maker for .NET Control to generate, create UPC-A image in .NET framework applications.
do not need to depress the Run button on the RCX in order to execute the BasicTest code.) If all is working properly, the RCX should emit a short tone. If you get an error or the tone doesn t sound, recheck that the RCX is operating properly. Verify that the IR tower is functioning by verifying that the dim green light is on when the BasicTest program is being downloaded. This light will extinguish a few seconds after downloading is complete.
EAN 128 Generation In Objective-C
Using Barcode generator for iPhone Control to generate, create GTIN - 128 image in iPhone applications.
Code-39 Creation In .NET
Using Barcode creation for ASP.NET Control to generate, create ANSI/AIM Code 39 image in ASP.NET applications.
PROGRAMMING MOTOR ACTIONS
EAN13 Encoder In None
Using Barcode creator for Online Control to generate, create GS1 - 13 image in Online applications.
Create Barcode In VS .NET
Using Barcode generation for Reporting Service Control to generate, create bar code image in Reporting Service applications.
Sounding tones is hardly the life s work of the LEGO RCX unit, so let s try some more advanced programming techniques, including running two motors. For the following test, we ll assume that your RCX robot has two motors, attached to outputs A and C. Type the following
FIGURE 14.1 The test form in Visual Basic, with the spirit.ocx control added.
176 PROGRAMMING THE LEGO MINDSTORMS RCX
code, either in the same module in which you created BasicTest earlier or in a new module. Again, be watchful for typographical errors. We ll discuss what the code does in a bit.
Listing 14.1
Option Explicit
Testmotors
Public Const SWEEP_DOWN_SOUND = 2 Public Const SWEEP_UP_SOUND = 3 Public Const SWEEP_FAST_SOUND = 5 Sub TestMotors() With RCXFrm.PBrickCtrl .InitComm .SelectPrgm 0 .BeginOfTask 0 .Wait 2, 30 .SetPower "02", 2, 7 .SetFwd "02" .On "02" .Wait 2, 50 .SetRwd "02" .Wait 2, 50 .Off "02" .PlaySystemSound SWEEP_FAST_SOUND .EndOfTask End With MsgBox "Download complete" End Sub
Running the TestMotors program
When you are done typing, run the TestMotors program in VB/VBA. A message box appears when downloading is complete. For this test, you must select program 1 on the RCX, using the Pgm button. Press Run when you re ready to run the program. The RCX should spin its motors forward and reverse for a short burst each way. When done, the RCX will emit its up-sweep tone to tell you it s finished. The TestMotors program is actually straightforward. You may want to increase your understanding of what the program does by reviewing the PBrick documentation (described earlier in this chapter) from LEGO. Here is the first line of the program:
With RCXFrm.PBrickCtrl
Examining the TestMotors program
The With statement is a standard VB/VBA command. It allows you to reference an object in this case, RCXFrm.PBrickCtrl using a shorthand syntax. Refer to the VB/VBA documentation for additional information on using With. All of the statements that follow, except for MsgBox, are commands built into the spirit.ocx component:
.InitComm
.InitComm (note the period prefix) sets up communications between the IR tower and the RCX. You must always include this statement before sending other commands to the RCX.
.SelectPrgm 0 .BeginOfTask 0
USING VISUAL BASIC TO PROGRAM THE RCX
The .SelectPrgm 0 statement selects program 1 in the RCX (e.g., press the Pgm button until program 1 appears in the RCX s LCD display). Much of the programming with spirit.ocx involves zero-based values, so SelectPrgm 0 is program 1, SelectPrgm 1 is program 2, and so forth. Recall that you can store up to five programs in the RCX at any one time. As a point of reference, the 0 after the .SelectPrgm statement is known as a parameter. Many of the statements used to program the RCX with the spirit.ocx component require that you use of one or more parameters. The .BeginOfTask 0 statement tells the RCX that the code that follows is its main task. This functionality will occur when you press the Run button on the RCX. Each program can have up to 10 tasks. The RCX is designed to run each task simultaneously, which allows your programs to be multithreaded. For example, you might have your RCX play a tune while driving a zigzag course. Each of these actions is contained in its own task in one program.
.Wait 2, 30
The .Wait statement tells the RCX to wait a brief period of time. Wait uses two parameters: the 2 tells the RCX that the parameter that follows is a literal constant . The 30 indicates 30/100s of a second, or about a third of a second. Other Wait statements in the remainder of the program perform a similar function.
.SetPower "02", 2, 7 .SetFwd "02" .On "02"
These three statements set up the drive motors and turn them on. .SetPower sets the power to motors 0 and 2 (labeled A and C on the RCX) to full. The 2 indicates a literal constant, and the 7 indicates the value (1 is slow, 7 is fast, and there are several speeds in between). Similarly, .SetFwd sets the direction of motors 0 and 2, and .On turns them on.
.SetRwd "02"
Copyright © OnBarcode.com . All rights reserved.