QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: kevin pyle on March 06, 2020, 09:15:57 pm
-
Hi everyone,
I would greatly appreciate help with this problem, as I can't seem to get it to work. The program was originally written in QBASiC, however I've been trying to convert it run in QB64, as I need it for testing a system we are building where I work. The code I'm struggling with is as follows:
OPEN "COM1:9600,N,8,1,RS,CD,DS" FOR RANDOM AS #3
OPEN "ATS2CALD.TXT" FOR OUTPUT AS #2
KEY OFF
'
AGAIN:
PRINT #3, "ATX" + CHR$(13)
INPUT #3, N$
ATSRES$(1) = MID$(N$, 1, 5): ATSRES$(2) = MID$(N$, 10, 5)
ATSRES$(3) = MID$(N$, 19, 5): ATSRES$(4) = MID$(N$, 28, 5)
ATSRES$(5) = MID$(N$, 37, 5): ATSRES$(6) = MID$(N$, 46, 5)
ATSRES$(7) = MID$(N$, 55, 5): ATSRES$(8) = MID$(N$, 64, 5)
ATSRES$(9) = MID$(N$, 73, 5): ATSRES$(10) = MID$(N$, 82, 5)
ATSRES$(11) = MID$(N$, 91, 5): ATSRES$(12) = MID$(N$, 100, 5)
ATSRES$(13) = MID$(N$, 109, 5): ATSRES$(14) = MID$(N$, 118, 5)
ATSRES$(15) = MID$(N$, 127, 5): ATSRES$(16) = MID$(N$, 136, 5)
ATSRES$(17) = MID$(N$, 145, 5): ATSRES$(18) = MID$(N$, 154, 5)
ATSRES$(19) = MID$(N$, 163, 5): ATSRES$(20) = MID$(N$, 172, 5)
ATSRES$(21) = MID$(N$, 181, 5)
ATSRES$(22) = MID$(N$, 190, 5): ATSRES$(23) = MID$(N$, 199, 5)
ATSRES$(24) = MID$(N$, 208, 5)
I understand that the command RANDOM in QB64 has to use GET and PUT, rather than PRINT and INPUT, but I don't understand the syntax of the command.
Thanks
Kev
-
Welcome to the forum kevin,
Sorry I've only used RANDOM with files but I did find this:
https://www.qb64.org/wiki/OPEN_COM
-
This code receives serial data over COM2.
The INPUT$ function has a timeout of about one second for no data received.
-
The loop execution of this code is not blocked by using the INPUT$ function as in the example in my previous post.
The LOC function is used to check if serial data has been received.
-
Here are some useful tools for developing serial port software.
RealTerm
https://sourceforge.net/projects/realterm/ (https://sourceforge.net/projects/realterm/)
Yet Another Terminal (YAT)
https://sourceforge.net/projects/y-a-terminal/ (https://sourceforge.net/projects/y-a-terminal/)
Null-Modem Emulator, com0com
Be sure to download com0com version 2.2.2.0, "com0com-2.2.2.0-x64-fre-signed.zip", rather than the latest version.
https://sourceforge.net/projects/com0com/files/com0com/2.2.2.0/ (https://sourceforge.net/projects/com0com/files/com0com/2.2.2.0/)
The above tools allow one to create a null-modem connection between two virtual serial ports.
The QB64 serial port program being developed is connected to one virtual COM port, and a terminal program is connected to the other.
The program and terminal software can then send data between each other, and so the serial communication can be verified to work properly.