Our utility program QWRS232 has the ability to connect to an RS232 enabled device and collect the data into a Quality Window application. But what if you have more than one device that you would like to collect data from? The only practical way of doing this is through scripting. When a user presses the Add button, a scripting hook called QW_BeforeDisplay is called and you can do whatever you like in this routine to collect data prior to the Add screen being displayed.
One of the many functions available through QWTool.dll is the ability to display a small Menu screen to guide an operator on what to do next. In the following example, we will assume that a weight scale is connected to the computer via COM5 and a Torque tester is connected via COM4. A small menu will be displayed prompting the operator to either collect weights, to collect torques, or to exit and return to the Add screen.
You can start by copy and pasting the following script code into a file that has the same name as your Quality Window application but with a file extension of .QWX (ie Monitor.qwx)
Function QW_BeforeDisplay(QWFunction) Select Case QWFunction Case "A" Dim oMenu Set oMenu = CreateObject("QWTool.Menu") oMenu.Caption = "Select a Function" oMenu.AddItem "1. Get Scale Values" oMenu.AddItem "2. Get Torque Values" oMenu.AddItem "3. Exit" Do oMenu.Display Select Case oMenu.Selection Case 1 : GetWeights Case 2 : GetTorques End Select Loop Until (oMenu.Selection = 0) Or (oMenu.Selection = 3) End Select End Function
Sub GetWeights Dim oRS232, I, BegVariable, EndVariable Set oRS232 = CreateObject("QWtool.RS232") BegVariable = 3 EndVariable = 5 With oRS232 .Device = "Ohaus Navigator" .Port = 5 .PortSettings = "2400,N,7,2" .Timeout = 0.2 .InitString = "" .SendString = "SA$0D" .ResetString = "" .AutoSend = False .AutoAccept = True .MinSamples = 0 .MaxSamples = EndVariable-BegVariable+1 .DebugWindow = True .Fields.Add "Weight", "N", "", 0, 4, 6, True .Notes = "Place one object on the scale.|" & _ "Wait for scale to settle.|" & _ "Remove object.|Replace with next object." .Display If .Cancel = False Then For I = 1 To .MaxSamples QWFile.Value(BegVariable+I-1) = .Value(I,1) Next End If End With Set oRS232 = Nothing End Sub
Sub GetTorques Dim oRS232, I, BegVariable, EndVariable Set oRS232 = CreateObject("QWtool.RS232") BegVariable = 13 EndVariable = 15 With oRS232 .Device = "Imada Torque" .Port = 4 .PortSettings = "2400,N,7,1" .Timeout = 0.2 .InitString = "" .SendString = "P$0D$0A" .ResetString = "" .AutoSend = False .AutoAccept = True .MinSamples = 0 .MaxSamples = EndVariable-BegVariable+1 .DebugWindow = True .Fields.Add "Torque", "N", "", 0, 1, 5, True .Notes = "Place one object on the tester.|" & _ "Wait for tester to settle.|" & _ "Remove object.|Replace with next object." .Display If .Cancel = False Then For I = 1 To .MaxSamples QWFile.Value(BegVariable+I-1) = .Value(I,1) Next End If End With Set oRS232 = Nothing End Sub
Now let’s take a closer look at the GetWeights routine, and please note that for your device, most likely some of the options and parameters will need to be changed as most devices have different communication settings. The BegVariable = 3 and EndVariable = 5 statements are telling the script that variables 3, 4 and 5 will be used to store the weights in the QW application – you can change these to reflect your own variables as well as the total number of samples. Note that the variables must be consecutive in the QW application.
You will also need to adjust some of the other properties:
Device – Just an arbitrary name given to the device
Port – The COM port that the device is connected to your computer on
PortSettings – BaudRate,Parity,DataBits,StopBits (see device manual for this setting)
Timeout – The length of time in seconds to wait for end of stream traffic (0.2 is usually sufficient)
InitString – The command sequence to send to the device on initialization (usually blank)
SendString – The command to send to the device when the SpaceBar is pressed (see device manual)
ResetString – The command to send to the device on exit (usually blank)
AutoSend – If True will automatically transmit the SendString prior to reading the port
AutoAccept – If True will automatically accept the returned value (no need to manually accept)
MinSamples – The minimum number of samples to collect before allowing an exit
MaxSamples – The maximum number of samples to collect (script sets this for you)
DebugWindow – If True will display the device traffic in a box
Fields.Add – Name,Type(N/T),FindString,Occurrence,StartPosition,Length,Required
Notes – Operator instructions. Use ‘|’ to separate into lines
You will note that the GetTorque routine is very similar to the GetWeights routine. You simply need to adjust the properties to match the specifications of your device. Using the above script, it would be fairly easy to modify it so that you could connect to more than just 2 devices.
Tip: Make use of the Debug Window in QWRS232Admin to determine what the StartPosition and Length parameters should be set to. Setting them incorrectly may cause the collected values to be truncated.
If you have any questions, please contact us at firstname.lastname@example.org