• Please review our updated Terms and Rules here

Qbasic: Raw binary output to COM port

SiriusHardware

Veteran Member
Joined
Feb 15, 2014
Messages
815
Location
UK
I have an application in which I need to output some 8-bit non-ASCII characters to COM1: on a DOS PC with Qbasic V4.5.

I've knocked up the following code but it looks (on a scope) as though there is more than just the single desired character coming out through the COM port, possibly automatically appended CR / LF? At this time I unfortunately do not have a null-modem cable, nor do I have a storage scope so what I'm seeing, with the port continually transmitting, is what appear to be at least two different byte values alternating. What I want to see is the same single byte being sent over and over again.

This is the little bit of test code I am using: Ignore the test value of 128 in this example, it is just that, an example. I need to be able to send any single byte with a value in the range 0-255, and without auto-appended CR/LF or any other characters.

Code:
char1$=CHR$(128)

OPEN "com1: 9600,N,8,1,bin,cs0,ds0" FOR OUTPUT AS #1

start:
PUT#1,,char1$

GOTO start:

It's years, possibly decades, since I last tried to write anything in Qbasic. If the example above is not the correct way to output single raw binary bytes, what is?
 
Ok, I think I may have managed to answer my own question. If I use PRINT #1 that allows me to put a semicolon, which traditionally means "don't auto-append a CR/LF" after the value being printed.

Like this:

Code:
char1$=CHR$(128)

OPEN "com1: 9600,N,8,1,bin,cs0,ds0" FOR OUTPUT AS #1

start:
PRINT #1,char1$;

GOTO start:

...Now the code only seems to be sending the character I want it to.

Oh, by the way, the expression 'knocked up' means 'threw together' on this side of the pond. ;)
 
You were mixing up the syntax for two different file modes.

I've checked my manual for QB 4.0, which is prob much the same for 4.5.

Your first version prob could have worked if you'd used 'FOR RANDOM' instead of 'FOR OUTPUT', but then you'd have needed the FIELD and LSET commands as well, but then the PUT would have been OK.

The second version is now consistent for sequential file operation.

As for 'Knocked Up', I'm quite fond of that movie, although not particularly Seth Rogan!

Geoff
 
Really? Wow, it's been so long since 8/16 bit computers and early PCs let us go straight to the hardware, I had not even considered that possibility.

I take it you mean

Code:
OUT &03F8,value

...assuming that the base address (03F8 on the machine in question) happens to be the COM1 UART data register?

The PRINT approach I mentioned above works so that will probably be the better option as it removes the onus on the Qbasic program to know which physical address COM1: is set for.
 
Back
Top