Solved

How Do I Send Data to a Serial Port with VB

Posted on 2002-07-16
4
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I need help formating a date variable in my VB.Net application 2 68
MsgBox 4 71
VBA - If Bookmark = "XXBOOKMARKXX" then 15 50
Dinamic report to Crosstab query 9 49
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

735 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