Author Topic: A functionaity wish for the next version of QB64  (Read 2927 times)

0 Members and 1 Guest are viewing this topic.

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
A functionaity wish for the next version of QB64
« on: December 20, 2020, 12:07:39 am »
Is there a wish list for the next version of QB64?

If so, I strongly want to add: Please remove this restriction

"Currently, QB64 only supports OPEN FOR RANDOM access using the GET/PUT commands in BIN mode."

I set out to convert this beautifully simple old BASIC program, which uses text strings for input and output , that I want to re-purpose:

Code: QB64: [Select]
  1. OPEN "COM2:9600,N,8,1" FOR RANDOM AS 1
  2. PRINT #1, "I0"
  3. INPUT #1, A$
  4. INPUT #1, A$
  5. PRINT "Input Status: "; A$
  6. PRINT #1, "R"; A$
  7. INPUT #1, A$
  8. PRINT #1, "S0"
  9. INPUT #1, A$
  10. INPUT #1, A$
  11. PRINT "Relay Status: "; A$
  12.  

... but QB64 won't allow use of INPUT and PRINT for random (i.e. I/O) mode, requiring me to use binary (byte) mode , GET  and PUT, whereas I'd love to be able to use string mode -- the application I'm working on sends long ASCII strings back and forth on the same port and dealing with them byte by byte is unnecessarily laborious.

And while I'm on the subject, I'd love to see this good old and nicely simple QBasic COM port functionality implemented, too:

Code: QB64: [Select]
  1. COM(1) ON       'Enable event trapping on port 1.
  2. ON COM(1) GOSUB ComHandler
  3. COM(1) OFF
  4.  
  5. ComHandler:
  6.   PRINT "Something was typed at the terminal attached to COM1."

Maybe it doesn't have to use GOSUB -- CALL would be fine.
« Last Edit: December 20, 2020, 12:50:13 am by GTC »

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: A functionaity wish for the next version of QB64
« Reply #1 on: December 20, 2020, 02:09:50 am »
you can still use string values with GET\PUT on a com port. like in this example of mine,

Quote
you need to use GET #, and PUT # when communing with the COM ports with QB64

little example from my robotics control, controlling a remote fired static mounted firearm.
in Simulation it, sends fire command PUT #1, and checks weapon status with GET #1 over and over checking for weapon jam, ammo depleted and weapon mounting secured.

Code: QB64: [Select]

        OPEN "COM1:9600,N,8,1,BIN,CS0,DS0" FOR RANDOM AS #1
        B1 = 197 'Command byte
        B2 = 21 'Motor control byte \ Trigger solenoid
        B12$ = CHR$(B1) + CHR$(B2)
        PUT #1, , B12$
        DO
         PUT #1, , B12$
         _DELAY .03
         GET #1, , B3~%% 'did bolt return to fire pos?
         GET #1, , B4~%% 'is the magazine at empty pos?
         GET #1, , B5~%% 'is front and rear mount switch still down?
         LOCATE 1, 1: PRINT B3~%%
         PRINT B4~%%; B5~%%
        LOOP UNTIL INKEY$ = CHR$(27)
        CLOSE
 

now I do indeed use GET with _UNSIGNED _BYTEs, but I could just as easily get a STRING variable too, as I do with the PUT statement.
Granted after becoming radioactive I only have a half-life!

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Re: A functionaity wish for the next version of QB64
« Reply #2 on: December 20, 2020, 02:54:48 am »
Yeah, that works. (Imagine thumbs up emoticon here).

I tried something similar earlier and was getting record length fatal errors. Must have been overthinking it.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A functionaity wish for the next version of QB64
« Reply #3 on: December 20, 2020, 06:35:46 am »
Basically, all you need is to add two simple functions to your code:


SUB fakePRINT (where, what$)
    PUT #where, ,what$ + CHR$(10)
END SUB

SUB fakeINPUT (where, what$)
    what$ = “”
    DIM b AS _UNSIGNED _BYTE
    DO
         GET #where, , b
         IF b = 10 THEN EXIT SUB
         IF b <> 0 THEN what$ = what$ + CHR$(b)
         _LIMIT 10
    LOOP
END SUB

PRINT and INPUT are basically nothing more than CRLF-terminated strings.  Just write a quick routine to add a terminator to your code, and look for that value in your input loop, until you find it.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!