Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 27, 2024, 08:50:57 20:50


Login with username, password and session length


Pages: [1]
Print
Author Topic: Visual basic 2008 picbasic pro  (Read 11641 times)
0 Members and 2 Guests are viewing this topic.
zero
Newbie
*
Offline Offline

Posts: 24

Thank You
-Given: 8
-Receive: 2


« on: October 08, 2008, 04:36:43 16:36 »

Hi people!
Had anyone of you used vb 2008 to comunicating with picbasic pro?
Or in your opinion is better visual basic 6?

Thank you !

With best regards
Zero
Logged
gem1144aaa
Junior Member
**
Offline Offline

Posts: 88

Thank You
-Given: 134
-Receive: 27


« Reply #1 on: October 12, 2008, 04:57:01 16:57 »

Hi

generally in control systems we use Vb6 cause its easier smaller and requires no special hw or sw

unless some complicated .net application is required
Logged
sherm
Junior Member
**
Offline Offline

Posts: 44

Thank You
-Given: 14
-Receive: 9


« Reply #2 on: October 14, 2008, 04:22:09 04:22 »

It is very simple to get VB2008 and PicBasic Pro talking to one another. Here is an example of one direction communication to get you started.

PicBasic Pro Code:

Written for a PIC16F628 running at 20MHz with 2 LEDs for diagnostics, and a MAX232 to drive the serial I/O

Code:
@ DEVICE HS_OSC, LVP_OFF, MCLR_OFF, WDT_OFF
  DEFINE   OSC 20

'***************************
' Alias
'***************************
  LED_Pow  VAR PORTB.0        'Power LED. Shows code is running
  LED_Stat VAR PORTB.1        'Status LED. Blinks each time data is sent
  IO_Tx    VAR PORTA.3        'Serial Out to MAX232

'***************************
' Constants
'***************************   
  IO_Baud  CON 6              'Connection parameters: 9600 8,N,1
 
Init:
  HIGH     LED_Pow            'Code is running
  LOW      LED_Stat
   
Main_Loop:
  'Transmit a string roughly every two seconds.
  SEROUT   IO_Tx, IO_Baud, ["BLIP", 10, 13]
  HIGH     LED_Stat
  PAUSE    250
   
  LOW      LED_Stat
  PAUSE    1750
 
  GOTO     Main_Loop


This will output the string "BLIP" about every two seconds from the PIC.


Now some .NET code to retreive the data:

Start by adding a listbox to your main form and name it lstData. This will display the data as it is collected.
Add a button named butConnect. This will open your serial port to start receiving data.
Add a button named butDisconnect. This will close the serial port.

Code:
Imports System.IO
Imports System.IO.Ports
Imports System.Net
Imports System.Data
Imports System
Imports System.Windows.Forms
Imports System.Threading
Imports System.Text

Public Class mMain

  Dim WithEvents serPort As New IO.Ports.SerialPort
  Dim myStringBuilder As New StringBuilder

  Private Sub mMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    serPort.PortName = "COM1"  'Set to whichever COM port you will be listening to
    serPort.BaudRate = 9600
    serPort.DataBits = 8
    serPort.Parity = Parity.None
    serPort.StopBits = StopBits.One

    butConnect.Enabled = True
    butDisConnect.Enabled = False
  End Sub

  Private Sub butConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butConnect.Click
    If (serPort.IsOpen = False) Then
      Try
        serPort.Open()

        lstData.Items.Clear()
        myStringBuilder = New StringBuilder  'Clear any old data
       
        butConnect.Enabled = False
        butDisConnect.Enabled = True
      Catch ex As Exception
        'Routine to process exceptions like port already open etc.
        msgbox("Exception error")
      End Try
    End If
  End Sub

  Private Sub butDisConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butDisConnect.Click
    If (serPort.IsOpen = True) Then
      serPort.Close()
      butDisConnect.Enabled = False
      butConnect.Enabled = True
    End If
  End Sub

  Private Sub serPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serPort.DataReceived
    Try
      myStringBuilder.Append(serPort.ReadExisting())
      Me.Invoke(New EventHandler(AddressOf update_Data))
    Catch ex As Exception
      MsgBox("Data Error")
    End Try
  End Sub

  Private Sub update_Data()
    lstData.Items.Add(myStringBuilder.ToString)
    myStringBuilder = New StringBuilder  'Flush the old data
  End Sub
End Class

There are some imports at the top of the code that aren't really needed. They're just a generic starting point that I use. Obviously, for a proper application, there would need to be a lot more error handling added. This is just a starting point on getting going using the serial port in .NET.

From here you could add a status bar to the form and keep a track of how long you have been connected and perhaps the number of packets you've received. Then you can move on to transmitting data from the PC to the PIC.

Hope this is of use to you.

regards,

Sherm



Posted on: October 14, 2008, 11:47:08 11:47 - Automerged

generally in control systems we use Vb6 cause its easier smaller and requires no special hw or sw

unless some complicated .net application is required

... or you'll use .NET if you want menus to display nicely under Windows XP Tongue

I was once loathe to make the transition from VB6 to .NET. I've found over time that the benefits of .NET and the IDE are more than those of VB6 in most circumstances for myself. I respect that other people will have different needs, and I still prefer VB6 from a simplicity point of view. VS2008 has grown on me though Smiley
« Last Edit: October 14, 2008, 04:24:38 04:24 by sherm » Logged
Shinta
Newbie
*
Offline Offline

Posts: 21

Thank You
-Given: 20
-Receive: 3


« Reply #3 on: November 05, 2008, 12:50:41 00:50 »

First.... Like Always.... Sorry my very bad english

VB200X Is my favorite software development program. Is very powerfull and it can't compare with VB6 because the things that you can do with VB200X (specially 2008) is impossible make in VB6.

Altought VB2003 doens't provide controls to make easy the serial communication, VB2005 and VB2008 have a preinstalled component called SerialPort. the parameters like baudrate, parity, databits, rts, cts, CommPort, InBuffer, OutBuffer, TimeOut are setteable by the properties window in design mode (don't forget that also can be modified by code).

If you don't know the comm ports avalaibles you can use the following code:

For i As Byte = 0 To My.Computer.Ports.SerialPortNames.Count - 1
     Me.ComboBox1.Items.Add(My.Computer.Ports.SerialportNames(i))
Next i

of course you first have a control ComboBox named ComboBox1. Discard the COM3 port because is the modem and if you have a bluetooth serial device maybe a COM4 also be enlisted.

To open the port with a SerialPort Control you will use the following code
me.SerialPort1.open

If you want to send a data with the SerialPort control you can use the following code
Me.SerialPort1.Write("Hola a todo el mundo")
Is not a problem if you want send a character (ascii code) or a string

if you want to read a data with the SerialPort control you can use the following code
Dim Var As String = me.SerialPort1.ReadExisting

And Finally if you want to close the port try this
me.Serialport1.close

A little of practice and you will discover a lot of posibilities of control that VB6 don't have.
Logged
hemlig
Translator
Active Member
***
Offline Offline

Posts: 168

Thank You
-Given: 26
-Receive: 50



« Reply #4 on: November 05, 2008, 01:21:25 01:21 »

The difference in this particular example of comparision between VB6 and VB200x is the name of the control and the syntax as the control for serialport in VB6 is MSCOMM.
One advantage of VB6 is that it runs directly on WinXP without the need of first installing dotnetfx.
(dotnetfx 1 for VB2003, dotnetfx 2 for VB2005 and dotnetfx 3 for VB2008).

There are other advantages with the dotnet concept as joining codes from other languages as CSharp etc. (this could be the reason why they (M$) made dotnet).
But for controling a serialport it might be easier to use VB6 with a much smaller footprint.

Logged

If it work don't fix it!
FriskyFerret
Hero Member
*****
Offline Offline

Posts: 560

Thank You
-Given: 513
-Receive: 360


Put it in, take it out.


WWW
« Reply #5 on: November 05, 2008, 02:38:18 02:38 »

Use VB6 but use a third-party serial communications library control. You'll have much more flexibility and control. There are two main libraries to consider. Can't remember which one I used. It was 3 or 4 years ago that I did a sizable laboratory control application.

Remember, don't use more technology than you need to get the job done quickly, correctly and maintainable. Leave .NET to the code-heads.
Logged

Dancing pants and leotards, that's what I'm talkin' about!
sonicm
Inactive

Offline Offline

Posts: 5

Thank You
-Given: 10
-Receive: 0


« Reply #6 on: February 20, 2009, 04:16:34 04:16 »

Use VB6 but use a third-party serial communications library control. You'll have much more flexibility and control. There are two main libraries to consider. Can't remember which one I used. It was 3 or 4 years ago that I did a sizable laboratory control application.

Remember, don't use more technology than you need to get the job done quickly, correctly and maintainable. Leave .NET to the code-heads.
I'm really agree with FriskyFerret , in real world, most of application still use VB6 to communicate with microcontroller etc. ECU of gas injector engine.(many vendor)
you have to lunch application fast to market. And I saw some vendor use .net and it's  not work properly. like connection not stable , program error ..


Logged
newboy
Junior Member
**
Offline Offline

Posts: 94

Thank You
-Given: 42
-Receive: 20


« Reply #7 on: February 20, 2009, 05:51:28 05:51 »

Use VB6 but use a third-party serial communications library control. You'll have much more flexibility and control. There are two main libraries to consider. Can't remember which one I used. It was 3 or 4 years ago that I did a sizable laboratory control application.

Remember, don't use more technology than you need to get the job done quickly, correctly and maintainable. Leave .NET to the code-heads.

Can you share the library here ?

Thanks
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