RS-232 Transmit Issues with VB Express 2010

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
I am trying to communicate with a device using RS-232 and VB Express 2010. I used the program provided by
http://tiktakx.wordpress.com/2010/11/21/serial-port-interfacing-with-vb-net-2010/
http://tiktakx.wordpress.com/2010/11/21/serial-port-interfacing-with-vb-net-2010/
which I got to work and Im able to send and receive data, to an extent. The problem I am having I think is related to a timing issue. When I try to send data like "Example", the device output is showing "Ex??". The problem is also happening
on received data as well. It will cut some of the letters out or show random ASCII characters. Here is the code for the send and receive, can anyone assist me?
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click<br/>
SerialPort1.Write(txtTransmit.Text & vbCr) The text contained in the txtText will be sent to the serial port as ascii<br/>
plus the carriage return (Enter Key) the carriage return can be ommitted if the other end does not need it<br/>
End Sub<br/>
<br/>
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived<br/>
ReceivedText(SerialPort1.ReadExisting()) Automatically called every time a data is received at the serialPort<br/>
End Sub<br/>
Private Sub ReceivedText(ByVal [text] As String)<br/>
compares the ID of the creating Thread to the ID of the calling Thread<br/>
If Me.rtbReceived.InvokeRequired Then<br/>
Dim x As New SetTextCallback(AddressOf ReceivedText)<br/>
Me.Invoke(x, New Object() {(text)})<br/>
Else<br/>
Me.rtbReceived.Text &= [text]<br/>
End If<br/>
End Sub

Thanks,
Carl

View the full article
 
Back
Top