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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serial port communications via file I/O 1

Status
Not open for further replies.

KornGeek

Programmer
Aug 1, 2002
1,961
US
I am upgrading an app from QBasic to VB6. This program interfaces with some hardware across a serial port and needs to send commands and receive data back.

In QBasic, this we did this by open the comport as a file in Random mode, and then used input and print commands to communicate with this file.

In VB6, my old code doesn't work. When a file is opened as Random, print and input are no longer supported. I looked at using put and get, but found that with strings, put is appending string length to the front of the output.

I next tried opening the file in Binary mode, and I was able to send data out the comm port succesfully (yippee!), but I'm now having trouble receiving data. In QBasic, I used the Loc function to determine how many bytes were in the buffer so I could determine if I should read the data or wait (or timeout, etc.). I have tried using both LOC and LOF under VB6, but they don't seem to be seeing any data in the buffer.

When I switch to Hyperterminal, communications work correctly, so I've ruled out the com port, cable, etc.

At this point, I would like to know how to determine how many bytes are in the buffer, as that would result in the fewest changes to my code. However, I'm open to just about any suggestion as to how I might get this to work. I've seen reference to MSComm, but I do not have this on my machine.

Thank you for your time. I appreciate whatever guidance you might offer.
 
MSComm control (microsoft comm control 6 MSCOMM32.OCX) ships as standard with VB6 enterprise and professional.

i imagine thats the way forward.

(i didnt know you could use file I/O with Com ports-learn somethin new every day)

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
ADoozer,
I guess I was mistaken. I do have the MSComm control after all. I'm making progress now. Thank you very much.

I'm glad I was able to teach you something also. Unfortunately though, it looks like this functionality is no longer supported, so the knowledge you gained isn't very valuable. If you ever go back to QBasic, I know it works there.
 
i have a couple of QBasic game in the office (gorilas and a kind of snake game) ill make sure i read the code for it. learn me some new(old) stuff!

cant hurt!

good luck with MSComm, watch out for the inbuffercount it can be deceiving (personal experiance)!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top