A serial foot pedal is a device which has three mechanical switches for play, rewind, and fast forward. People like medical transcriptionists use these devices for playing audio while they keep their hands busy on the keyboard. Any programmer who is developing solutions for such a firm should be able to find a software interface to incorporate the foot pedal device into the application.
Months ago, I was assigned a project for a medical transcription company of making a piece of software for handling their daily transcription workflow. They had existing applications for other accounts that used a serial foot pedal to play the audio. They wanted the new software to have the same feature, demanding me to find my own way to connect my VB.NET application to the foot pedal via the serial port. This .NET component was written as a result. I found out that a lot of programmers are in search of such a component for their projects, so I decided to share my code here. Any curses or praises are welcome.
Using the Code
Serial foot pedal device uses modem signals to tell the system to play, rewind, and fast-forward. These signals are DSR (Data Set Read, used for play function here), CTS (Clear to Send, fast-forward here), and CD (Carrier Holding, used for rewinding in my code).
The component uses SerialPort control shipped with .NET 2.0. There are 6 timers to monitor the current pin state of the 3 pins, 2 timers for each state, namely up and down.
After downloading the DLL, place the control from the toolbox in Visual Studio 2005/2008.
To open the port, use the code:
To close the port:
Sometimes, the serial port may already be in use by another program. You can check the error string returned by
LastErrorMessage property of the control immediately after opening the port, like:
If FootPedal1.LastErrorMessage<>"" Then
Every time user presses a pedal switch on the foot pedal device, the corresponding event is raised. You can place the code for playing, rewinding, and fast-forwarding in these event handlers, like:
Private Sub FootPedal1_CentralPedal_
(ByVal Status As FootPedalControl.FootPedal.PedalStatus) Handles FP.CentralPedal
If Status = FootPedalControl.FootPedal.PedalStatus.Down Then
ElseIf Status = FootPedalControl.FootPedal.PedalStatus.Up Then
I have also included a test application which changes the color of three picture boxes according to the current up/down state of foot pedal switches.
The control may be useful in other kinds of applications too such as a game application where a foot pedal is used as a control device.
Points of Interest
When I started coding, I first thought of using
PinChanged event of SerialPort control. The
e has the property named
EventType which holds values like
CtsChanged. SerialPort control also has properties like
DsrHolding which can be used to find out the current state of these 3 pins. By examining these properties, the current state of the respective pin can be determined.
For example, if the central pedal is depressed, the
DsrHolding property would be set, and so on.
I played around with these properties and the
EventType for some time, but here I was stopped by a roadblock. For each press of 1 of the pedals, the
PinChanged event fired multiple times, sometimes 2, sometimes 3, whereas only one was desired. Then I Googled a bit about this issue, and bumped into this link:
The forum does not give a solution for this, so I recognized that I must not rely on the
PinChanged event for my particular application, so I decided to place some timers on my control designer to monitor the state of these 3 pins, which fortunately worked perfectly.
- 7th March, 2010: Initial post