Click here to Skip to main content
15,920,508 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionMultiple MonthCalendars in a form - does not keep all dates in each textbox Pin
PrissySC10-Mar-13 0:54
PrissySC10-Mar-13 0:54 
AnswerRe: Multiple MonthCalendars in a form - does not keep all dates in each textbox Pin
Eddy Vluggen10-Mar-13 2:44
professionalEddy Vluggen10-Mar-13 2:44 
GeneralRe: Multiple MonthCalendars in a form - does not keep all dates in each textbox Pin
PrissySC13-Mar-13 8:01
PrissySC13-Mar-13 8:01 
QuestionCell grid can change color and down the line in the title ? Pin
Member 24584678-Mar-13 16:40
Member 24584678-Mar-13 16:40 
AnswerRe: Cell grid can change color and down the line in the title ? Pin
Dave Kreskowiak9-Mar-13 3:20
mveDave Kreskowiak9-Mar-13 3:20 
QuestionRemote Desktop Accessing Pin
PDBHONGAON7-Mar-13 1:04
PDBHONGAON7-Mar-13 1:04 
AnswerRe: Remote Desktop Accessing Pin
Richard MacCutchan7-Mar-13 1:38
mveRichard MacCutchan7-Mar-13 1:38 
QuestionSerial Communication Pin
sadeghjun6-Mar-13 5:32
sadeghjun6-Mar-13 5:32 
Hi Friends
I'm working on a project that Read & Write from COM ports.

http://s2.picofile.com/file/7680529565/03_05_2013_11_44_28_%D8%A8_%D8%B8.jpg

But i have some problems!
I define a thread in a Buttom to read from Port in Background because when i send a text to port and other device did'nt send any thing the program become hang!!
therefore :

VB
Dim t As New Threading.Thread(AddressOf Recieve_Data)
t.IsBackground = True
t.Start()


and Recieve_Data():

VB
Sub Recieve_Data()
    While True
        associatedChar = ChrW(SerialPort1.ReadByte)
        RichTextBox2.Text &= SerialPort1.ReadExisting & "    " & CStr(Now) & vbCrLf
        RichTextBox2.SelectionStart = RichTextBox2.TextLength
        RichTextBox2.ScrollToCaret()
    End While

End Sub


but when i run project i receive this error:

http://s3.picofile.com/file/7680529137/03_05_2013_11_43_48_%D8%A8_%D8%B8.jpg


Complete Code is:




VB
'******************************************'
'   UART TOOL V1.00                        '
'   author: Sdaegh Ghafoori                '
'   Email: sadeghghafoori@yahoo.com        '
'   Free to use and change for all!        '
'******************************************'
Public Class Form1

    Dim associatedChar As Char
    Dim ok As Image = Global.SadeghAPP.My.Resources.OK
    Dim err As Image = Global.SadeghAPP.My.Resources.Err
    Dim disconnect As Image = Global.SadeghAPP.My.Resources.Disconnect
    Dim connect As Image = Global.SadeghAPP.My.Resources.Connect
    Dim aboutStr As String = "Author: Sadegh Ghafoori" & vbCrLf & "Version: 1.0.0" & vbCrLf & "March 2013"


    Private Sub ComboComPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComPortNum.SelectedIndexChanged
        SerialPort1.PortName = ComPortNum.Text ' set serial port = selected value of ComPortNum list
        If ComPortNum.SelectedIndex >= 0 Then
            Message.Text = ""           'clear message text
            BaudRateBox.Enabled = True
        End If

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click

        Try
            SerialPort1.Open()
        Catch
        End Try

        If SerialPort1.IsOpen = True Then
            Message.ForeColor = Color.Green         'set message text color
            Message.Image = ok                      'set message image
            Message.Text = "     Device Is Connected !"
            RichTextBox1.Text &= DataTextBox.Text & "    " & CStr(Now) & vbCrLf      'set RichTextBox1 text = DataTextBox text
            RichTextBox1.SelectionStart = RichTextBox1.TextLength       ' this line and the next line are to scroll to new line
            RichTextBox1.ScrollToCaret()                                '
            SerialPort1.Write(DataTextBox.Text)                                    'send DataTextBox Text to device

        Else
            Message.ForeColor = Color.Red         'set message text color
            Message.Image = err                      'set message image
            Message.Text = "     Device Not Connected !"
        End If

    End Sub


    Private Sub ConnectButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConnectButton.Click


        Try
            SerialPort1.Open()
        Catch
        End Try


        If SerialPort1.IsOpen = True Then
            SendButton.Enabled = True
            ConnectButton.Enabled = False
            DisConnectButton.Enabled = True
            ComPortNum.Enabled = False
            BaudRateBox.Enabled = False
            ParityCombo.Enabled = False
            StopBitCombo.Enabled = False
            RichTextBox2.Enabled = True
            RichTextBox1.Enabled = True
            DataTextBox.Enabled = True

            Dim t As New Threading.Thread(AddressOf Recieve_Data)
            t.IsBackground = True
            t.Start()

            Message.ForeColor = Color.Green         'set message text color
            Message.Image = ok                      'set message image
            Message.Text = "     Device Is Connected !"
            PictureBox1.Image = connect
        Else
            Message.ForeColor = Color.Red               'set message text color
            Message.Image = err
            Message.Text = "     Device Not Connected !"
            PictureBox1.Image = disconnect
        End If
        DataTextBox.Select()
    End Sub

    Private Sub DisConnectButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisConnectButton.Click
        PictureBox1.Image = disconnect
        DisConnectButton.Enabled = False
        RichTextBox2.Enabled = False
        RichTextBox1.Enabled = False
        DataTextBox.Enabled = False
        SendButton.Enabled = False
        BaudRateBox.Enabled = False
        ConnectButton.Enabled = False
        ComPortNum.Enabled = True
        SerialPort1.Close()
        Message.ForeColor = Color.Red         'set message text color
        Message.Image = err                      'set message image
        Message.Text = "     Device Disonnected !"
    End Sub


    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BaudRateBox.SelectedIndexChanged
        SerialPort1.BaudRate = BaudRateBox.Text ' set serial port BoudRate = selected value of BaudRateBox list
        If ComPortNum.SelectedIndex >= 0 Then
            Message.Text = ""            'clear message text
            DataTextBox.Enabled = False   '  -
            SendButton.Enabled = False    '   |
            RichTextBox1.Enabled = False  '    > disable or enable objects
            RichTextBox2.Enabled = False  '   |
            ConnectButton.Enabled = False '   |
            StopBitCombo.Enabled = True  '  -
        End If
    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        RichTextBox2.Text = ""
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        RichTextBox1.Text = ""
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        MsgBox(aboutStr)
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopBitCombo.SelectedIndexChanged
        If StopBitCombo.Text = "One" Then
            SerialPort1.StopBits = IO.Ports.StopBits.One
        ElseIf StopBitCombo.Text = "OnePointFive" Then
            SerialPort1.StopBits = IO.Ports.StopBits.OnePointFive
        ElseIf StopBitCombo.Text = "Two" Then
            SerialPort1.StopBits = IO.Ports.StopBits.Two
        End If
        DataTextBox.Enabled = False   '  -
        SendButton.Enabled = False    '   |
        RichTextBox1.Enabled = False  '    > disable or enable objects
        RichTextBox2.Enabled = False  '   |
        ParityCombo.Enabled = True    '  -

    End Sub

    Private Sub ParityCombo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ParityCombo.SelectedIndexChanged
        If ParityCombo.Text = "None" Then
            SerialPort1.Parity = IO.Ports.Parity.None
        ElseIf ParityCombo.Text = "Even" Then
            SerialPort1.Parity = IO.Ports.Parity.Even
        ElseIf ParityCombo.Text = "Odd" Then
            SerialPort1.Parity = IO.Ports.Parity.Odd
        ElseIf ParityCombo.Text = "Mark" Then
            SerialPort1.Parity = IO.Ports.Parity.Mark
        ElseIf ParityCombo.Text = "Space" Then
            SerialPort1.Parity = IO.Ports.Parity.Space
        End If
        ConnectButton.Enabled = True
    End Sub

    Private Sub Recieve_Data()
        While True
            associatedChar = ChrW(SerialPort1.ReadByte)
            RichTextBox2.Text &= SerialPort1.ReadExisting & "    " & CStr(Now) & vbCrLf
            RichTextBox2.SelectionStart = RichTextBox2.TextLength
            RichTextBox2.ScrollToCaret()
        End While

    End Sub

End Class

AnswerRe: Serial Communication Pin
Simon_Whale6-Mar-13 5:45
Simon_Whale6-Mar-13 5:45 
GeneralRe: Serial Communication Pin
sadeghjun6-Mar-13 7:20
sadeghjun6-Mar-13 7:20 
QuestionMSCOMCT2.OCX Compatible problem in win 7(64 bit) Pin
D.Manivelan6-Mar-13 0:46
D.Manivelan6-Mar-13 0:46 
AnswerRe: MSCOMCT2.OCX Compatible problem in win 7(64 bit) Pin
Dave Kreskowiak6-Mar-13 2:06
mveDave Kreskowiak6-Mar-13 2:06 
AnswerRe: MSCOMCT2.OCX Compatible problem in win 7(64 bit) Pin
Just eg8-Mar-13 17:34
Just eg8-Mar-13 17:34 
QuestionCreate Chat integrated with facebook winforms .net Pin
Member 97566055-Mar-13 19:52
Member 97566055-Mar-13 19:52 
AnswerRe: Create Chat integrated with facebook winforms .net Pin
Dave Kreskowiak6-Mar-13 2:09
mveDave Kreskowiak6-Mar-13 2:09 
GeneralRe: Create Chat integrated with facebook winforms .net Pin
Member 97566056-Mar-13 3:30
Member 97566056-Mar-13 3:30 
GeneralRe: Create Chat integrated with facebook winforms .net Pin
Dave Kreskowiak6-Mar-13 6:44
mveDave Kreskowiak6-Mar-13 6:44 
Questionvb 6. compatibility with sql 2012 Pin
Stripelesstiger5-Mar-13 16:55
Stripelesstiger5-Mar-13 16:55 
AnswerRe: vb 6. compatibility with sql 2012 Pin
Dave Kreskowiak5-Mar-13 18:08
mveDave Kreskowiak5-Mar-13 18:08 
GeneralRe: vb 6. compatibility with sql 2012 Pin
Richard MacCutchan5-Mar-13 22:39
mveRichard MacCutchan5-Mar-13 22:39 
QuestionHow to arrange old project files into new project directory architecutre [ solved] Pin
econy5-Mar-13 10:08
econy5-Mar-13 10:08 
AnswerRe: How to arrange old project files into new project directory architecutre Pin
econy5-Mar-13 10:12
econy5-Mar-13 10:12 
QuestionHow can I output the conditional compilation constants to screen [Solved] Pin
econy5-Mar-13 6:56
econy5-Mar-13 6:56 
AnswerRe: How can I output the conditional compilation constants to screen Pin
Eddy Vluggen5-Mar-13 9:37
professionalEddy Vluggen5-Mar-13 9:37 
GeneralRe: How can I output the conditional compilation constants to screen Pin
econy5-Mar-13 10:09
econy5-Mar-13 10:09 

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.