Solved

How Do I Send Data to a Serial Port with VB

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses
Course of the Month7 days, 13 hours left to enroll

632 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