Solved

How Do I Send Data to a Serial Port with VB

Posted on 2002-07-16
4
157 Views
Last Modified: 2010-05-02
I'm need to open a serial port, and send data to it with Visual Basic (specifically from Access 97's built in visual basic). What is the easiest way to do this? I will be sending a single character to open a serial cash drawer, so I need very little error checking or anything like that, just need quick & dirty code ;) Thanks for anyone that can help.
0
Comment
Question by:wrussell051197
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
rspahitz earned 200 total points
ID: 7157611
This is quick and dirty:

open "Com1:" for output as #1
print #1, byt;
close #1

--
better code:

private sub SendRegisterCode(CodeToSend as string)
   dim iFileNum as integer

   const cCommPort as string = "COM1:"

   iFileNum = freefile()
   open cCommPort for output as #iFileNum
   print #iFileNum, CodeToSend ;
   close #iFileNum
end sub
0
 
LVL 3

Expert Comment

by:PNJ
ID: 7159199
You can use the comm port OCX - MSCOMM32.OCX. Add this to the components and drag it onto a form, call it "comRegister". Set the properties (port, baud rate etc) at design or run time and then use "comRegister.Output = "code"
0
 

Author Comment

by:wrussell051197
ID: 7170070
Quick and dirty worked great! Just a note to anyone wanting to use this code for the purpose I did (i.e. opening a cash drawer). You must change the flow control on the port in the device manager to "Hardware" for it to work properly.

Thanks a bunch rspahitz!
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7170105
Glad to help.  Thanks for the "A".
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now