Author Topic: Com Port Issues  (Read 3364 times)

0 Members and 1 Guest are viewing this topic.

Offline kevin pyle

  • Newbie
  • Posts: 1
    • View Profile
Com Port Issues
« 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


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Com Port Issues
« Reply #1 on: March 06, 2020, 10:02:16 pm »
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


« Last Edit: March 06, 2020, 10:07:25 pm by bplus »

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Com Port Issues
« Reply #2 on: March 07, 2020, 03:27:33 am »
This code receives serial data over COM2.
The INPUT$ function has a timeout of about one second for no data received.

Code: QB64: [Select]
  1. OPEN "COM2:9600,N,8,1" FOR BINARY AS #f%
  2.     N$ = INPUT$(1, f%)
  3.     PRINT TIMER;
  4.     IF N$ = "" THEN
  5.         PRINT " NO DATA"
  6.     ELSE
  7.         PRINT " " + N$
  8.     END IF
  9. CLOSE #f%
  10.  

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Com Port Issues
« Reply #3 on: March 07, 2020, 03:50:47 am »
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.

Code: QB64: [Select]
  1. DIM ByteIn AS STRING * 1
  2.  
  3.  
  4. OPEN "COM2:9600,N,8,1" FOR RANDOM AS #f%
  5.  
  6.     IF LOC(f%) <> 0 THEN
  7.         GET f%, , ByteIn
  8.         PRINT ByteIn;
  9.     ELSE
  10.         PRINT TIMER, "No Data"
  11.     END IF
  12.     _DELAY (0.1)
  13.  
  14.  

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Com Port Issues
« Reply #4 on: March 07, 2020, 06:48:13 am »
Here are some useful tools for developing serial port software.

RealTerm
https://sourceforge.net/projects/realterm/

Yet Another Terminal (YAT)
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/

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.