Solved

How Do I Send Data to a Serial Port with VB

Posted on 2002-07-16
4
160 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

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now