Solved

How to use a coin acceptor in VB

Posted on 2001-06-19
11
1,479 Views
Last Modified: 2010-05-02
I'm now working with a coin acceptor and the comm port.

Using this code i'm able to reciebe the pulses of the acceptor.

Private Sub MSComm1_OnComm()
    Select Case MSComm1.CommEvent
        Case comEvCD  
        msgbox "Pulse"

    End Select
end sub

but it fails with some pulses and don't works at 100% and i have to achieve that every pulse sent by the acceptor is triggered by my program.

I am using this code to initialize the serial port:
   
MSComm1.CommPort = 2
MSComm1.InputLen = 0
MSComm1.Handshaking = comNone
MSComm1.PortOpen = True

I need help about what are the correct parameters to program the Mscomm to receive/send pulses to the acceptor.

I have NO idea about comm programmming and i'm actualing searching info about that :)

Thanks in advance
0
Comment
Question by:MoriQuendi
11 Comments
 
LVL 5

Accepted Solution

by:
gbaren earned 300 total points
ID: 6207657
Mori,

Without handshaking, the events are not reliable. The device you are working with, probably does not support handshaking anyway.

The way to do this is to keep polling the InBufferCount property. When it becomes > 0, that means you had received that many pulses. You access the Input property to clear InBufferCount back to 0.

This should be done in a Timer control's Timer event.


Here's some code to try:


------------------------------------------------
Option Explicit

Private Sub Form_Load()
   
    With MSComm1
        .CommPort = 1
        .Settings = "9600,n,8,1"
        .PortOpen = True
    End With
   
    With Timer1
        .Interval = 100 'poll every 100 milliseconds
        .Enabled = True
    End With
   
End Sub

Private Sub Timer1_Timer()

    Timer1.Enabled = False

    If MSComm1.InBufferCount > 0 Then
        MsgBox "Pulse with data: " & MSComm1.Input
    End If
       
    Timer1.Enabled = True

End Sub

---------------------------------------------------
0
 

Author Comment

by:MoriQuendi
ID: 6209501
Do you think is better to use a timer instead the OnComm event?

well i'll try :)
0
 

Author Comment

by:MoriQuendi
ID: 6209738
Do you think is better to use a timer instead the OnComm event?

well i'll try :)
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 5

Expert Comment

by:gbaren
ID: 6210352
If the OnComm event was more reliable, it would be better to use it. As it is, unfortunately, this is the best way. The MSComm control's OnComm event has never been reliable.
0
 
LVL 3

Expert Comment

by:kfrick
ID: 6221902
I'd start looking at your hardware....the Comm port wants to see about +9 to +12 VDC as an "OFF" signal, and about -9 to -12 VDC as an "ON" signal. You might need to convert some voltage levels to improve the reliability.

I have been using the MSComm control in numerous projects for the last 6 years, and have not run into an OnEvents problem.

Hope this helps!
-kf
0
 

Author Comment

by:MoriQuendi
ID: 6223610
The coin acceptor is manufactured by Jofemar and works with 12V (i'm plugging the acceptor to the computer's power supply directly).

Is there any Comm propertie to take care about? or the default ones works with this device?
0
 

Author Comment

by:MoriQuendi
ID: 6289039
Sorry, i was out for two weeks ad i was unable to continue this task, expect my answer soon ;)
0
 
LVL 5

Expert Comment

by:gbaren
ID: 6289620
Actually, are you sure this is a serial device? Sorry for the silly question, I just want to make sure you have a serial and not a contact closure device.
0
 

Author Comment

by:MoriQuendi
ID: 6316722
This device is not originally developed to be attached to a computer but it have to work.

It seems that it can be a hardware solution:

http://www.cyberzeus.demon.co.uk/page1.htm

There's a device than check when the serial is working or not.


0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139522
Hi MoriQuendi,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Split points between: gbaren and kfrick

MoriQuendi, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Author Comment

by:MoriQuendi
ID: 7139879
I forgot this thread at all, sorry.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Paint/Redraw window while dragging 16 82
VB6 Compile Compatibility Issue 4 115
How to compare ms sql hashbytes results within vb6 5 84
using web browser with BING 40 132
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 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