1. You can now buy finished microcontroller project from us, Check out the Store for the complete list of projects.
  2. Need a custom project, Send us some details about your project. So that we can quote the price for it.

Nokia N70 Bluetooth Controller Program

Discussion in 'Bluetooth' started by jenelann, Feb 28, 2011.

  1. jenelann

    jenelann New Member

    Likes Received:
    0
    Trophy Points:
    0
    Can anyone help me design a program for a Nokia N70. It will be a bluetooth remote control program. I have designed one in mobilevb but it won't work on my n70. It keeps saying it needs the appforge crossfire installed. but i cant find that software for my n70. Please can someone please help me...
  2. jenelann

    jenelann New Member

    Likes Received:
    0
    Trophy Points:
    0
    Below is my program I designed in MobileVB. If anyone can help fix this program that would be great. If not then can someone please help me design a new one.


    ' Port constants for serial over Bluetooth
    #If APPFORGE Then
    Private Const SerialClient As Long = 1919312749
    ' Private Const SerialServer As Long = 1919312750
    #Else ' Running on the PC
    Private Const SerialClient As Long = 12 ' Your PC's Bluetooth adapter may have different
    ' Private Const SerialServer As Long = 13 ' settings for Bluetooth server and client.
    #End If

    ' Defines the possible states that the bluetooth serial port can be in
    ' Your app may want additional states
    Private Enum ePortState
    NotConnected ' No bluetooth serial ports have been opened.
    ' ServerOpen ' Server serial port is open and listening.
    ConnectedClient ' Client serial port is connected to a server.
    ' ConnectedServer ' Server is connected to a client.
    End Enum

    ' String constants for "special" strings -- codes that
    ' the Chat program sends out for the other chat program.
    Private Const StringConnect As String = "(+)" & vbCrLf ' Must end with a CrLf
    Private Const StringDisconnect As String = "(-)" & vbCrLf ' Must end with a CrLf
    Private Const StringPing As String = "(.)" & vbCrLf ' Must end with a CrLf

    ' Timer constants for the inactivity timer
    Private Const Seconds As Long = 1000
    Private Const Minutes As Long = 60000

    ' Global variables within frmMain
    Private BlueState As ePortState ' See the comments for ePortState.
    Private DeviceUser As String ' Stores the Device Username.
    Private IncomingString As String ' Stores the incoming serial data.
    Private DisplayString As String ' Stores the parts of the incoming data that is ready
    ' to be processed (displayed) when the AFTimer fires.

    Private Sub Form_Load()
    ' Initialize global variables
    BlueState = NotConnected
    DeviceUser = AFSysInfo.DeviceUserName
    IncomingString = ""
    DisplayString = ""

    OpenServer ' This way Bluetooth chat is always ready for a client
    DisplayTimer.Interval = 500 ' Set the interval to 1/2 second
    End Sub

    Private Sub OpenServer()
    If BlueState = NotConnected Then
    On Error GoTo serialerror

    ' Set up the bluetooth serial server port and connect
    'serConnection.CommPort = SerialServer
    'serConnection.InBufferSize = 4096 ' Can be used to alleviate Buffer OverRun
    ' errors. The default is 1024.
    'serConnection.RThreshold = 1 ' We want OnComm to fire at the 1st byte
    'serConnection.PortOpen = True

    ' Erase a previous conversation and disable input in the txtInput box
    txtConversation.Text = ""
    txtInput.Text = ""
    txtInput.Locked = True

    lblStatus.Caption = ""
    mnuConnect.Caption = "Connect"
    'BlueState = ServerOpen
    End If

    Exit Sub
    serialerror:
    ' An error has occurred -- Bluetooth is probably not supported on this device.
    lblStatus.Caption = " Bluetooth Server not available"
    mnuConnect.Enabled = False
    mnuConnect.Visible = False
    End Sub

    Private Sub CloseServer()
    If Not (BlueState = NotConnected) Then
    serConnection.Output = StringDisconnect
    InactivityTimer.Enabled = False
    serConnection.PortOpen = False
    BlueState = NotConnected
    End If
    End Sub

    Private Sub mnuConnect_Click()
    If BlueState = NotConnected Then ' switch to client state
    On Error GoTo serialerror

    ' First close the serverport
    CloseServer

    ' Set up the bluetooth client serial port and connect
    serConnection.CommPort = SerialClient
    'serConnection.InBufferSize = 4096 ' Can be used to alleviate Buffer OverRun
    ' errors. The default is 1024.
    serConnection.RThreshold = 1 ' We want OnComm to fire at the 1st byte
    serConnection.PortOpen = True

    ' Send a special string telling the server that you have connected
    serConnection.Output = StringConnect

    ' Update the status label and menu caption
    lblStatus.Caption = " Connected to Buddy"
    mnuConnect.Caption = "Disconnect"

    ' Enable input in the txtInput box
    txtInput.Locked = False
    txtInput.SetFocus

    ' Start the ping timer
    InactivityTimer.Interval = 30 * Seconds
    InactivityTimer.Enabled = True
    BlueState = ConnectedClient

    Else ' If connected in any way at all...disconnect

    ' Close the port and sends a disconnect string if connected to anyone
    CloseServer

    ' Reopen the server port so that future connections can be made
    OpenServer
    End If

    Exit Sub
    serialerror: ' An error has occurred. Maybe your buddy refused the connection?
    MsgBox "Unable to connect, or connection refused.", vbExclamation
    OpenServer ' Reopen the server port
    End Sub

    Private Sub mnuExit_Click()
    End
    End Sub

    Private Sub mnuSend_Click()
    Dim StringToSend As String

    If BlueState = ConnectedClient Then
    If Len(txtInput.Text) > 0 Then
    ' Reset Ping timer if you are the client
    If BlueState = ConnectedClient Then
    InactivityTimer.Enabled = False
    InactivityTimer.Enabled = True
    End If

    ' Update the conversation box and send the message to your buddy
    StringToSend = "* " & DeviceUser & " says:" & _
    vbCrLf & txtInput.Text & vbCrLf

    UpdateConversationBox StringToSend
    serConnection.Output = StringToSend

    ' Clear the Input TextBox
    txtInput.Text = ""
    End If
    End If
    ' Give focus to the Input TextBox
    txtInput.SetFocus
    End Sub

    Private Sub serConnection_OnComm()
    Dim CrLfIndex As Long

    ' Process the OnComm event
    Select Case serConnection.CommEvent
    '------------------------------------------------------
    ' The following event means that there is data waiting.
    ' This event should not involve heavy processing -- It
    ' should just be used for data collection. We use the
    ' the AFTimer to perform the heavy work when there are
    ' complete lines of text to display. Even though this
    ' is not necessary in a trivial chat application, this
    ' architecture allows the app to process large amounts
    ' of data without overflowing the Input Buffer.
    Case afSerialEventReceive
    ' Temporarily turn off the OnComm Receive event while
    ' we process the current batch of incoming data.
    serConnection.RThreshold = 0

    ' Start the Display Timer, which will update the display
    ' when there is something ready to be displayed. i.e.
    ' we have at least one CrLf in the incoming string.
    DisplayTimer.Enabled = True

    lblStatus.Caption = " Receiving Data..."
    While serConnection.InBufferCount > 0
    ' Read in data...
    IncomingString = IncomingString & serConnection.Input
    ' Look for the last vbCrLf. If found, extract the preceeding string from IncomingString
    CrLfIndex = InStrRev(IncomingString, vbCrLf)
    If CrLfIndex > 0 Then
    ' Update CrLfIndex to point to AFTER the CrLf in msgReceived
    CrLfIndex = CrLfIndex + Len(vbCrLf) - 1
    ' Put everything up to the last vbCrLf in DisplayString and keep
    ' the rest in IncomingString. When the AFTimer fires, DisplayString
    ' will be deplayed in the textbox.
    DisplayString = DisplayString & Left(IncomingString, CrLfIndex)
    IncomingString = Right(IncomingString, Len(IncomingString) - CrLfIndex)
    End If
    ' DoEvents allows other events to fire while this loop is
    ' busy collecting incoming data. Again, this is not
    ' necessary for a Chat application, but it is useful when
    ' your program has a lot of data to process.
    DoEvents
    Wend
    lblStatus.Caption = " Connected to Buddy"

    ' Turn the OnComm Receive event back on again
    serConnection.RThreshold = 1
  3. jenelann

    jenelann New Member

    Likes Received:
    0
    Trophy Points:
    0
    ' -------------------------------------------------
    ' The OnComm event also fires where an error occurs in serial
    ' communications. Below are the possible errors and what they mean.
    Case afSerialEventBreak
    ' The other device sent a break signal. This is supposed to be
    ' done programmatically, and is not some "accident"
    lblStatus.Caption = " Break"
    Case afSerialEventError
    ' This is an unknown error that the AFSerial Ingot did not expect.
    lblStatus.Caption = " Unknown Error"
    Case afSerialEventFrame
    ' Frame errors can occur when the Baud rates of both devices are not
    ' the same. Not applicable to Bluetooth communications.
    lblStatus.Caption = " Frame Error"
    Case afSerialEventOverrun
    ' Overrun Errors indicate that the incoming stream of data is coming
    ' in too fast for your app to process -- thus overflowing the input
    ' buffer. The best solution to this problem is to increase the
    ' .InBufferSize of the Serial Ingot and/or to reduce the Baud rate.
    lblStatus.Caption = " Overrun Error"
    Case afSerialEventParity
    ' Usually happens when there is some kind of interference in the
    ' line of communications.
    lblStatus.Caption = " Parity Error"
    End Select

    End Sub

    Private Sub DisplayTimer_Timer()
    ' More intensive work happens here (displaying to TextBox) so that the
    ' OnComm event can just handle incoming data, thus allowing higher
    ' overall throughput.

    ' Check to see if any of the display data is a special string before displaying it
    ParseSpecialStrings

    ' Server has received data, so you can reset the inactivity timer
    ' If BlueState = ConnectedServer Then
    ' InactivityTimer.Enabled = False
    ' InactivityTimer.Enabled = True
    ' End If

    ' If there is no more new data expected any time soon.
    If Len(IncomingString) = 0 Then DisplayTimer.Enabled = False

    If Len(DisplayString) > 0 Then
    ' Stop the Display Timer (unless there is still more incoming data in IncomingString)
    ' Display the existing text
    UpdateConversationBox DisplayString
    ' Now erase the current Display String
    DisplayString = ""
    End If
    End Sub

    Private Sub InactivityTimer_Timer()
    Select Case BlueState
    'Case ConnectedServer ' Reset the connection
    ' CloseServer
    ' OpenServer

    Case ConnectedClient ' Send a ping
    serConnection.Output = StringPing

    Case Else ' Nobody needs the inactivity timer right now
    InactivityTimer.Enabled = False
    End Select
    End Sub

    Private Sub ParseSpecialStrings()
    ' Parses special strings, processes them, and removes them from
    ' DisplayString before it is sent out to the ConversationBox.
    Dim LocSpecial As Long

    ' LocSpecial = InStr(1, DisplayString, StringConnect)
    ' If LocSpecial > 0 Then
    ' ' Start a new session.
    ' RemoveSpecialString LocSpecial, Len(StringConnect)
    ' InactivityTimer.Interval = 1 * Minutes + 5 * Seconds ' Just longer than 2 pings from the client
    ' lblStatus.Caption = " A Buddy has connected"
    ' mnuConnect.Caption = "Disconnect"
    ' BlueState = ConnectedServer
    ' txtInput.Locked = False
    ' txtInput.SetFocus
    ' End If

    LocSpecial = InStrRev(DisplayString, StringDisconnect)
    If LocSpecial > 0 Then
    ' Connection was disconnected. Reset the server
    RemoveSpecialString LocSpecial, Len(StringDisconnect)
    CloseServer
    OpenServer
    End If

    LocSpecial = InStr(1, DisplayString, StringPing)
    If LocSpecial > 0 Then
    ' Just remove the Ping string
    RemoveSpecialString LocSpecial, Len(StringPing)
    End If
    End Sub

    Private Sub RemoveSpecialString(Start As Long, Length As Long)
    ' Removes the text in the specified range from DisplayString
    Dim TempStr As String

    TempStr = Mid(DisplayString, Start + Length)
    DisplayString = Left(DisplayString, Start - 1) & TempStr
    End Sub

    Private Sub SendButton_Click()
    Dim StringToSend As String

    If BlueState = ConnectedClient Then
    If Len(txtInput.Text) > 0 Then
    ' Reset Ping timer if you are the client
    If BlueState = ConnectedClient Then
    InactivityTimer.Enabled = False
    InactivityTimer.Enabled = True
    End If

    ' Update the conversation box and send the message to your buddy
    StringToSend = "* " & DeviceUser & " says:" & _
    vbCrLf & txtInput.Text & vbCrLf

    UpdateConversationBox StringToSend
    serConnection.Output = StringToSend

    ' Clear the Input TextBox
    txtInput.Text = ""
    End If
    End If
    ' Give focus to the Input TextBox
    txtInput.SetFocus
    End Sub

    Private Sub UpdateConversationBox(message As String) ' Updates txtConversation
    With txtConversation
    ' Append the message to the Conversation TextBox
    .Text = .Text & message

    ' Scroll down the Conversation TextBox to show the new text
    .TopLine = .TotalLines - .DisplayableLines
    End With
    End Sub

    Private Sub Form_Terminate()
    ' Let the other guy know you're leaving if you haven't already.
    CloseServer
    End Sub

    '-----------------------------------------------------------------------------------------------
    '-----------------------------------------------------------------------------------------------
    '
    ' Nokia Series 60 Form Template for AppForge Applications
    ' Revised 10/25/02
    ' Copyright © 2002, AppForge Inc. All rights reserved.
    '
    ' This form template is provided to simplify developing
    ' Nokia Series 60 applications with AppForge.
    ' This template is intended to accompany the Nokia Series 60 Module template.
    '
    '-----------------------------------------------------------------------------------------------
    '-----------------------------------------------------------------------------------------------

    '// The KeyDown event can be used to respond to inputs from the keyboard and control buttons.
    '// Just insert your code after the appropriate Case statement
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case lNOKIA_SELECT_KEYCODE 'Select button
    mnuSend_Click
    KeyCode = 0
    Case vbKeyRight 'Arrow pad right
    serConnection.Output = "a"
    Case vbKeyLeft 'Arrow pad left
    serConnection.Output = "b"

    Case vbKeyUp 'Arrow pad up
    serConnection.Output = "c"

    Case vbKeyDown 'Arrow pad down

    serConnection.Output = "d"

    End Select
    End Sub
  4. Binu

    Binu Administrator

    Likes Received:
    147
    Trophy Points:
    63
    Send me a link to download the APPFORGE MobileVB so that i can try it.
    Just PM me.
Loading...

Share This Page