Solved

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

Posted on 2006-06-29
5
339 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 250 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Report events not being triggered 8 100
find a node in VST 2 47
WMI, model #, retrieving information 10 94
firstChar challenge 13 85
This is an explanation of a simple data model to help parse a JSON feed
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now