Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 11, 2024, 05:43:43 17:43


Login with username, password and session length


Pages: [1]
Print
Author Topic: Poblems communicating picbasic pro and vb6  (Read 4533 times)
0 Members and 1 Guest are viewing this topic.
zero
Newbie
*
Offline Offline

Posts: 24

Thank You
-Given: 8
-Receive: 2


« on: March 26, 2007, 01:12:13 13:12 »

Hi everyone!

I'm trying communicating at first digital data between pic with picbasic pro and vb6 on the pc.

My problem is with variables in the pic code and vb6 source code.
At first step i tryed sending data from pic to pc.

serout2 portb.2,n9600,[dec B7]   
B7 is a variable Word

in vb6

Private sub form load
mscomm1.commport=1
mscomm1.settings= "9600,n,8,1"
mscomm1.portopen=true
sdata=mscomm1.input
lbl1.caption=sdata

sdata is a variable.

when i debug the program with F8 everithing runs ok but i don't receive nothing in sdata, i don't understand, i've shearch on rentron  site but i can't found the problem. Huh Huh
thanks in advance
 ZERO
Logged
frasenci
Translator
Active Member
***
Offline Offline

Posts: 171

Thank You
-Given: 142
-Receive: 84


« Reply #1 on: March 26, 2007, 02:38:18 14:38 »

Hi ZERO,

I suggest you check settings on size off INPUT buffer , an OnReceive() message for mscomm1 in your Vb prog.
Set mscomm1 for byte data type , buffer = 1 ( fires every 1 byte received, or 2 for Word length)

I also suggest you just send the raw data byte for byte  ( no formatting ) for Vb to read.

Not an expert but faced the same problem time ago.


Now , you want it easy , have a look at this interesting program.

Code:
http://www.rhombus-tek.com./microgui.html


I vae tried it out wit BStamp and PIC 16/18.  Works fine !!

 Wink

So long
FAA
Logged
zero
Newbie
*
Offline Offline

Posts: 24

Thank You
-Given: 8
-Receive: 2


« Reply #2 on: March 26, 2007, 05:41:23 17:41 »

thanks Frasencis
Logged
LazBoy
Active Member
***
Offline Offline

Posts: 154

Thank You
-Given: 78
-Receive: 25


« Reply #3 on: March 27, 2007, 07:15:14 19:15 »

I recommended EPE SerialOCX (freeware).
SerialOCX is more effective than MSComm:

http://ftp://ftp.epemag.wimborne.co.uk/pub/PICS/SerialOCX/

Sample files included.
Logged
raham
Junior Member
**
Offline Offline

Posts: 70

Thank You
-Given: 13
-Receive: 18


« Reply #4 on: March 28, 2007, 08:01:37 08:01 »

Thank you lazboy i will try it  Smiley
Logged
frasenci
Translator
Active Member
***
Offline Offline

Posts: 171

Thank You
-Given: 142
-Receive: 84


« Reply #5 on: March 28, 2007, 05:53:12 17:53 »

Nice !!!!

LAZYBOY, I will give it a try.

Posted EPE Oct- 2003 issue in EBooks , sits on arunalab FTP

Thank You

Greetings
FAA
Logged
chyelim
Junior Member
**
Offline Offline

Posts: 81

Thank You
-Given: 715
-Receive: 134


« Reply #6 on: March 28, 2007, 06:34:50 18:34 »

Hi, currently I'm working on a project which use the function, it is already work fine. Here is my source code in PICBASIC PRO.

Notes : Please put on the 22K and 1K resistor to the RX and TX pins that means PIN 2 and PIN 3 on the serial port. Remember to set the default of the RThreshold=1 in Visual Basic, if not VB will not receive anything.

-- Start --

DEFINE OSC 20

        Include "modedefs.bas"          ' Include serial modes

SO      var     portc.3                       ' Define serial out pin
SI      var     portc.0                       ' Define serial in pin
Alarm   var      portb.5                    ' Alarm
Unlock   var    portb.4                    ' Unlock
RedLed   var      porte.0                    ' Red Led
OrgLed   var      porte.1                    ' Orange Led
GrnLed   var      porte.2                    ' Green Led

B0        var    byte

TRISE=%000
TRISC.3=0
TRISC.0=1
ADCON1=7

low RedLed
low OrgLed
low GrnLed

inloop:   
   Serin2 SI,16468,[B0]                       ' B0 = input character
       
loop:   
   if (B0="S") then
      high OrgLed
      Serout2 SO,16468,["R"]
      goto mainloop
   endif

   if (B0="O") then
      low RedLed
      high GrnLed
      goto inloop      
   endif

   if (B0="E") then
      low GrnLed
      high RedLed
      goto inloop
   endif
   
   if (B0="X") then
      while (Unlock=1)
      wend
      Serout2 SO,16468,["L"]
      pause 5000
      pause 5000   
      low GrnLed
      Serout2 SO,16468,["Z"]
      goto mainloop
   endif
goto loop

mainloop:
   if (Unlock=1) then
      Serout2 SO,16468,["P"]
      goto inloop
   endif

   if (Alarm=1) then
      low Grnled
      high RedLed
      Serout2 SO,16468,["E"]
      goto mainloop
   endif
goto mainloop

-- End --

Here is my VB source code

-- Start --

Option Explicit
Dim WithEvents Context As SpSharedRecoContext
Dim Grammar As ISpeechRecoGrammar
Dim PicPixels() As Long
Dim Data As String
Dim Counter As Integer

Private Sub cmdExit_Click()
    'Grammar.DictationUnload
    'Grammar.DictationSetState SGDSInactive
   
    ComPort.PortOpen = False
    'Exit program
    Unload Me
End Sub

Private Sub Command1_Click()
    If (Context Is Nothing) Then
        Set Context = New SpSharedRecoContext
        Set Grammar = Context.CreateGrammar(1)
        Grammar.DictationLoad
    End If
   
    Grammar.DictationSetState SGDSActive
End Sub

Private Sub Command4_Click()
    ez1.ShowDlgVideoFormat
End Sub

Private Sub cmdLoad_Click()
    'If there are Errors -> Exit sub
    On Error GoTo EndOfcmdLoad_Click
   
    Set picImage.Picture = LoadPicture(App.Path & "\Init.jpg")
EndOfcmdLoad_Click:
End Sub

Private Sub Command5_Click()
    ez1.CaptureFile = App.Path & "\init.jpg"
    ez1.SaveDIB App.Path & "\init.jpg"
    cmdLoad_Click
End Sub

Private Sub Context_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechRecognitionType, ByVal Result As ISpeechRecoResult)
    List1.AddItem Result.PhraseInfo.GetText
    Text1.Text = Result.PhraseInfo.GetText
    If Text1.Text = "you" Or Text1.Text = "YOU" Or Text1.Text = "You" Then
        Shape3.FillStyle = 1
        Shape1.FillStyle = 0
        ComPort.Output = "O"
        lblStatus.Caption = "Unlocked"
        lblTimer.Caption = "10"
        Grammar.DictationSetState SGDSInactive
        Counter = 0
        Timer1.Enabled = True
    Else
        Counter = Counter + 1
        If Counter = 3 Then
            Counter = 0
            Shape1.FillStyle = 1
            Shape3.FillStyle = 0
            ComPort.Output = "E"
            lblStatus.Caption = "Alarm On"
            Command5_Click
        End If
    End If
End Sub

Private Sub Form_Load()
    ReDim PicPixels(picImage.ScaleWidth / Screen.TwipsPerPixelX, picImage.ScaleHeight / Screen.TwipsPerPixelY)
    'Command1_Click
    Data = ""
    txtIn.Text = ""
    lblStatus.Caption = ""
    Counter = 0
    ComPort.PortOpen = True
    Shape2.FillStyle = 0
    ComPort.Output = "S"
End Sub
'Monitor The Com Port Events
Private Sub comPort_OnComm()
   
    Select Case ComPort.CommEvent
       
        Case comEvReceive
               
                Data = ComPort.Input
                txtIn.Text = Data
               
                If Data = "P" Then
                   
                    lblStatus.Caption = "Voice Please"
                    Command1_Click
               
                ElseIf Data = "E" Then
                       
                    Shape1.FillStyle = 1
                    Shape3.FillStyle = 0
                    lblStatus.Caption = "Alarm On"
                    Command5_Click
                                                                   
                ElseIf Data = "L" Then
                   
                    lblStatus.Caption = "Locking..."
                   
                ElseIf Data = "Z" Then
                   
                    Shape1.FillStyle = 1
                    Shape3.FillStyle = 1
                    lblStatus.Caption = "Locked"
               
                ElseIf Data = "R" Then
                               
                    lblStatus.Caption = "Ready"
                   
                End If
                               
    End Select

End Sub

Private Sub Timer1_Timer()
    If lblTimer.Caption = 0 Then
        lblStatus.Caption = "Please Lock"
        ComPort.Output = "X"
        Grammar.DictationSetState SGDSInactive
        Timer1.Enabled = False
    Else
        lblTimer.Caption = lblTimer.Caption - 1
    End If
End Sub

-- End --

Hope it will help !! Enjoy !!
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC