简体   繁体   中英

Looping through serial port (COM port) in VB.NET and detect the correct port which is used by device

Ok let me give you the details of the software and applications i am using:

  • Windows 7 Professional Edition
  • Microsoft Visual Studio Ultimate 2010
  • VB.NET
  • .NET 4.0 Framework

My device is a simple data transmitter device which gets data inputted by the user like, name, age, gender and then it is transmitted to the PC software.

I already have the source code of the PC software which is in C# and i am a VB guy. I have gone through many tutorials on internet to learn serial port communication but i think maybe i am unable to get the logic or maybe that was not the right thing for my project. SO i need help from you people.

i have searched a lot on internet and found few resources which explains, how exactly i can communicate with serial ports, but none of these are working for me:

  1. COM port made simple with VB.NET
  2. Serial Port Communication in VB.NET
  3. Serial Port Interfacing with VB.net 2010
  4. Serial COM Port Communication

The previous software use to scan all available IO PORTS and Evaluates the incoming data from the serial ports. Finally, it detects the device on the basis of this data.

The Software is set for BaudRate = 19200 DataBits = 8 StopBits = StopBits.One Encoding = Encoding.GetEncoding(1252) DataReceived += new SerialDataReceivedEventHandler(portDataReceived)

However with the tutorials i understood the terminologies specified here, but how to exactly communicate with the device and to check which port is the correct one is still a question.

So what i understood is required for me is to:

  1. Loop through all available communication ports
  2. Receive the data being sent by them
  3. Then analyze that data and match with the standard data of the source code (provided to me)
  4. And if the correct port is recognized then start receiving data from it.

What i need is an insight of you people on exactly what resource is required as i have been searching and reading for a long time and could not able to get exactly what i am looking for. Maybe i am unaware with the logic and the topic, so if the right resource is visible still i am ignoring it. Its just that i am a newbie in Serial Port communications.

Also, maybe there are many other question that you may require from my side to help me with this question and i have not produced you. So please let me know what all information you need from me, i will be try to get you if i can.

EDIT-1

I have used an Port Monitoring Software which gave me this raw data and it thrilled me...

在此处输入图片说明

What you propose (opening each port and attempting communication) is exactly what you need to do.

There is no standard way of doing this. It depends on the device. Nobody can tell you how to do this without knowing the protocol used to communicate with your device. There is nothing special about a serial port... it just sends and receives data. The protocol implementation is up to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM