Shop OBEX P1 Docs P2 Docs Learn Events
How do I read a string through the serial terminal in Visual Basic 2008? — Parallax Forums

How do I read a string through the serial terminal in Visual Basic 2008?

MicrocontrolledMicrocontrolled Posts: 2,461
edited 2010-04-28 12:38 in General Discussion
I have a program in VB 2008 that will read the serial terminal and when it gets a string it will search for a web page using the string as the URL. It will then return the webpage. I have successfully sent strings in VB in the past, but I am now having trouble receiving one. Can I have some help on this?

Thanks,
Micro

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my new website!!

Use the Propeller icon!! Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-04-25 16:13
    What code are you using?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • mctriviamctrivia Posts: 3,772
    edited 2010-04-25 17:20
    Is this your work around to not having a prop Nic? I can lend you one

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Lots of propeller based products in stock at affordable prices.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-04-25 18:29
    @mctrivia: I thought that since this would cut the cost about $20-$30, it is worth it. I have it returning part of the HTML page, but there is some error and I think that it is returning the wrong HTML page. There must be some error with the receive string on the VB side of things. I am having this transmit wirelessly. mctrivia, check your inbox. I'll send you the other app I made for this.
    @others: I'll post my VB code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my new website!!

    Use the Propeller icon!! Propeller.gif

    Follow me on Twitter! Search "Microcontrolled"
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-04-28 12:38
    That doesn't seem to be the complete vb.net code. But in any case, I have lots of bits of vb.net code. At the beginning, use this sort of thing:
    Imports System.IO
    Imports Strings = Microsoft.VisualBasic ' so can use things like left( and right( for strings
    Public Class Form1
        Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer) ' for sleep statements
        Dim WithEvents SerialPort As New IO.Ports.SerialPort ' serial port declare
        Dim OutPacket(0 To 2000) As Byte ' used for serial output bug with serial.write strings like chr(255) won't go out
        Dim InPacket(0 To 2000) As Byte '  for input bytes
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            SerialPort.PortName = "COM1"
            SerialPort.BaudRate = "9600" ' 9600
            SerialPort.Parity = IO.Ports.Parity.None ' no parity
            SerialPort.DataBits = 8 ' 8 bits
            SerialPort.StopBits = IO.Ports.StopBits.One ' one stop bit
        End Sub
    
    



    There are several methods. I tend to set a timer going then periodically check if any bytes are available. Put them in an array and then turn them into strings later. Then you have to remember to disable the timer while running that code. This is an incomplete code fragment that sits in a Do..Loop
                    If SerialPort.BytesToRead = 0 Then Exit Do ' no more bytes
                    BytesToRead = SerialPort.BytesToRead
                    If BytesToRead > 2000 Then BytesToRead = 2000
                    SerialPort.Read(InPacket, 0, BytesToRead) ' read in a packet
    
    



    You can also set interrupts to run when bytes come in. The above assumes that once you have read in n bytes you process them before reading in the next group.

    Or am I completely off the mark? I'm not sure what you mean by "through the serial terminal"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
Sign In or Register to comment.