Solved

How Do I Send Data to a Serial Port with VB

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

770 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