Using both Visual Basic and Visual C++ sample code, the following set of applications will demonstrate the implementation and capabilities of the RFTone object and its methods. Both applications will create a multi-note tone file, save the tone file to the RF device, play the tone file, alter the tone file, then delete the tone from the device when the application is finished.
' RFTone Object Demo Application
'
' Import a sleep function from the kernel32 dll
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' Declare an RFIO object for use throughout the
' demo application.
Public rfConsole As New RFIO
' Declare an RFMenu object for use throughout the
' demo application.
Public rfTon As New RFTONE
' strBuffer is a temp storage buffer
Dim strBuffer As String
' bDone is a loop control variable
Dim bDone As Boolean
' nTmp is a temporary integer
Dim nTmp As Integer
' nTmp2 is a temporary integer
Dim nTmp2 As Integer
Dim nLcv as Integer
Public Sub Main()
' This application demonstrates the use of the various RFTone
' methods. It assumes a display area of 20x8. In practice, one
' should use an RFTerminal object to format output to fit the
' current device. The following lines clear the display and output
' the app title in reverse video.
rfConsole.RFPrint 0, 0, " Welcome To The ",
WLCLEAR + WLREVERSE
rfConsole.RFPrint 0, 1, " RFTone Demo! ", WLREVERSE
rfConsole.RFPrint 0, 3, "Hit a key to proceed", WLNORMAL
' Hide the cursor for a cleaner display
rfConsole.RFPrint 0, 9, "", WLNORMAL
'
' Flush the output buffer and await a keystroke/scan
If rfConsole.GetEvent() = "" Then
GoTo ExitApp
End If ' If rfConsole.GetEvent() = ""
' An RF application can respond to user input in three ways: not at
' all, through the display, or through the speaker. Each has its
' benefits and drawbacks. By using the RF device's speaker, an
' application can quickly respond to user input with a simple
' acknowledgement. Tones can also be used to denote error conditions,
' status reports, and application progress.
' This application demonstrates the methods for creating, storing,
' using, & deleting tones from an RF device.
' Add some notes to the rfTone object
For nLcv = 0 To 9
If rfTone.AddTone(440 + (nLcv * 100), 200) = False Then
GoTo ExitApp
End If ' If rfTone.AddTone(440 + (nLcv * 100), 200) = False
Next nLcv ' For nLcv = 0 To 9
' Store the tone object on the RF device under "ToneDemo"
If rfTone.StoreTone("ToneDemo") = False Then
GoTo ExitApp
End If ' If rfTone.StoreTone("ToneDemo") = False
' Play the tone. One might create various tones for data
' validation, etc.
If rfTone.PlayTone("ToneDemo") = False Then
If rfTone.RFGetLastError() <> WLNOTINITIALIZED Then
rfTone.DeleteToneFile "ToneDemo"
End If ' If rfTone.RFGetLastError() <> WLNOTINITIALIZED
GoTo ExitApp
End If ' If rfTone.PlayTone("ToneDemo") = False
' To demonstrate some of the other RFTone methods, we will read
' a tone from the RF device,
rfTone.ClearToness ' Gives us a fresh object to work with
If rfTone.GetToneFile("ToneDemo") < 0 Then
If rfTone.RFGetLastError() <> WLNOTINITIALIZED Then
rfTone.DeleteToneFile "ToneDemo"
End If ' If rfTone.RFGetLastError() <> WLNOTINITIALIZED
GoTo ExitApp
End If ' If rfTone.GetToneFile("ToneDemo") < 0
' double the duration of each individual note,
nTmp = rfTone.ToneCount() ' Store the number of notes
' in a temp variable
For nLcv = 0 To nTmp - 1
nTmp2 = rfTone.GetDuration(nLcv) * 2
If nTmp2 < 0 Then
GoTo ExitApp
End If ' If nTmp2 < 0
If rfTone.SetDuration(nTmp2, nLcv) = False Then
GoTo ExitApp
End If ' If rfTone.SetDuration(nTmp2, nLcv) = False
Next nLcv
' store the new tone on the RF device over the old,
If rfTone.StoreTone("ToneDemo") = False Then
If rfTone.RFGetLastError() <> WLNOTINITIALIZED Then
rfTone.DeleteToneFile "ToneDemo"
End If ' If rfTone.RFGetLastError() <> WLNOTINITIALIZED
GoTo ExitApp
End If ' If rfTone.StoreTone("ToneDemo") = False
' and play it.
If rfTone.PlayTone("ToneDemo") = False Then
If rfTone.RFGetLastError() <> WLNOTINITIALIZED Then
rfTone.DeleteToneFile "ToneDemo"
End If ' If rfTone.RFGetLastError() <> WLNOTINITIALIZED
GoTo ExitApp
End If ' If rfTone.PlayTone("ToneDemo") = False
' Anytime an application changes the configuration of an RF device,
' it should return it to its original values during cleanup
rfTone.DeleteToneFile "ToneDemo"
ExitApp:
End Sub
//////////////////////////////////////////////////////////
// Place RF application's main code here
IRFIO rfConsole; // Declare an RFIO interface object
IRFTone rfTone; // Declare an RFTone interface object
Cstring csBuffer; // Storage buffer for data strings
Short nTmp; // Temporary short value
// Create an RFIO object in the automated server for our use
if (rfConsole.CreateDispatch ("WAVELINKOLE.RFIO") == FALSE) ¿
return FALSE;
// Create an RFTone object in the automated server for our use
if (rfTone.CreateDispatch ("WAVELINKOLE.RFTONE") == FALSE) ¿
return FALSE;
// This application demonstrates the use of the various RFTone
// methods. It assumes a display area of 20x8. In practice, one
// should use an RFTerminal object to format output to fit the
// current device.
// The following lines clear the display and output the app
// title in reverse video.
rfConsole.RFPrint (0, 0, " Welcome To The ", ¿
WLCLEAR | WLREVERSE);
rfConsole.RFPrint (0, 1, " RFTone Method Demo ", WLREVERSE);
rfConsole.RFPrint (0, 3, "Hit a key to proceed", WLNORMAL);
// Hide the cursor for a cleaner display
rfConsole.RFPrint (0, 9, "", WLNORMAL);
// Flush the output buffer and await a keystroke/scan
if ((rfConsole.GetEvent ()).IsEmpty () == TRUE) {
// Release the RFIO & RFTone objects
rfConsole.ReleaseDispatch ();
rfTone.ReleaseDispatch ();
return FALSE;
} // if ((rfConsole.GetEvent ()).IsEmpty () == TRUE)
// An RF application can respond to user input in three ways:
// not at all, through the display, or through the speaker. Each
// has its benefits and drawbacks. By using the RF device's
// speaker, an application can quickly respond to user input
// with a simple acknowledgement. Tones can also be used to
// denote error conditions, status reports, and application
// progress.
// This application demonstrates the methods for creating,
// storing, using, & deleting tones from an RF device.
// Add some notes to the rfTone object
for (int nLcv = 0; nLcv < 10; ++nLcv) {
if (rfTone.AddTone (440 + (nLcv * 100), 200) == FALSE) {
// Release the RFIO & RFTone objects
rfConsole.ReleaseDispatch ();
rfTone.ReleaseDispatch ();
return FALSE;
} // if (rfTone.AddTone (440 + (nLcv * 100), 200) == FALSE)
} // for (int nLcv = 0; nLcv < 10; ++nLcv)
// Store the tone object on the RF device under "ToneDemo"
if (rfTone.StoreTone ("ToneDemo") == FALSE) {
// Release the RFIO & RFTone objects
rfConsole.ReleaseDispatch ();
rfTone.ReleaseDispatch ();
return FALSE;
} // if (rfTone.StoreTone ("ToneDemo") == FALSE)
// Play the tone. One might create various tones for data
// validation, etc.
if (rfTone.PlayTone ("ToneDemo") == FALSE) {
if (rfTone.RFRFGetLastError() != WLNOTINITIALIZED)
rfTone.DeleteToneFile ("ToneDemo");
// Release the RFIO & RFTone objects
rfConsole.ReleaseDispatch ();
rfTone.ReleaseDispatch ();
return FALSE;
} // if (rfTone.PlayTone ("ToneDemo") == FALSE)
// To demonstrate some of the other RFTone methods, we will
// read a tone from the RF device
rfTone.ClearToness (); // Gives us a fresh object to work with
if (rfTone.GetToneFile ("ToneDemo") < 0) {
if (rfTone.RFRFGetLastError() != WLNOTINITIALIZED)
rfTone.DeleteToneFile ("ToneDemo");
// Release the RFIO & RFTone objects
rfConsole.ReleaseDispatch ();
rfTone.ReleaseDispatch ();
return FALSE;
} // if (rfTone.GetToneFile ("ToneDemo") < 0)
// double the duration of each individual note,
nTmp = rfTone.ToneCount (); // Store the number of notes
// in a temp variable
for (nLcv = 0; nLcv < nTmp; ++nLcv)
rfTone.SetDuration (rfTone.GetDuration (nLcv) * 2, nLcv);
// store the new tone on the RF device over the old,
if (rfTone.StoreTone ("ToneDemo") == FALSE) {
if (rfTone.RFRFGetLastError() != WLNOTINITIALIZED)
rfTone.DeleteToneFile ("ToneDemo");
// Release the RFIO & RFTone objects
rfConsole.ReleaseDispatch ();
rfTone.ReleaseDispatch ();
return FALSE;
} // if (rfTone.StoreTone ("ToneDemo") == FALSE)
// and play it.
if (rfTone.PlayTone ("ToneDemo") == FALSE) {
if (rfTone.RFRFGetLastError() != WLNOTINITIALIZED)
rfTone.DeleteToneFile ("ToneDemo");
// Release the RFIO & RFTone objects
rfConsole.ReleaseDispatch ();
rfTone.ReleaseDispatch ();
return FALSE;
} // if (rfTone.PlayTone ("ToneDemo") == FALSE)
// Anytime an application changes the configuration of an RF
// device, it should return it to its original values during
// cleanup
rfTone.DeleteToneFile ("ToneDemo");
// Release the RFIO & RFTone objects
rfConsole.ReleaseDispatch ();
rfTone.ReleaseDispatch ();
Was this article useful?
The topic was:
Inaccurate
Incomplete
Not what I expected
Other