Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send ASCII String to Serial Port?

Status
Not open for further replies.

GDGarth

Technical User
Aug 5, 2000
412
US
How can I send an ASCII string to a serial port in VB 4?

Can I do in in Access '97, using VBA?
 
It seems to me I once saw code that wrote to a serial port using standard file processing statements (Open, Write, and Close). You just have to use the port name (with a trailing colon) as the file path. For example,
Dim iFile As Integer
iFile = FreeFile()
Open "COM1:" For Output As iFile
Write #iFile, "ATDT nnn-nnnn" & vbCrLf
Close #iFile

I could be just imagining this, but if it works, it sure is an easier method than using the Windows commlib. (Make sure you handle errors, though--in case the port is busy.) Rick Sprague
 
I tried your code, but I got an error. It appears as though it is trying to find a file named "Com1:", and that's not a legal file name.

I can't seem to find a command in Visual Basic or VB for Applications that sends a string to a com port. What is the Windows Commlib?

In the past, I've tried to print to the port, but that didn't seem to work, either.

 
That used to work in qbasic...but VBA does not support it,(except for lpt1)...maybe you can adapt a parallel port to read you data?

Also, I think you can pass commands/parameters (to or through)DDE and have DDE access the port.
 
The Windows commlib (not an actual name, just an abbreviation I'm using) is the part of the Windows API that supports accessing the serial communications ports. Like any Windows API, you need to get some documentation of how it works, and then code Declare Function statements to invoke it from VBA code. And like most APIs, its relatively "down to the metal" compared to VB, so you should think of it as a medium-hard programming task.

An excellent resource for using the Windows API is the book "Visual Basic Programmer's Guide to the Windows API" by (I think) Daniel Appleman. This is a "must have" on professional VB and VBA programmers' bookshelves.

I just noticed you said you're using VB4. This forum is for Access only. If you plan to continue seeking information, you need to do so in some other forum.
Rick Sprague
 
I'm using Access 97, but I also have VB 4. I included that in case the necessary commands weren't available in Access.
 
mscomm32 I think it is avaliable for vb5 and up I know I have with vb6
 
I still haven't figured out how to send data to a serial port in Access 97 (or VB 4 for that matter, if I can be forgiven for mentioning that on the Access board). Neither of the above have "MSCOMM" anywhere that I can find.

I am able to do it in QuickBasic, then shell out to send the data, but that seems like a clumsy way to make it happen.

Since I'm generating the data in an access database, I'd like to be able to send it directly from there.

 
Hello

I have also been trying to use a serial RS-232 port through Access 97 to read an instrument directly in a table.
I was checking answers to your post, and I have been searching the web quite a lot these last days, and it seems that VBA has no control to do that like MSCOMM in VB6, so the solutions would be (as far as I understood) :
- use APIs functions, seems difficult
- or write one's own control in VB6 to use it in VBA, I just found that somebody did it for us and it is a freeware. Have a look there :
I am going to try that

If anyone has a better way to do that let us know!

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top