Visual Basic

Lliam20789

New Member
Guys,
I have been experimenting with VB, but still can not et it to read simple variable sent out, vier the PICAXE with the sertxd command.
Could some one help me with the setup?
 

Lliam20789

New Member
I just downloaded it onto my Mum's PC laptop.
:Microsoft Visual Basic 2005 Express Edition

In about:
Microsoft Visual Studio 2005
V 8.0.50727.42

Microsoft .NET Framework
V 2.0..50727

I don't think it's the NET one.

Thanks
 

inglewoodpete

Senior Member
I have written code in VB2005 Express to read and log Debug outputs, so it can be done. I have the code at home, so will try to upload it tonight (Aust time).
 

Lliam20789

New Member
sounds great! thanks!
That would would basically be the basis of the program I need so it would be great to learn from.

Thanks again.
 

moxhamj

New Member
Essentially Micro-Soft Basic (1978), Qbasic (80's)and vb 1 to 6 all supported the serial port, and then they got rid of it in vb.net. <A href='http://www.codeworks.it/net/VBNetRs232.htm' Target=_Blank>External Web Link</a> describes it in a bit more detail.
My working vb6 code is at <A href='http://www.geocities.com/drvernacula/serial_port_communications_with_.htm' Target=_Blank>External Web Link</a>

I'm going to stick with vb6 until it becomes hopelessly obsolete and/or vb.net gets fixed.

I suspect where things are going is embedded controllers that link directly to a router via cat6 and have I/O on them. Thus rather than having a PC controlling things, the internet controls it and the actual controller is any PC on the internet. Ethernet to serial adaptors are getting cheaper. One can imagine cheap devices with wireless that just hook into a home wireless network on a 192.168.1.x address. Not quite sub $10 yet though.

Meanwhile, if vb.net is too hard maybe get a copy of vb6?
 

Lliam20789

New Member
Thankyou Dr_Acula,
I take it this version of VB is not the one I have or the free one...?
I got my version free of the Microsoft site....
I also just found Microsoft Robotics Studio... interesting...
anyway, it seems as though 2005 is the newer version, at least it's free...
 

inglewoodpete

Senior Member
VB 6 is more primituve implemention of VB but its a lot more understandable for a traditional BASIC programmer. VB2005Ex takes OO programming to a new level, if anything, parallelling Visual C or Java.

Translating programs from VB6 to VB2005Ex is not a simple exercise, especially if you're struggling with getting your head around VB2005Ex. (Trust me: I know ;o)
 

RickAlty

Senior Member
I have succesfully commuicated with a picaxe using VB 5 and 6, and also with the .NET Express (The free one that you downloaded).

It's a LOT easier in the older versions of VB than it is in .net Express, though.

It's actually gotten easier again in the full version of VB .NET, because MS got so many complaints about dropping MSComm that they put it back.
 

Denzel

Senior Member
I had vb 2005 express before I got the genuine give up your life savings edition from singapore and the coding is compatible with both. It is definately easier in vb 6 but I have made a real time scanner with the edition you have that collects picaxe sertxd readings off the input buffer and converts them into a picture so...

My first step to accomplishing what you intend to do was to download the following vb 2005 programme from this website

http://www.hardandsoftware.net/

before you get edgy about downloading this its not really software, it's more of a resource and ive downloaded it about 5 times its so helpful so its trustworthy!

goto software downloads then from the page that shows scroll to the main heading
OTHER DOWNLOADS
click on the 'DesktopSerialIO' link and then from the page that shows scroll down
until you see this...

&quot;Download Now, Visual Studio 2003 version, about 50 KB (includes a simple VB .NET Terminal application example).&quot;
Download this it will be a lifesave, it was for me.
next extract the files and open the folder, click on 'testdesktopterm' project file and it should open in the designer mode of your vb express with a single form that says 'simple terminal' on it.

For this particular project to recieve picaxe data all you have to do is change the bitrate to 4800 OR the bit/baudrate that your picaxe is using
.BitRate = 9600 TO .BitRate = 4800
An you will need to change the commport to the number commport you are using,
.CommPort = 7 TO .CommPort = 1 etc etc

once you have done that it should be ready to test. just click run and plug in a picaxe and sertxd a variable or &quot;text&quot; and it should appear on the form.

Once that is acheived customise the programme all you want so if that means manipulating the data coming in from the input buffer then you could do the following in the ON_COMM event:

Private Sub SerialPort_OnComm() Handles SerialPort.OnComm
ReceiveBuffer.Append(SerialPort.InputString)
Dim value as string
value = ReceiveBuffer.ToString 'then do with 'value' what you wish!!!!

Any questions? (LOL)
P.S my names Liam

Edited by - Denzel on 11/05/2007 09:32:08

Edited by - Denzel on 11/05/2007 09:35:02
 

manuka

Senior Member
Liam - I've just received you direct email about this, &amp; feel you may well be best to check StampPlot &amp; StampDAQ. Both these Basic Stamp utilities are Picaxe friendly &amp; capable of gorgeous graphical displays. Stan
 

rbright

Member
Don't forget Liberty Basic - very user friendly and supported with a great user forum. look at http://www.phanderson.com/picaxe/liberty_basic.html
 

inglewoodpete

Senior Member
Below is the core code to read serial data using VB2005 Express. It is a working serial 'receive-only' terminal.

In order to reduce the size of this post, I have only included the 'receive' code. No 'send' code or processing of debug outputs.


Create a form with the following controls:
cboPort (ComboBox)
cboBitRate (ComboBox)
cboBits (ComboBox)
cboParity (ComboBox)
cboHandshake (ComboBox)
txtReceivedLog (TextBox with Multiline = True and Scrollbars = Vertical)

Code:
Imports System
Imports System.IO.Ports
Imports System.Threading.Thread
' Imports the System, System.IO.Ports and System.Threading.Thread namespaces so that e.g.
'   System.IO.Ports.SerialPort may just be written as SerialPort, and System.EventArgs may just be
'     written as EventArgs.

Public Class Form1

    Public Delegate Sub StringSubPointer(ByVal Buffer As String)
    Dim SpaceCount As Byte = 0
    Dim sDataSeparator As String = " "

    Dim WithEvents SerialPort As New SerialPort ' Make a new System.IO.Ports.SerialPort instance, which is able to send events

    Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
        ' Note this subroutine is executed on the serial port thread - not the UI thread.
        Dim RXByte, Nibble As Byte
        Dim RXArray(2047) As Char
        Dim I As Integer = 0
        Dim BreakDetect As Boolean
        '
        Do
            BreakDetect = SerialPort.BreakState     ' Read COMPort.BreakState as early as possible.
            ' Note. Break detection above approximately 300 bit/s is not reliable because BreakState may go low again
            '   before this routine is running (not latched).
            RXByte = SerialPort.ReadByte
            If BreakDetect And (RXByte = 0) Then ' If RXByte <> 0, the Break is detected too early
                RXArray(I) = "B"
                I = I + 1
                RXArray(I) = "r"
                I = I + 1
                RXArray(I) = "e"
                I = I + 1
                RXArray(I) = "a"
                I = I + 1
                RXArray(I) = "k"
                I = I + 1
                RXArray(I) = Chr(13)  ' CR
                I = I + 1
                RXArray(I) = Chr(10)  ' LF
                I = I + 1
                SpaceCount = 0
            Else
                Nibble = (RXByte >> 4) + 48 ' Convert received byte to Hex
                If Nibble > 57 Then
                    Nibble = Nibble + 7
                End If
                RXArray(I) = Chr(Nibble)
                I = I + 1
                Nibble = (RXByte And 15) + 48
                If Nibble > 57 Then
                    Nibble = Nibble + 7
                End If
                RXArray(I) = Chr(Nibble)
                I = I + 1
                RXArray(I) = sDataSeparator
                I = I + 1
                SpaceCount = (SpaceCount + 1) And 31 ' Insert spaces and CRLF for better readability
                If SpaceCount = 0 Then               ' Insert CRLF after 32 numbers
                    RXArray(I) = Chr(13) ' CR
                    I = I + 1
                    RXArray(I) = Chr(10) ' LF
                    I = I + 1
                Else
                    If (SpaceCount And 3) = 0 Then   ' Insert two extra spaces for each 4 numbers
                        RXArray(I) = " "
                        I = I + 1
                        RXArray(I) = " "
                        I = I + 1
                    End If
                End If
            End If
        Loop Until (SerialPort.BytesToRead = 0)
        Dim RxString As New String(RXArray, 0, I) ' Convert the first part of the Char Array to a String
        ' Put the display routine and the RxString on the message queue and return immediately.
        txtReceivedLog.BeginInvoke(New StringSubPointer(AddressOf Display), RxString)
    End Sub

    ' Text display routine, which appends the received string to any text in the Received TextBox form.

    Private Sub Display(ByVal Buffer As String)
        txtReceivedLog.AppendText(Buffer)
    End Sub

    Private Sub cboPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPort.SelectedIndexChanged
        OpenSerialPort()
    End Sub

    'Handles the opening (or changing) of the port

    Private Sub OpenSerialPort()
        'Port has been selected or changed via the Combo List box of port names
        If SerialPort.IsOpen Then
            SerialPort.RtsEnable = False
            SerialPort.DtrEnable = False
            SerialPort.Close()
            Application.DoEvents()          ' Empty the message queue before the UI thread goes to sleep.
            Sleep(200)                      ' Wait 0.2 second for port to close as this do not happen immediately.
        End If
        SerialPort.PortName = cboPort.Text  ' Default: 9600 Baud, 8 data bits, no parity, 1 stop bit

        ' Set the buffer size to 2, which is minimum. The reason for this is that the buffer is only 8 bit wide,
        '   but the receiver FIFO in the UART is 11 bit wide as it also contains information about any Break or
        '     error conditions. Because of this difference, a Break condition may be detected too early.
        '       To minimize the problem, the buffer size is reduced as much as possible.
        SerialPort.ReadBufferSize = 2
        SerialPort.WriteTimeout = 5000          ' Max time to wait for CTS = 5 sec. 
        Try
            SerialPort.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If SerialPort Is Nothing Then
            cboBitRate.Text = ""
            cboBits.Text = ""
            cboParity.Text = ""
            cboHandshake.Text = ""
        Else
            cboBitRate.Text = SerialPort.BaudRate.ToString
            cboBits.Text = SerialPort.DataBits.ToString
            cboParity.Text = SerialPort.Parity.ToString
            cboHandshake.Text = SerialPort.Handshake.ToString
            SerialPort.RtsEnable = True
            SerialPort.DtrEnable = True
        End If
    End Sub

    Private Sub cboBitRate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboBitRate.SelectedIndexChanged
        SerialPort.BaudRate = CInt(cboBitRate.Text)
    End Sub

    Private Sub cboBits_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboBits.SelectedIndexChanged
        SerialPort.DataBits = CInt(cboBits.Text)
    End Sub

    Private Sub cboParity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboParity.SelectedIndexChanged
        SerialPort.Parity = CType([Enum].Parse(GetType(Parity), cboParity.Text), Parity)
    End Sub

    Private Sub cboHandshake_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboHandshake.SelectedIndexChanged
        SerialPort.Handshake = CType([Enum].Parse(GetType(Handshake), cboHandshake.Text), Handshake)
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If SerialPort.IsOpen Then SerialPort.Close() ' Close COM port when the form is terminated with [X]
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For Each COMString As String In My.Computer.Ports.SerialPortNames ' Load all available COM ports.
            cboPort.Items.Add(COMString)
        Next
        cboPort.Sorted = True
        cboPort.SelectedIndex = 0  'Ensure default serial port is selected 
        'cboBitRate.Items.Add("110")
        cboBitRate.Items.Add("300")
        cboBitRate.Items.Add("600")
        cboBitRate.Items.Add("1200")
        cboBitRate.Items.Add("1800")
        cboBitRate.Items.Add("2400")
        cboBitRate.Items.Add("4800")
        cboBitRate.Items.Add("7200")
        cboBitRate.Items.Add("9600")
        cboBitRate.Items.Add("14400")
        cboBitRate.Items.Add("19200")      ' Min. FIFO size 3 Bytes (8030 or 8530)
        'BaudRateBox.Items.Add("38400")
        'BaudRateBox.Items.Add("57600")      ' Min. FIFO size 8 bytes
        'BaudRateBox.Items.Add("115200")     ' Min. FIFO size 16 bytes (16C550)
        'BaudRateBox.Items.Add("230400")     ' Min. FIFO size 32 bytes (16C650)
        'BaudRateBox.Items.Add("460800")     ' Min. FIFO size 64 bytes (16C750)
        'BaudRateBox.Items.Add("921600")     ' Min. FIFO size 128 bytes (16C850 or 16C950)
        cboBitRate.SelectedIndex = 5    'Set default bit rate = 4800 for PICAXE
        cboBits.Items.Add("5")
        cboBits.Items.Add("6")
        cboBits.Items.Add("7")
        cboBits.Items.Add("8")
        cboParity.Items.Add("None")
        cboParity.Items.Add("Odd")
        cboParity.Items.Add("Even")
        cboParity.Items.Add("Mark")         ' Leaves the parity bit set to 1
        cboParity.Items.Add("Space")        ' Leaves the parity bit set to 0
        cboHandshake.Items.Add("None")
        cboHandshake.Items.Add("RequestToSend")
        cboHandshake.Items.Add("RequestToSendXOnXOff")
        cboHandshake.Items.Add("XOnXOff")
    End Sub
End Class

Edited by - inglewoodpete on 11/05/2007 10:52:46
 
Last edited:
Hi

How would I actually <b>re-program </b> a PICAXE with Vb2005? -When i say re-program, I mean like the programming editor does, but using a GUI and allowing the user to set about 4 lines of code using drop-downs.

thanks
 

Lliam20789

New Member
Thankyou Peter, that is the kind of help I need.
I have read through the program and think I understand most of it.
There is one thing I can not work out, which is why I get:
42 31 20
3D 20 31 30 0D 0A

When I out put the data:
sertxd(&quot;B1 = &quot;,#b1,13,10)

The setting are:
BitRate- 4800
Bits- 8
Parity- None
Handshaking- None

Thankyou for your help,
If you do not wish to post the send code here maybe you would rather email it to me on;
Lliam3_20789@Hotmail.com
That would be much appreciated.

Lliam.
 

hippy

Ex-Staff (retired)
The clue is in the source code comment &quot;Convert received byte to Hex&quot;; what you are seeing is the hexadecimal values of every byte received.
 

moxhamj

New Member
From an ascii table <A href='http://www.asciitable.com/' Target=_Blank>External Web Link</a> in hex, 42=&quot;B&quot;, 31=&quot;1&quot;, 20=space, 3D= &quot;=&quot;... It looks like you might have a eureka moment.

Edited by - Dr_Acula on 13/05/2007 13:24:20
 

Lliam20789

New Member
I understand that. But do I need to take out the hex converter or put in a char converter?
I have been searching for a command or something, but are yet to find a working one...
thanks.
 

moxhamj

New Member
This is in VB I presume, and you have a string representing a hex value? <A href='http://www.devx.com/vb2themax/Tip/18273' Target=_Blank>External Web Link</a> shows how to convert a hex string to a number. Let us know if that is not the conversion you need, as there is a solution for any conversion in VB.
 

hippy

Ex-Staff (retired)
My guess would be to change ...<code><pre><font size=2 face='Courier'> Nibble = (RXByte &gt;&gt; 4) + 48 ' Convert received byte to Hex
If Nibble &gt; 57 Then
Nibble = Nibble + 7
End If
RXArray(I) = Chr(Nibble)
I = I + 1
Nibble = (RXByte And 15) + 48
If Nibble &gt; 57 Then
Nibble = Nibble + 7
End If
RXArray(I) = Chr(Nibble)
I = I + 1 </font></pre></code> to ...<code><pre><font size=2 face='Courier'> RXArray(I) = Chr(RXbyte)
I = I + 1 </font></pre></code> But I have no idea how that's going to affect characters like CR and LF; there may be more to it than that. I'd personally have just extended a string rather than use an array, but then it's not my code :)

As with using the PICAXE effectively, it's a case of sitting down and getting to understand the fundamentals of Visual Basic; reading the documentation, looking at example code and tutorials, cruising the web for information from others, and trying things out. Event driven serial communications isn't the simplest of programs to start with so, like learning to use the PICAXE, it's a case of having to persevere until it all clicks into place.
 

inglewoodpete

Senior Member
Liam, Reading between the lines, you have got the programme running, so now you have something that runs in VB2005Ex.

I posted that code as a concept: something that actually worked on the serial port using VB2005Ex. As you should be able to see that Sub Receiver() handles the SerialPort.DataReceived event. It mashes the data into the receive array and simply hands the array to the Display Sub which appends the new data with the existing in the text box (display).

It should be a simple matter to rewrite the code in Sub Receiver() to simply buffer the available characters and pass them the Sub Display(). That way, the CR (13) and LF (10) will be treated correctly as a simple terminal program.

The code is a subset of a larger programme under development, which logs debug outputs from PICAXEs, formatting them and writing to a log file with date/time stamps etc. for post-processing by MS Excel. There was simply too much code to post on the forum.

I don't want to get involved in rewriting the code for your exact needs: it should be a good exercise to familiarise yourself with VB2005Ex! With my work, family and study commitments (and my own PICAXE developments), I just don't have enough time. However if you have particular queries on the code, I'll try to help.

jsimpson001: Rev-Ed have the only 'compiler' for PICAXE. To rewite it in VB would be a massive task and probably illegal.

-Peter
 

hippy

Ex-Staff (retired)
To clarify some loose ends from early -

Visual Basic 2005 Express Edition is the only VB version Microsoft currently supplies free of charge. For most users it is no less a product than others which Microsoft sell.

VB 2005 Express SP1 is available; make sure that is downloaded and installed as well.

Visual Basic 2005 Express can be used to develop commercial applications and there is no need to register to use it.

Unless one already has a copy of VB 6.0 Pro, IMO, VB 2005 Express is what a VB programmer should be using.

VB 2005 Express is based upon .NET Framework 2.0 and requires that framework to be installed on all PC's on which the finished program will be run. The .NET 2.0 Framework installs on any PC from at least Windows 98SE upwards, so programs written in VB 2005 Express should run under Windows 98SE through Vista.

The VB 2005 Express GUI IDE will only install and run under Windows XP, Vista, 2000 and Server 2003. That should not be a problem for most users.

For advanced users sticking with Windows 98SE, the core VB Compiler is included free in the .NET 2.0 Framework and can be used by coding in Notepad and using the command line compiler. This is not easy and 98SE users, IMO, would be better off using VB 6.0 Pro, or configuring a dual-boot 98SE/XP system.

There are other non-Microsoft products available as alternatives to VB 2005 Express, a Forum Search substitutes for having to list them all again; this is simply to clarify the situation with VB 2005 Express.
 

Lliam20789

New Member
Thankyou,
As a general question, what are the Bits outputed by the Picaxe?
I tried to read them from an ocilascope but could not match them to anything.

Hippy:
Your idea worked but as expected Cr and Lf did not.

Peter:
I expect buffering the text is the best thing to do, but I am still truing to work out how.

Thanks again for all the help
 

hippy

Ex-Staff (retired)
The 'bits' as seen on a scope is the byte sent serially wrapped with a Start (S) and Stop (E) bit. There are eight data bits sent lsb first, and this is commonly known as &quot;8N1&quot; format; 8 data bits, no parity bit, 1 stop bit. When using SERTXD or SEROUT with an Nxxxx baud rate the waveform will look like this -<code><pre><font size=2 face='Courier'> .---. .---. .---.---. +V
| | | | | |
-------' `---^---^---' `---^---' `---------- 0V
| S 0 1 2 3 4 5 6 7 E |
| |
|&lt;------------ One Character ----------&gt;| </font></pre></code> The length of each bit is determined by the baud rate ( 1/baud ) and the data bits are sent with a 1 as 0V and 0 as +V. The above diagram shows a byte of $37 ( Ascii character &quot;7&quot; ) being sent. The start bit is always +V and the Stop bit is always 0V. When using SEROUT with a Txxxx baud rate, the whole waveform will be inverted.

Edited by - hippy on 14/05/2007 14:05:12
 

hippy

Ex-Staff (retired)
To handle non-printable characters, one way would be to change the simple -<code><pre><font size=2 face='Courier'>RXArray(I) = Chr(RXbyte)
I = I + 1 </font></pre></code> to ...<code><pre><font size=2 face='Courier'>If RXbyte &gt;= &amp;h20 And RXbyte &lt; &amp;h7F Then
RXArray(I) = Chr(RXbyte)
I = I + 1
Else
RXArray(I) = &quot;&lt;&quot;
I = I + 1
RXArray(I) = Hex(RXbyte \ &amp;h10)
I = I + 1
RXArray(I) = Hex(RXbyte And &amp;hF)
I = I + 1
RXArray(I) = &quot;&gt;&quot;
I = I + 1
End If </font></pre></code>
 
Top