Link to home
Start Free TrialLog in
Avatar of Cause
CauseFlag for Ireland

asked on

Reading Data From the Com Port

Hi,
Can anyone give me some sample code on how to read data that is sent to a com port? I have attached a barcode reader to the com port which sends back the barcode value and in my VB i need to be able to read this value.

Can anyone help??

Thanks in Advance
ASKER CERTIFIED SOLUTION
Avatar of bingie
bingie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bingie
bingie

Oops...where as the barcode data is serial bits you should try the following:


Private Sub Form_Load()

'add this to the above form load
timer1.Interval = 50 'change as you see fit. now set to 50 ms
timer1.enabled = False
 
End Sub


Then use the command button to activate the timer and read the data

Private Sub readBarcode_Click()
 timer1.enabled = true
End Sub

Then for the timer

Private Sub Time1_timer()

Do
   Dummy = DoEvents()
   Loop until MScomm1.InbufferCount >=11 'number of bits incoming
   barcode = MSCOMM1.Input 'read the data
   timer1.enabled = false 'stop reading data
End Sub

why not finding a reader that plug within Key board connector,very simple to use...
every program can use it without recode again
Avatar of Cause

ASKER

Thanks bingie  the first went a treat - i was over complicating it. Trying to use the oncomm event - way off!!
Thanks again
No trouble...

But why a B grade?

bingie
Avatar of Cause

ASKER

Firstly, Sorry - I was unaware that the Experts that answered the questions weren't just browsers of the site .i.e. that a person browses the site and if they can answer a question they will do and grading of answers was irrelevant. They obviously spend sometime here helping people like me who are struggling through stuff ļ
Secondly, I simply graded the question with a B because I asked the question and got the answer straight away- bingiwe obviously knew the answer and had dealt with the topic before. Other questions I have asked I have graded the answer with an A because it involved it seemed, alot of hard work/thought from the person giving the answer. I understand now that the grading should be best on whether it helped you or not and not on the difficulty of the question.

I was unaware that the grading might as must to the Experts and will be more careful in future.

I do apologize bingiwe if you were offended!
No offence taken.

It's a simple error. Basically, the amount of question points will dictate the difficulity and the grade the quality of the answer.

So if you wouldn't mind, could I have an A grade?

And if so, Please post a request in Community Support https://www.experts-exchange.com/Community_Support/ for the change. Please include this question URL.

If not, what more help can I offer to change the grade?
An easy way for Code128 barcode; using barcode reader on com1, os=XP, VB6

settings:
 MSComm1.CommPort = 1
 MSComm1.Settings = "9600,n,8,1"
 MSComm1.PortOpen = True
 MSComm1.RThreshold = 1
 Label1.Caption = ""

Private Sub MSComm1_OnComm()
   MSComm1.EOFEnable = True
   barcode = MSComm1.Input
   Label1.Caption = Label1.Caption & barcode   '! auto EOF enabled, new data moved to next line inside Label1
End Sub