Solved

Mscomm in access 2007

Posted on 2013-01-21
7
1,344 Views
Last Modified: 2013-02-22
Back in access 2000 had wrote a database for a collecting live data from a scale.  Now I need to collect date and have it run process when someone scans a barcode.  I have a rs232 barcode scanner but I don't know how to program this new mscomm control.  here is my code so far.

   With mscomm1
            .CommPort = 1
            .Handshaking = 2 - comRTS
            .RThreshold = 1
            .RTSEnable = True
            .Settings = "9600,n,8,1"
            .SThreshold = 1
            If .PortOpen = True Then
            .PortOpen = False
            End If
            .PortOpen = True
       
             mscomm1.Output = Me.test
    End With

When I open the form it says the port is open already so I thought i could check if it was open and close it so it would be opened when I wanted it to.  Also I need the oncomm event so the scanner triggers printing things out.

Andy help would be great thanks.
0
Comment
Question by:fasse
  • 4
  • 3
7 Comments
 
LVL 57
ID: 38802928
<<I have a rs232 barcode scanner but I don't know how to program this new mscomm control. >>

 Check the scanner Mfg's web site.  They often have VB 6.0 or VBA examples.  Very often you can almost drop code right in.

 Also, even rs232 scanners often come with a driver and you talk to the driver rather then talking directly to port.  Most newer scanners are this way, especially if they are USB based.

 If you need more, post the scanner model and mfg.

Jim.
0
 

Author Comment

by:fasse
ID: 38807679
It is a Honeywell Voyager 9500 232
I called them and they said they have not sample code so I have been trying to piece this together.

Here is the code I have so far.

Private Sub Form_Load()
   
         With NETComm0
            .CommPort = 1
            .Handshaking = 2 - comRTS
            .RThreshold = 1
            .RTSEnable = True
            .Settings = "9600,n,8,1"
            .SThreshold = 1
        If .PortOpen = True Then
        .PortOpen = False
        Else
        End If
         End With
         Me.test = "worked"
      End Sub
   
   
    Private Sub netComm0_OnComm()
    Dim something As String
   
    something = NETComm0.InputData
   
    End Sub


Private Sub Form_Unload(Cancel As Integer)
If NETComm0.PortOpen = True Then
NETComm0.PortOpen = False
Else
End If

End Sub
0
 
LVL 57
ID: 38809843
This should be helpfull:

INFO: Receiving Data Using the MSComm Control's OnComm Event
http://support.microsoft.com/kb/194922

If you look at the article, you'll see your most of the way there already.  The code for the OnComm event should drop right in from the article.

 Let me know where that gets you...

Jim.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:fasse
ID: 38810924
I will give it a try.
0
 

Author Comment

by:fasse
ID: 38811478
I have it working except for 2 problems.  The code will return nothing to the test text box I have on the form unless I have the code stopping at end sub.  If I do that and keep hitting the stop button to reset the code I get an output on the form.  

2nd is the barcode scanner does not read the same amount every time.  One time it may ready a sting length of 3 next time it may ready 30.  I thought if I closed the port then opened it and cleared the buffer it would fix the buffer problem but did not help. My string should be something like this F569375.0 but I will get (.0  F569375.0  F569375.0 F569375) with little squares in the spaces

Also I find that it is storing the read then sending it to the computer on the next time.  so i have the code stop and scan a couple of barcodes it will not send those until i reset the code and read another code.  Problem with that is that is does not send the one it just read it send the other two it read before.  It is like it is not sending real time scans.

I am at a lose.

Private Sub netComm0_OnComm()
         Dim InBuff As String
         Dim fixed As String
         Me.test = ""
           
         InBuff = NETComm0.InputData
         fixed = InBuff
         Me.test = ""  ''used this to clear text box to verify inputdata
         Me.test = fixed
         
         NETComm0.PortOpen = False
         NETComm0.PortOpen = True
         NETComm0.InBufferCount = 0
         NETComm0.OutBufferCount = 0
         

             
    End Sub
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 38814345
<<I have it working except for 2 problems.  The code will return nothing to the test text box I have on the form unless I have the code stopping at end sub.  If I do that and keep hitting the stop button to reset the code I get an output on the form.  >>

 Sounds like the scanner is sending data rapidly.  In your code, you have:

         Me.test = ""  ''used this to clear text box to verify inputdata
         Me.test = fixed

So each receipt of data is causing the text box to clear.

 As a test, only clear you text control on the form open. Also setup a button to clear it manually.

 Then, in your comm receive, do this:

   Me.Test = Me.test & fixed

I think you'll find you now receive what you expect.

<< One time it may ready a sting length of 3 next time it may ready 30. >>

  That's the way serial communications works.  You need to take the incomming data and buffer it (like I said above) until you know the messsage is complete (ie. you encounter a specific character, say a carriage return or a null).

  All scanners are programmable to send either a prefix sequence, a suffix sequence, or both to let you know when a scan starts and stops.  But that scan may come in in one or more parts.  You need to assemble it.

<<Also I find that it is storing the read then sending it to the computer on the next time.  so i have the code stop and scan a couple of barcodes it will not send those until i reset the code and read another code.  Problem with that is that is does not send the one it just read it send the other two it read before.  It is like it is not sending real time scans.>>

 I think part of the problem here is how you thought it was working.  Put the buffering in place first as I suggested above with the control (latter you can do it in a variable) so you can see what is coming in.  Keep in mind though that by displaying it in a control, non-visible characters may not be obvious.

 Then work on the programming of the scanner and set a prefix and suffix sequence that would not appear as part of the data. Often one uses either a carriage return or a tab character for the suffix, because that would automatically move the focus in Access to the next control.

  However since this is RS232, you need to do all the work.  Having a suffix character of a CR or tab is not going to do anything in this case.   With other types of scanners, the data appears as if it came from the keyboard and Access reacts without effort on your part, which makes it easy.

 You code then can look for these sequences and know what data is part of each scan.

 The final piece is that when you process a scan, you'll want to get rid of anything the gun has and is continuing to send, which you'll do by continuing to receive data, but ignoring some of it.

 In other words, you always want to be accepting data in the comm event as it comes in and decide what to do with it after you have it.

  Think of the comm event as a process that continually needs to run in the background.  You take the data from that, put it somewhere (a variable or text control) and then work with it from there.

Jim.
0
 

Author Closing Comment

by:fasse
ID: 38920542
I didn't get it figured out but the project moved in a different direction.  I appreciated the help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

867 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

12 Experts available now in Live!

Get 1:1 Help Now