QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: GTC 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:
PRINT "Input Status: "; A$
PRINT "Relay Status: "; A$
... 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:
COM(1) ON 'Enable event trapping on port 1.
ComHandler:
PRINT "Something was typed at the terminal attached to COM1."
Maybe it doesn't have to use GOSUB -- CALL would be fine.
-
you can still use string values with GET\PUT on a com port. like in this example of mine,
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.
-
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.
-
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.