?
Solved

Conver Open "Com1" to MSCOMM

Posted on 2006-04-25
2
Medium Priority
?
871 Views
Last Modified: 2008-03-17
Experts, I am sending data to a barcode printer via the Open "LPT1" structure.  For some reason, which I cannot understand, the code works fine for LPT1, but only works SOMETIMES when the printer is attached to a com port (on some computers I can never get the com ports working....LPT1 always works).  I have tried for numerous hours to figure this out...but I've been unsuccessful.

What I'd like to do now is use the MSCOMM option for all com communication, but I have never used it.  How does one convert the following code to MSCOMM format?  (I now have the license for MSCOMM)

              Open PrnPort For Output As #2      'i.e. LPT1, COM1, COM2...
               
                Print #2, "N"
                Print #2, "q816"
                Print #2, "Q1218,24+0"
                Print #2, "S3"
                Print #2, "D8"
                Print #2, "ZT"
                Print #2, "TTh:m"
                Print #2, "TDy2.mn.dd"
                Print #2, "OD"
                Print #2, "LO2,55,807,12"
                Print #2, "LO6,1112,807,13"
                Print #2, "LO8,1141,805,16"
                Print #2, "LO2,114,807,16"
                Print #2, "LO4,1078,805,18"
                Print #2, "A49,201,0,4,1,1,N,""CARRIER: """
                Print #2, "A35,246,0,4,1,1,N,""LOCATION: """
                     .
                     .
                     .

              Close #2


0
Comment
Question by:dmailbox
2 Comments
 
LVL 36

Accepted Solution

by:
SidFishes earned 500 total points
ID: 16537303
comm ports are slooow so you probably need to add a delay which you can do in code...

Dim PauseTime, Start, Finish, TotalTime

'these will depend on your device settings
MSCOMM2.CommPort = 1
MSCOMM2.Settings = "9600,n,8,1"
MSCOMM2.InputLen = 0
MSCOMM2.PortOpen = True
MSCOMM2.DTREnable = True
MSCOMM2.RTSEnable = False

PauseTime = 3000 '3 seconds

'with a mscomm control on your form called mscomm2

'send command to device
Me.MSCOMM2.Output = "N" & Chr(13) 'string termination may vary by device. check manual.

   'wait 3 seconds
   Start = Timer   ' Set start time.
    Do While Timer < Start + PauseTime
        DoEvents    ' Yield to other processes.
    Loop
    Finish = Timer  ' Set end time.

msgbox Me.MSCOMM2.Input 'answer string from device

'then just continue

Me.MSCOMM2.Output = "q816" & Chr(13) 'string termination may vary by device. check manual.

   'wait 3 seconds
   Start = Timer   ' Set start time.
    Do While Timer < Start + PauseTime
        DoEvents    ' Yield to other processes.
    Loop
    Finish = Timer  ' Set end time.


'close the port
MSCOMM2.PortOpen = False

you may find you can pass the whole string in one shot , "N, q816, Q1218,24+0"

not sure. not done printers only weigh scales.


0
 

Author Comment

by:dmailbox
ID: 16540220
Fabulous!!! This code is great...and exactly what I needed.  Thank you very much SidFishes!!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Implementing simple internal controls in the Microsoft Access application.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

621 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