Click here to Skip to main content
15,899,126 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: VB.NET SQL Error Pin
Shrimpersfan10-Feb-09 1:40
Shrimpersfan10-Feb-09 1:40 
GeneralRe: VB.NET SQL Error Pin
Rupesh Kumar Swami10-Feb-09 1:48
Rupesh Kumar Swami10-Feb-09 1:48 
GeneralRe: VB.NET SQL Error Pin
Shrimpersfan10-Feb-09 1:50
Shrimpersfan10-Feb-09 1:50 
GeneralRe: VB.NET SQL Error Pin
Rupesh Kumar Swami10-Feb-09 1:58
Rupesh Kumar Swami10-Feb-09 1:58 
GeneralRe: VB.NET SQL Error Pin
Shrimpersfan10-Feb-09 3:19
Shrimpersfan10-Feb-09 3:19 
QuestionSerialport data save to file Pin
Quin Nee9-Feb-09 22:40
Quin Nee9-Feb-09 22:40 
AnswerRe: Serialport data save to file Pin
Dave Kreskowiak10-Feb-09 5:32
mveDave Kreskowiak10-Feb-09 5:32 
GeneralRe: Serialport data save to file Pin
Quin Nee16-Feb-09 3:10
Quin Nee16-Feb-09 3:10 
Dear Dave,

Thanks for the hints. I have the program up and running but it's still rough around the edges for my project. Is it possible to recognise the type of data cming in? For example, the device connected to the computer is a wireless node which receives transmissions from other wireless nodes. I want to read the data from each node and save it into different files like the MAC add of each node. Is it possible to do so in VB.NET. So far most of what I read about serial comms is just reading character or data. A colleague suggested using a look-up table to classify the data received. I'm not too sure how it works though. Btw, please take a look at my codes and inform me if there are any better methods of doing it.
Imports System.Text
Imports System.IO.Ports

Public Class Form1
    Dim WithEvents serialPort As New IO.Ports.SerialPort
    Dim mystringbuilder As New StringBuilder
    Private Sub Form1_Load( _
           ByVal sender As System.Object, _
           ByVal e As System.EventArgs) _
           Handles MyBase.Load

        For i As Integer = 0 To _
           My.Computer.Ports.SerialPortNames.Count - 1
            ComboBox3.Items.Add( _
               My.Computer.Ports.SerialPortNames(i))
        Next
        Button2.Enabled = False
    End Sub

    '-------------------------------------------
    ' Event handler for the Connect button
    '-------------------------------------------
    Private Sub Button1_Click( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) _
       Handles Button1.Click

        If serialPort.IsOpen Then
            serialPort.Close()
        End If

        Try
            With serialPort
                .PortName = ComboBox3.Text()
                .BaudRate = 9600
                .Parity = IO.Ports.Parity.None
                .DataBits = 8
                .StopBits = IO.Ports.StopBits.One
            End With
            serialPort.Open()

            TextBox2.Text = ComboBox3.Text & " connected."
            Button1.Enabled = False
            Button2.Enabled = True
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
    '-------------------------------------------
    ' Event handler for the Disconnect button
    '-------------------------------------------
    Private Sub Button2_click( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) _
       Handles Button2.Click
        Try
            serialPort.Close()
            TextBox2.Text = serialPort.PortName & " disconnected."
            Button1.Enabled = True
            Button2.Enabled = False
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
    
    '-------------------------------------------
    ' Event handler for the DataReceived
    '-------------------------------------------
    Private Sub Serialport_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialPort.DataReceived
        'This happens on another thread
        mystringbuilder.Append(serialPort.ReadExisting())
        Me.Invoke(New EventHandler(AddressOf UpdateControls))
    End Sub

    Private Sub UpdateControls(ByVal sender As Object, ByVal e As EventArgs)
        'Do any UI code here on the main thread
        My.Computer.FileSystem.WriteAllText("J:\Test\test.txt", mystringbuilder.ToString(), True)

    End Sub


End Class

Most of it was copy and paste but I do get the general understanding of the program. I still feel that the data received section can be improved. I hope to hear from anyone soon about this.
GeneralRe: Serialport data save to file Pin
Dave Kreskowiak16-Feb-09 12:07
mveDave Kreskowiak16-Feb-09 12:07 
GeneralRe: Serialport data save to file Pin
Quin Nee18-Feb-09 9:48
Quin Nee18-Feb-09 9:48 
QuestionPopup box Pin
carrigart9-Feb-09 20:23
carrigart9-Feb-09 20:23 
AnswerRe: Popup box Pin
Rupesh Kumar Swami9-Feb-09 20:49
Rupesh Kumar Swami9-Feb-09 20:49 
GeneralRe: Popup box Pin
carrigart9-Feb-09 22:37
carrigart9-Feb-09 22:37 
GeneralRe: Popup box Pin
Dave Kreskowiak10-Feb-09 1:57
mveDave Kreskowiak10-Feb-09 1:57 
GeneralRe: Popup box Pin
carrigart10-Feb-09 21:57
carrigart10-Feb-09 21:57 
GeneralRe: Popup box Pin
Dave Kreskowiak11-Feb-09 1:28
mveDave Kreskowiak11-Feb-09 1:28 
QuestionAdd all files under a particular folder and subfolders to listbox [modified] using VB.Net Pin
SankarKonagalla9-Feb-09 19:24
SankarKonagalla9-Feb-09 19:24 
AnswerRe: Add all files under a particular folder and subfolders to listbox [modified] using VB.Net Pin
Rupesh Kumar Swami9-Feb-09 20:54
Rupesh Kumar Swami9-Feb-09 20:54 
Questionhow do i get the exe reference (dll) files using vb.net Pin
kvelu.d9-Feb-09 19:21
kvelu.d9-Feb-09 19:21 
AnswerRe: how do i get the exe reference (dll) files using vb.net Pin
Dave Kreskowiak10-Feb-09 1:51
mveDave Kreskowiak10-Feb-09 1:51 
GeneralRe: how do i get the exe reference (dll) files using vb.net Pin
kvelu.d10-Feb-09 2:14
kvelu.d10-Feb-09 2:14 
GeneralRe: how do i get the exe reference (dll) files using vb.net Pin
Dave Kreskowiak10-Feb-09 3:39
mveDave Kreskowiak10-Feb-09 3:39 
Questionread keyboard wedge scanner in vb.net Pin
Member 37427839-Feb-09 8:05
Member 37427839-Feb-09 8:05 
AnswerRe: read keyboard wedge scanner in vb.net Pin
Dave Kreskowiak9-Feb-09 12:06
mveDave Kreskowiak9-Feb-09 12:06 
AnswerRe: read keyboard wedge scanner in vb.net Pin
Maxwell Barrett10-Feb-09 4:22
Maxwell Barrett10-Feb-09 4:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.