serial port
serial port
serial port
serial port
serial port
serial port serial port serial port serial port serial port serial port serial port serial port
serial port serial port
serial port
Go Back  Xtreme Visual Basic Talk > > > serial port


Reply
 
Thread Tools Display Modes
  #1  
Old 09-03-2006, 12:37 PM
wence wence is offline
Newcomer
 
Join Date: Sep 2006
Posts: 10
Default serial port


1)wanting to send command A0 0D in hex, is it correct to write this way?

Dim byte1() As Byte = New Byte() {&H61, &H30, &H20, &H30, &H44}
serialport1.write (byte1, 0, 5)

2) if i want to click on a button, and let it sends multple commands line by line, can i do this?
Dim byte1() As Byte = New Byte() {&H61, &H30, &H20, &H30, &H44}
Dim byte2() As Byte = New Byte() {&H68, &H31, &H22, &H37, &H47}
serialport1.write (byte1, 0, 5)
serialport1.write (byte2, 0, 5)
Reply With Quote
  #2  
Old 09-06-2006, 07:17 AM
shaul_ahuvaserial port shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

If you want to send text, you could just use SerialPort1.Write("A0 0D").

When you say line-by-line, do you mean lines of codes or commands ended by a carriage-return/line-feed?
Reply With Quote
  #3  
Old 09-07-2006, 09:18 AM
wence wence is offline
Newcomer
 
Join Date: Sep 2006
Posts: 10
Unhappy Reading serial port

Hi thanks for your reply..i've managed to write to serial port, now that i'm facing problems with reading data from serial port.
Im sending out a command to the analyzer, and start reading. characters appears continously but i still cant read as its in ascii.
this is what i wrote:



Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

SerialPort1.WriteLine(Chr(82) & Chr(51) & Chr(13) & vbCrLf)

End Sub


Private Sub DataReceived( _
ByVal sender As Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles SerialPort1.DataReceived

TextBox3.Invoke(New _
myDelegate(AddressOf updateTextBox3), _
New Object() {})
End Sub

Public Delegate Sub myDelegate()

Public Sub updateTextBox3()
With TextBox3
.Font = New Font("Garamond", 12.0!, FontStyle.Bold)
.AppendText(SerialPort1.ReadExisting & vbCrLf)
.ScrollToCaret()
End With
End Sub

here're my questions:
1)Im new to VB.net, im confused what invoke and delegate do?
2)how to convert my data read from port which is in ascii into decimal?
3)how can i read more about the dataReceived class?
4)the incoming data is running such as in an overflow state, but i want it to appears as a continuously changing figure.










Quote:
Originally Posted by shaul_ahuva
If you want to send text, you could just use SerialPort1.Write("A0 0D").

When you say line-by-line, do you mean lines of codes or commands ended by a carriage-return/line-feed?
Reply With Quote
  #4  
Old 09-07-2006, 10:10 AM
shaul_ahuvaserial port shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

1: Delegates are basically function pointers (the address of a function in memory) - they are used to dynamically call functions. The Control.Invoke method marshals a method call to the UI thread (updates to the user interface should only be done from the UI thread).
2: Decimal.Parse
3: You mean the SerialPort.DataReceived event? You can look it up on MSDN (search for SerialPort.DataReceived).
4: If I'm understanding the question, then just replace the text in the textbox (don't append to it).
Reply With Quote
  #5  
Old 09-08-2006, 02:07 AM
wence wence is offline
Newcomer
 
Join Date: Sep 2006
Posts: 10
Default Rs232

Thanks for replying, ill try on it. ive few other questions which are:
1)how to save the incoming data from serial port to textfile inside certain folder?
2)the incoming data is changing in real time, how to display the data in a real time graph.

Im using VB 2005 Express.



Quote:
Originally Posted by shaul_ahuva
1: Delegates are basically function pointers (the address of a function in memory) - they are used to dynamically call functions. The Control.Invoke method marshals a method call to the UI thread (updates to the user interface should only be done from the UI thread).
2: Decimal.Parse
3: You mean the SerialPort.DataReceived event? You can look it up on MSDN (search for SerialPort.DataReceived).
4: If I'm understanding the question, then just replace the text in the textbox (don't append to it).
Reply With Quote
  #6  
Old 09-12-2006, 08:36 AM
aghost_d aghost_d is offline
Newcomer
 
Join Date: Sep 2006
Posts: 1
Default

i'm also having same problem with wence... i'm currently working with at command
I can send at command to my mobile phone via serial port, but i cant read data from serial port..
i use serialport1.readexisting, but got nothing..
if i use serialport1.readline(), the program stop responding..
i also use SerialPort.DataReceived, but nothing happen if i send and at command like "at+cbc?" or "at+cmgl=1"

i'm very confused...
thanks
Reply With Quote
  #7  
Old 09-13-2006, 02:28 PM
gnappi gnappi is offline
Freshman
 
Join Date: Mar 2006
Posts: 33
Default

Quote:
Originally Posted by aghost_d
i'm also having same problem with wence... i'm currently working with at command
I can send at command to my mobile phone via serial port, but i cant read data from serial port..
i use serialport1.readexisting, but got nothing..
if i use serialport1.readline(), the program stop responding..
i also use SerialPort.DataReceived, but nothing happen if i send and at command like "at+cbc?" or "at+cmgl=1"

i'm very confused...
thanks
I follow these serial port / modem posts with interest. Long ago I wrote a number of programs for the serial port and modem, and with very few lines of code you could do most anything with Basic, or Pascal. Jeez after building an assembly toolkit to include it was even not so hard in assembler :-)

Why should opening a port, sending data, receiving it be such a chore? You'd think that I/O were some ******* child of MS who wants it to go away!


Regards,

Gary
Reply With Quote
  #8  
Old 09-14-2006, 09:10 PM
shaul_ahuvaserial port shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

wence:
1) Use classes in the Sytem.IO namespace such as the FileStream or StreamWriter to write to a text file.
2) Either buy a graphing/charting package or create your own - there are plenty of offerings if you search for them.

gnappi:
I don't think it's a chore - the user just needs to have an understanding of how the desired device communicates (i.e. what commands it's expected and what it will send in response).
Reply With Quote
  #9  
Old 09-19-2006, 10:01 AM
wence wence is offline
Newcomer
 
Join Date: Sep 2006
Posts: 10
Default

Can I have some comments regarding the codes below. Where the mistakes are? and how to append read data to textbox?


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


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

Try
With SerialPort1
.PortName = "COM1"
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.Two
End With
SerialPort1.Open()

Catch ex As Exception
MsgBox(ex.ToString)
End Try


End Sub

Dim WithEvents SerialPort As New System.IO.Ports.SerialPort
Dim rxbyte As New ArrayList
Dim i As Integer

Public Delegate Sub myDelegate()

Public Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As _
System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

If SerialPort1.BytesToRead > 0 Then
Do
rxbyte.Add(SerialPort1.ReadByte)

TextBox1.Invoke(New myDelegate(AddressOf updateTextBox1), _
New Object() {SerialPort1.ReadByte})

Exit Do
Loop
End If
End Sub

Public Sub updateTextBox1()

With TextBox1
.AppendText(rxbyte(i))
End With

End Sub


End Class
Reply With Quote
  #10  
Old 09-19-2006, 12:41 PM
shaul_ahuvaserial port shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

I don't see anything that would cause a problem in the code you posted; what problems are you having?

Also, you can use [vb][/vb] tags to format the code and make it much easier to read
Reply With Quote
  #11  
Old 09-20-2006, 03:08 PM
wence wence is offline
Newcomer
 
Join Date: Sep 2006
Posts: 10
Default re:

Quote:
Originally Posted by shaul_ahuva
I don't see anything that would cause a problem in the code you posted; what problems are you having?

Also, you can use [vb][/vb] tags to format the code and make it much easier to read

I read nothing at all fr the text box. well im trying to figure out where my problems are
Reply With Quote
  #12  
Old 09-20-2006, 09:30 PM
shaul_ahuvaserial port shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

Is the DataReceived event being raised? If so, what happens if you call "ReadExisting" instead of "ReadByte"?
Reply With Quote
  #13  
Old 09-22-2006, 06:10 AM
wence wence is offline
Newcomer
 
Join Date: Sep 2006
Posts: 10
Default reading data

Quote:
Originally Posted by shaul_ahuva
Is the DataReceived event being raised? If so, what happens if you call "ReadExisting" instead of "ReadByte"?

I wrote it this way still doesnt work:
Code:
Public Delegate Sub stringsubpointer(ByVal buffer As String)

    Dim WithEvents SerialPort As New System.IO.Ports.SerialPort

    Public Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As _
        System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

        Dim RXString As String = SerialPort1.ReadLine
        TextBox1.BeginInvoke(New stringsubpointer(AddressOf Display), RxString)


    End Sub

    Private Sub Display(ByVal Buffer As String)

        TextBox1.AppendText(Buffer)

    End Sub
I have a question here, from my device manual, i read something about reading output level. But i dont know how to write the command for the reading event to work..hereby i include the word document url for reading fr the device. i wonder it affects the data reading or not>?
http://www.geocities.com/sandrea83/3...32commands.doc
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
serial port
serial port
serial port serial port
serial port
serial port
serial port serial port serial port serial port serial port serial port serial port
serial port
serial port
 
serial port
serial port
 
-->