Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SerialPort get less byte

Status
Not open for further replies.

selimsl

Programmer
Aug 15, 2005
62
TR
Hello everyone,

I am writing a program which communicates with a device(Energy Meter) via com port of my computer. I am using a RS232/RS485 converter. Because the device that I want to communicate with only supports RS485 communication media.
I have two different brand of converters
1) Moxa converter
2) Evir converter (a very cheap converter)

and I have two programs to communicate with Energy Meter
1)My program that I am writing in VB.NET
2)MBPoll (A program that I've downloaded from internet)

MBPoll can communicate with Energy meter if I use Moxa converter or Evir converter

But

My program can communicate with Energy meter if I use Moxa converter. If I use Evir converter it doesnt communicate. I get everytime less byte then expected. Do you have any Idea why I get less bytes when I use Evir converter. Evir converter is a cheap converter with low quality but MBPoll converter can communicate with it, so something should missing in my code .

Here is my code
Code:
     Private Sub DataReceivedEventHandler(ByVal sender As Object, ByVal e As IO.Ports.SerialDataReceivedEventArgs) Handles objSerialPort.DataReceived
        '**************************************

        Dim spTemp As SerialPort = CType(sender, SerialPort)
        Do While (spTemp.BytesToRead > 0)
            strInputBuffer &= spTemp.ReadExisting
        Loop


        '**************************************
        Dim strReturn As String
        strReturn = strInputBuffer
        '**************************************
        Dim strTemp As String = String.Empty
        For intTemp As Integer = 0 To strReturn.Length - 1
            strTemp &= Hex((Decoder(strReturn.Substring(intTemp, 1), 1252))).PadLeft(2, Chr(48))
        Next
        strReturn = strTemp
    End Sub

Thanksss in advance ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top