Image Map Image Map
Results 1 to 6 of 6

Thread: Qbasic: Raw binary output to COM port

  1. #1

    Default Qbasic: Raw binary output to COM port

    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?

  2. #2

    Default

    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.

  3. #3
    Join Date
    Jun 2016
    Location
    Guisborough, England
    Posts
    191

    Default

    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

  4. #4

    Default

    If it works fine, if not you can use the outport addr, value.
    Dwight

  5. #5

    Default

    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.

  6. #6

    Default

    Quote Originally Posted by GeoffB17 View Post
    You were mixing up the syntax for two different file modes.
    Thanks for clearing that up.

    Quote Originally Posted by GeoffB17 View Post
    As for 'Knocked Up', I'm quite fond of that movie...
    Briefly OT: If you like that one, try finding a copy of 'The Ugly Truth'. (Katherine Heigl again).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •