omron — 3-1-13 Database Access

Coffee Machine scenario SECTION 3 Advanced Tutorial You should now have a template Access database (or other) to use. The next step is to add the database connections in the Developer. 1, 2, 3… 1. Open CX-Supervisor Developer and load the project. 2. Open the Workspace and switch to the Database tab 3. Right click and add a new connection called Connection1 and specify the new template file C:\Coffee\coffee.mdb as the Data Source. 4. Right click the Connection and select Connect. The icon will change to indicate the connection is live. 5. Add a new Recordset for adding records, called Recordset1 to the connection and ensure Ingredients is selected as the table name for the Source.

To allow writing to the database make sure Pessimistic (or Optimistic ) lock is selected. 6. Add a Field called selection linked to point selection_made and Field Selection . Change the Field Property to Add . 7. Repeat to add coffee linked to point coffee_amount and Field coffee with the Field Property Add and repeat for milk , sugar , tea , and water . 8. Add a new Recordset for reading records, called Recordset2 to the connection and ensure Ingredients is selected as the table name for the Source. 9. Copy each field from Recordset1 and Paste to Recordset2. Change all the Field Properties from Add to Value .

With the template of the database now defined, it is very to easy write the data to the database. 1, 2, 3… 1. At the Project level, add a subroutine script called WriteToDatabase 2. Add code to write to the database, requery the table so that the latest data can be seen, and navigate back to the original record: DBAddNew( "Connection1.Recordset1" ) DBExecute( "Connection1.Recordset2", "Requery" ) DBMove( "Connection1.Recordset2", "Position", record_index) Written database records can now be viewed: 3. Add script code to Make the Drink script to call the new subroutine 1, 2, 3… 1. At the Project level, add a subroutine script called ReadFromDatabase . 2. Add code to read to the database:

DBRead( "Connection1.Recordset2" ) record_index = DBProperty( "Connection1.Recordset2", "CurrentRecord" ) 3. Make a new page with the following properties Page Title = Database Border Style = THICK Display Mode = POPUP Top = 0 Left = 505 Height = 582 35 Field Name Field Data Type Field Size Sugar Number Integer