Conver Open "Com1" to MSCOMM

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


dmailboxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SidFishesCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dmailboxAuthor Commented:
Fabulous!!! This code is great...and exactly what I needed.  Thank you very much SidFishes!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.