Sending Serial Data Between Two Virtual Machine in a Learning Practice

158 Views Asked by At

I am trying to send and receive data between two VM in Vm-Ware Workstation for learning purpose. I use Quick Basic IDE for progrmming serial COM Port.Operating system is Freedos in both VM's. Every VM uses a virtual port of windows host. The pair of virtual ports are made ELTIMA software.
I use two piece of basic code , one for sending and the other one for receiving as follow:

DIM bytestr AS STRING * 1

INPUT "COM port number #", port$
OPEN "COM" + port$ + ":9600,N,8,1,BIN,CS0,DS0" FOR RANDOM AS #1
CLS
DO
        k$ = INKEY$
        IF LEN(k$) = 1 THEN
                k = ASC(k$)
                IF k >= 32 THEN
                        PRINT ">" + k$ + "<";
                        bytestr = k$
                        PUT #1, , bytestr
                END IF
        END IF
LOOP UNTIL k$ = CHR$(27)
CLOSE #1: PRINT "Finished!"  

and second peice for reciving :

CLS
DIM bytestr AS STRING * 1

INPUT "COM port number #", port$
OPEN "COM" + port$ + ":9600,N,8,1,ASC,CS0,DS0" FOR RANDOM AS #1
DO
        k$ = INKEY$
        IF LOC(1) THEN
                GET #1, , bytestr
                PRINT "[" + bytestr + "]";
        END IF
LOOP UNTIL k$ = CHR$(27)
CLOSE #1: PRINT "Finished!"

What I receive in receiving machine console are strange characters that are different from what was typed in sending machine. I cannot even find a logical relation between them.
Would you please explain me what is happening.

Codes have borrowed from:
https://www.qb64.org/wiki/OPEN_COM

1

There are 1 best solutions below

2
Sep Roland On

The documentation for OPEN "COM" says:

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

Your OPEN statement on the receiving end then erroneously uses ASC instead of BIN

OPEN "COM" + port$ + ":9600,N,8,1,ASC,CS0,DS0" FOR RANDOM AS #1
                                   ^
                                   | Should be BIN