Measurement Computing   Easy to Use | Easy to Integrate | Easy to Support catalog banner

How to write a mixture of global strings and variables to a text...

Expand / Collapse
 

How to write a mixture of global strings and variables to a text file


Minimum Requirements DASYLab 2016 FULL

Sometimes your DASYLab application calls for calculating various values and writing them to file, along with other information, such as serial number, part number, job number, etc. You may be testing parts and want to generate a file where the data appears on one line. Each subsequent test would adds another line to the file. 

If the required data can be stored in global variables (as numbers) then it's easy to retrieve the data using a Read Global Variable module and write it to a file with the Write Data module. However, if the information contains spaces, dashes or underscores, you need to use a global strings instead of variables. The problem then becomes how to get this mixture of variables and string to a file. There is no read global string module and the Action module write string range event puts the variables in a single column of data, which is not desirable. The solution is to use the ODBC module and the Windows Text Driver. The ODBC module can write both global variables and strings to file. 

To begin, create an empty folder to for the data file. Start the Notepad text editor and create a file with your column headers. If using a text (*.txt) file, separate the column headers with a tab character (tab key). A CSV file uses a comma instead of a tab. Create your file and save it to the empty folder.  It's important to note that the folder should contain only the text file. 




Next, launch your Windows Control Panel and locate the Administrative Tools. In the Administrative Tools, launch the ODBC Data Sources (32 bit) tool. Select Add and from the list select Microsoft Text Driver (*.txt, *.csv). This tool creates an entry into the User Data Sources list so give it a name such as TextDriverExample. Uncheck the Use Current Directory and instead browse and select your data file folder. Press the Options button to expand the dialog. 



Press the Define Format... button. From the Tables, select your file and set the format to tab delimited. For Columns, add each one of your global strings and variables. Global Strings are type Char with a length of 255. The Global Variable can be type Float or Integer depending on the measurement. 



Press OK to create the schema.ini file. This is the file that tells the Microsoft Text Driver the file format and it should look like the following.



To demonstrate how the ODBC module can write a data file, this article uses the following DASYLab worksheet. It determines a peak value from a slider control, which is simulating a force sensor. Moving the slider up and down simulates a force that ramps up and down. The worksheet will calculate the peak of this ramp and write it and the other data to the data file (book1.txt). After the Action module will restart the worksheet, which prompts the user to update the global variable and strings (Job Number, Part Number, etc.). Each time it runs, the data is appended to the book1.txt file.

To configure the ODBC module, double click it to show the setup dialog. Select Browse and browse for the Data Source Name and Table file (book1.txt). Because some of the global variables have spaces, select the Use quotes for name in SQL statements. Press the Get Fields button to populate the Field Assignments table. One-by-one select each field and assign a global variable or string. To assign a global variable or string, right-mouse-click the Variable box and from the menu select either Global String or Variable. This completes the ODBC configuration. 

To write the data out, an Action module is use with the event Always. This event fires when data arrives at the input, which is when the peak value is determined.  The Action is Write to database




The complete example, the schema.ini file and the book1.txt file are attached as a download file.








Rate this Article:
Tags:

Attachments


OBDC_Text_DriverEx.zip OBDC_Text_DriverEx.zip (5.47 KB, 415 views)

Add Your Comments


For comments email [email protected].

Details
Article ID: 50794

Last Modified:12/31/2019 10:12:33 AM

Article has been viewed 2,564 times.

Options