Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Read ASCII stream data directly from port, using VB.net.

Posted on 2006-06-29
5
Medium Priority
?
351 Views
Last Modified: 2012-05-05
Hi,

I am able to receive Data stream using Hyper Terminal and save to a log.txt file. To set up connection in my Hyper Terminal, all I need is the Host Address(IP#) and Port Number.

We want to read in the data stream from the port directly, whithout reading the log, using VB.net Windows program.

Question now is how to read in data, any idea?

Thanks,
Sheldon
0
Comment
Question by:XiaodongYan
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:bpmurray
ID: 17014054
Something like this?

        Dim mySocket As Socket
        Dim myBuffer(1024) As Byte
        Dim BytesRead As Integer

        mySocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        mySocket.Connect("127.0.0.1", 80)

        BytesRead = mySocket.Receive(myBuffer, 1024, SocketFlags.None)

        mySocket.Shutdown(Net.Sockets.SocketShutdown.Both)
        mySocket.Close()
0
 

Author Comment

by:XiaodongYan
ID: 17026886
Tried and it worked! Thank you!

Now, since I have no control on the sender part, which from antenna receiver. I have to receive continue stream of characters.

How do I void missing bytes?

Thanks,
Sheldon
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 17026903
What do you mean? Do you mean somehow flag that some data is missing or do you mean to somehow clean up the stream when some bytes are missing?

I think either of these situations is pretty much impossible - it depends on the data stream and the heuristics you can apply to the data.
0
 

Author Comment

by:XiaodongYan
ID: 17027814
Data in "myBuffer" needs to be saved into a log file.

I mean the possible gap between point 1 to point #2 in the following code.

For n = 0 To 500
      str = ""
      i = 0
      BytesRead = mySocket.Receive(myBuffer, 1024, SocketFlags.None)
' point #1
      Do While myBuffer(i) > 0
           str = str & Chr(myBuffer(i))
           i = i + 1
      Loop
      FilePut(FileNumber, str)
' point #2
Next n


Thanks,
Sheldon
0
 
LVL 15

Accepted Solution

by:
bpmurray earned 1000 total points
ID: 17027993
You can do this more efficiently:

      BytesRead = mySocket.Receive(myBuffer, 1024, SocketFlags.None)
'
      FilePut(FileNumber, str)
        Dim mySocket As Socket
        Dim myBuffer(1024) As Byte
        Dim BytesRead As Integer
        Dim myFile as FileStream

        mySocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        mySocket.Connect("127.0.0.1", 80)
        myFile = File.Open("antenna.log", FileAccess.Create)
        Do While whatever_might_stop_this
             BytesRead = mySocket.Receive(myBuffer, 1024, SocketFlags.None)
             myFile.Write(myBuffer, 0, Bytesread)
        Loop

        mySocket.Shutdown(Net.Sockets.SocketShutdown.Both)
        mySocket.Close()
        myFile.Close()
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Six Sigma Control Plans

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question