You are here:

Qbasic, Quickbasic/reading the serial port fastly


I went from amigabasic to vbdos to qbasic to freebasic and I get by in a primitive unstructured sort of way using fb like qb

I have a project where an external equipment closes dry contacts at random times during the day/week and i want to use the serial port to record the exact time to a hundredth of a second that it happens by writing to a file which I can check later.

I can handle the fb serial port default programming and file writing but what i can't figure out is which pins on the db9 should get connected by the remote contacts so that fb will instantly recognise an externally triggered event to a hundredth of a second which it can then write the full time to a file.

Open Com( options, As[#] filenum ) parameter settings doesn't seem relevant here because of what I want to achieve. Do i just set defaults? Is there a better approach using fb to do this?

A long time ago i found a simple qb program to allow a morse key to trigger a serial port and it was so simple but I lost it and can't figure it out again.

Is this clear as mud?


Sorry for the late reply; this question got buried among all my work emails that I was just able to dig through.  This is somewhat out of my expertise, as I'm a software guy and haven't had the chance to dabble too much on the hardware side of things.  You may have some luck posting to the freebasic or a hardware hackers forum.

As far as using Open Com, I'd start with the default options - if everything works, than you're good to go, and if not, you'll have some ideas about what to tweak.  I suspect you could get away with parity set to "N" and only 1 stop bit, but that's just by best guess.

As far as program structure, you could easily do a loop similar to:

Open Com "COM1:9600,N,,1" As #1
  Dim byte As Byte '' Assuming you're only sending 1 for closed, 0 for open
  Input #1, bytes '' Should block while waiting
  '' Grab a timestamp (however you desire - linux timestamp?)
  If bytes > 0 Then
    '' Write to a file?
  End If
  Sleep 10

This should be fairly close to a 10th of a millisecond, give or take OS processing/timer precision.

You'll probably want to grab the timestamp after the Input statement just in case the write file operation takes a few milliseconds and gives you inaccurate timing information.

Sorry I can't be much more help.

PS: Another thought came to me that you might be able to use Inp().

Qbasic, Quickbasic

All Answers

Ask Experts


Alex Barry


I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, QB64, c/c++, python, lua, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.


I have been programming in *Basic dialects since 2000, as mentioned in my expertise. After a year of QBasic, I learned C and C++, and dabbled a little in ASM (I don't program in ASM - I literally just played around to see how things work). When QB64 and FreeBASIC were released, I played with those languages. At the time, FreeBASIC offered more functionality and I sided with that language for a while. During that time, while I was learning new languages, that I would see what scripting languages are available, where I took up python and lua. I started to notice a staleness to QB64's development (which I kept tabs on from time to time), and am now trying to be active in it's community and maybe in it's development in the future. Currently, I am only active on the forums, but I appear on occasion on's forums as well.

Highschool - 2007

©2017 All rights reserved.