Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / Visual Basic

Serial Foot Pedal Device Server

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
7 Mar 2010CPOL3 min read 50.7K   1K   8   20
A control library to control signals from a serial port foot pedal device
testapp.JPG

Introduction

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.

foodpedal.jpg

Background

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:

VB.NET
Footpedal1.OpenPort("COM1") 'open port

To close the port:

VB.NET
Footpedal1.ClosePort() 'close 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:

VB.NET
Footpedal1.OpenPort("COM1")
If FootPedal1.LastErrorMessage<>"" Then
  MsgBox (FootPedal1.LastErrorMessage)
End If

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:

VB.NET
Private Sub FootPedal1_CentralPedal_
    (ByVal Status As FootPedalControl.FootPedal.PedalStatus) Handles FP.CentralPedal
   If Status = FootPedalControl.FootPedal.PedalStatus.Down Then
  'Code to play the audio
   ElseIf Status = FootPedalControl.FootPedal.PedalStatus.Up Then
   'Code to pause the audio
End If
End Sub

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 SerialPinChangedEventArgs object e has the property named EventType which holds values like CDChanged, DsrChanged, and CtsChanged. SerialPort control also has properties like CDHolding, CtsHolding, and 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.

History

  • 7th March, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
Nejimon CR started coding in early 2000s with classic Visual Basic 6 and later moved to .NET platform. His primary technology stack expertise is around Microsoft technologies, but with the previous and latest areas of functioning to include a wide variety of technologies such as Win32 APIs, AutoIt scripting, UI Automation, ASP.NET MVC and Web API, Node.js, NoSQL, Linq, Entity Framework, AngularJS, etc.

His Articles on CodeProject:
http://www.codeproject.com/Articles/1060520/Centralizing-WCF-Client-Configuration-in-a-Class-L
http://www.codeproject.com/Articles/567356/Asynchronous-Access-of-Web-Service-from-WPF-with-B
http://www.codeproject.com/Articles/63849/Serial-Foot-Pedal-Device-Server
http://www.codeproject.com/Tips/149249/Simplest-way-to-implement-irregular-forms-in-NET
http://www.codeproject.com/Tips/564388/Entity-Framework-Code-First-Navigation-Property-is

Comments and Discussions

 
QuestionProblem Detecting Button Pressed with Pinchanged Event Pin
Member 1045965813-Mar-14 4:08
professionalMember 1045965813-Mar-14 4:08 
AnswerRe: Problem Detecting Button Pressed with Pinchanged Event Pin
Nejimon CR13-Mar-14 6:20
Nejimon CR13-Mar-14 6:20 
GeneralRe: Problem Detecting Button Pressed with Pinchanged Event Pin
Member 1045965813-Mar-14 20:11
professionalMember 1045965813-Mar-14 20:11 
QuestionCan the foot pedal be integrated to with dew player through ASP.Net application? Pin
Member 1030669530-Sep-13 19:17
professionalMember 1030669530-Sep-13 19:17 
AnswerRe: Can the foot pedal be integrated to with dew player through ASP.Net application? Pin
Nejimon CR1-Oct-13 5:58
Nejimon CR1-Oct-13 5:58 
GeneralRe: Can the foot pedal be integrated to with dew player through ASP.Net application? Pin
Member 103066951-Oct-13 20:08
professionalMember 103066951-Oct-13 20:08 
GeneralRe: Can the foot pedal be integrated to with dew player through ASP.Net application? Pin
Nejimon CR1-Oct-13 22:35
Nejimon CR1-Oct-13 22:35 
Questioni haven't got COM1 Pin
serkan_serkan7-May-13 22:16
serkan_serkan7-May-13 22:16 
AnswerRe: i haven't got COM1 Pin
Nejimon CR18-Jul-13 15:09
Nejimon CR18-Jul-13 15:09 
QuestionCode in C # Pin
jaipe16-Jul-12 0:41
jaipe16-Jul-12 0:41 
AnswerRe: Code in C # Pin
Nejimon CR17-Nov-12 17:50
Nejimon CR17-Nov-12 17:50 
QuestionCan the foot pedal be integrated to work with a flash player Pin
nvinodh22-Jun-11 4:01
nvinodh22-Jun-11 4:01 
AnswerRe: Can the foot pedal be integrated to work with a flash player Pin
Nejimon CR24-Jun-11 20:44
Nejimon CR24-Jun-11 20:44 
GeneralRe: Can the foot pedal be integrated to work with a flash player Pin
nvinodh24-Jun-11 23:56
nvinodh24-Jun-11 23:56 
QuestionWhen it's on its on? Pin
H. Pearl26-Jan-11 4:38
H. Pearl26-Jan-11 4:38 
Nejimon, Regarding your comments on the Multiple execution of PinChanged Event of SerialPort, if the event is raised and the program is process for that raised event; wouldn't the program process for that event until another (differnet) event is raised? Thereby ignoring any Multiple "pinchange" for the current event?
AnswerRe: When it's on its on? Pin
Nejimon CR27-Jan-11 2:53
Nejimon CR27-Jan-11 2:53 
QuestionUSB Foot Pedal Pin
madhurigjoshi5-Oct-10 20:29
madhurigjoshi5-Oct-10 20:29 
AnswerRe: USB Foot Pedal Pin
Nejimon CR21-Jan-11 3:47
Nejimon CR21-Jan-11 3:47 
Generaldebouncing Pin
Luc Pattyn9-May-10 1:47
sitebuilderLuc Pattyn9-May-10 1:47 
GeneralRe: debouncing Pin
Nejimon CR21-Jan-11 3:44
Nejimon CR21-Jan-11 3:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.