Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 754
  • Last Modified:

Read data of a DB9 Serial port

I have a machine that sends data to a DB9 Serial port of my PC.

I want to read this data.

How can i read it?

Thanks in advance.

Regards
0
perfectshark
Asked:
perfectshark
  • 2
  • 2
2 Solutions
 
iHadiCommented:
Hi
The easiest way to read data from the serial port in VB is to use the MS Comm ocx

This component reads from the ports buffer and sends data via the port

See these urls for more information on using this component

http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=31818&lngWId=1&txtForceRefresh=416200514485392287

http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=35458&lngWId=1

Also you can look up the full explanation of this component in the msdn
0
 
imarshadCommented:
Yes iHadi is right.... The best and most reliable method is to use MSComm control of VB6
Go to Project | Components and select "Microsoft Comm Control 6" from the list.... Now add this to your form.....

Private Sub Form_Load()
MSComm1.Settings = "4800,n,8,1"      'Change this to your settings....
MSComm1.CommPort = 1                  'Change this to your port no.
MSComm1.RThreshold=1
     If mscomm1.portopen=false then
        MSComm1.PortOpen = True
     EndIf
EndIf
End Sub

Private Sub MSComm1_OnComm()
    Select Case MSComm1.CommEvent
        Case comEvReceive   ' Received RThreshold # of chars.        
            text1.seltext = MSComm1.Input          
    End Select
End Sub

To run this program you will need a MSComm control and a Textbox on your form.... Please change the multiline property of your Textbox to be true..... This will display what you receive on the comm port in a textbox....

Imran Arshad
0
 
perfectsharkAuthor Commented:
Ok. it works, but it return me "ôññð÷ôüòðòðððó" DATA

What could be the problem?
0
 
imarshadCommented:
>>What could be the problem?

Check the Baud Rate. Try it at 9600 or what the documentation of the machine says.... It could be any standard baud rate between 2400 and 115200...

Imran
0
 
iHadiCommented:
What is the data you are expecting
The machine might be sending machine code (binary code) that appears the way you see it
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now