Click here to Skip to main content
15,918,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i wish to know whether can i add voice to control the temperature

VB
Imports System.Speech.Synthesis

Public Class Form1
    Dim FromSerialPort_Temp
    Dim Thermistor_Temp(15) As Integer
    Dim Thermistor_R(15) As Integer
    Dim Circuit_Thermistor_R As Double
    Dim Result
    Dim Speaker As New SpeechSynthesizer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '[Timerspeak.Enabled = True
    End Sub
    Private Sub ReadSerialPortForTemp()
        FromSerialPort_Temp = SerialPort1.ReadExisting

        If Len(FromSerialPort_Temp) <> 0 Then
            'if FromSerialPort_Temp NOT equal to blank (power connected).
            TextBoxVoltage.Text = 0.01 * Convert.ToInt16(FromSerialPort_Temp.Substring(2, 3), 16)

            FromSerialPort_Temp = "U1000" 'assign with "U1000" if nothing is read and FromSeriaPort_Temp=blank
        End If

    End Sub
    Private Sub OpenPort1()
        If SerialPort1.IsOpen Then
            SerialPort1.Close()
        End If

        SerialPort1.PortName = "Com14"
        SerialPort1.BaudRate = 9600
        SerialPort1.Parity = System.IO.Ports.Parity.None
        SerialPort1.DataBits = 8
        SerialPort1.StopBits = System.IO.Ports.StopBits.One

        SerialPort1.RtsEnable = True
        SerialPort1.Open()
    End Sub
    Private Sub ThermistorTable()

        Thermistor_Temp(0) = -10
        Thermistor_R(0) = 42506

        Thermistor_Temp(1) = -5
        Thermistor_R(1) = 33892

        Thermistor_Temp(2) = -0
        Thermistor_R(2) = 27219

        Thermistor_Temp(3) = 5
        Thermistor_R(3) = 22021

        Thermistor_Temp(4) = 10
        Thermistor_R(4) = 17926

        Thermistor_Temp(5) = 15
        Thermistor_R(5) = 14674

        Thermistor_Temp(6) = 20
        Thermistor_R(6) = 12081

        Thermistor_Temp(7) = 25
        Thermistor_R(7) = 10000

        Thermistor_Temp(8) = 30
        Thermistor_R(8) = 8315

        Thermistor_Temp(9) = 35
        Thermistor_R(9) = 6948

        Thermistor_Temp(10) = 40
        Thermistor_R(10) = 5834

        Thermistor_Temp(11) = 45
        Thermistor_R(11) = 4917

        Thermistor_Temp(12) = 50
        Thermistor_R(12) = 4161

        Thermistor_Temp(13) = 55
        Thermistor_R(13) = 3535

        Thermistor_Temp(14) = 60
        Thermistor_R(14) = 3014

        Thermistor_Temp(15) = 1000
        Thermistor_R(15) = 1

        Dim Counter As Integer
        Dim Temperature_low
        Dim Temperature_high
        Dim Resistance_high
        Dim Resistance_low
        Dim Rnum1
        Dim Rnum2

        For Counter = 0 To 15


            If CInt(TextBoxResistance.Text) >= Thermistor_R(Counter) Then

                If Counter <> 0 And Counter <> 15 Then
                    Temperature_high = Thermistor_Temp(Counter)
                    Temperature_low = Thermistor_Temp(Counter - 1)
                    Resistance_low = Thermistor_R(Counter)
                    Resistance_high = Thermistor_R(Counter - 1)
                    Rnum1 = Resistance_high - TextBoxResistance.Text
                    Rnum2 = Resistance_high - Resistance_low
                    Result = 2.5 + Math.Round(Temperature_low + (5 * Rnum1 / Rnum2), 1)
                    TextBoxTemp.Text = Result & "C"


                    Exit For
                End If
                If Counter = 0 Or Counter = 15 Then
                    TextBoxTemp.Text = "Out of Range"
                    Exit For
                End If

            End If
        Next
    End Sub
    Private Sub AcquireTemp()
        Call OpenPort1()

        TextBoxVoltage.Clear()
        TextBoxResistance.Clear()
        TextBoxTemp.Clear()
        SerialPort1.WriteLine("U1" + vbCr)
        System.Threading.Thread.Sleep(150)

        Call ReadSerialPortForTemp()

        If Len(TextBoxVoltage.Text) = 0 Then ' wait for the equipment to be turned on '
        Else
            Circuit_Thermistor_R = 10000 * TextBoxVoltage.Text / (5 - TextBoxVoltage.Text)
            TextBoxResistance.Text = Math.Round(Circuit_Thermistor_R, 0)
            Call ThermistorTable()
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Call AcquireTemp()
    End Sub

    Private Sub BtnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart.Click

        Call ToStartAP()
    End Sub

    Private Sub ToStartAP()
        Dim StartAP() As Byte = {&HFF, &H7, &H3}

        Call OpenPort1()

        SerialPort1.Write(StartAP, 0, StartAP.Length)
        System.Threading.Thread.Sleep(300)
        TextBox1.Text = "AP Started"

    End Sub

    'Private Sub Timerspeak_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timerspeak.Tick
    '    Speak()
    'End Sub

    'Private Sub Speak()
    '    Call ThermistorTable()
    '    If TextBoxTemp.Text > 26 Then
    '        Speaker.Speak(TextBoxTemp.Text)
    '    End If
    'End Sub

End Class
Posted
Updated 25-Oct-10 16:42pm
v2

Yes, you can. How you do that depends entirely on your requirements and what you want to do.
 
Share this answer
 
You might need to add voice recognition to your code[^].
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900