Author Topic: Serial port COM working now  (Read 1883 times)

0 Members and 1 Guest are viewing this topic.

Offline acjacques

  • Newbie
  • Posts: 33
Serial port COM working now
« on: October 16, 2019, 06:37:44 pm »
Code: QB64: [Select]
  1. 'ACJacques transmit & receive serial working  tested up to  115200  tested also to connect to onboard PC Bluetooth port COM9 with success
  2. 'but could not connect to  COM15  (TTl-USB Serial converter) although it is available for other programs.
  3. DIM bytestr AS STRING * 1 'one byte transfers
  4. INPUT "COM port number #", port$ 'any COM port number available  'not ANY. See above
  5. OPEN "COM" + port$ + ":115200,N,8,1,BIN,CS0,DS0" FOR RANDOM AS #1
  6. DO 'main loop
  7.     'receive data in buffer when LOC > 0
  8.     IF LOC(1) THEN
  9.         GET #1, , bytestr
  10.         PUT #1, , bytestr 'echo on same COM port
  11.         PRINT bytestr; 'print in the QB64 screen
  12.     END IF
  13.     'transmit (send)    'send by keyboard
  14.     k$ = INKEY$
  15.     IF LEN(k$) = 1 THEN
  16.         k = ASC(k$)
  17.         IF k >= 32 THEN 'ignore control key codes
  18.             PRINT k$; 'print in the QB64 screen
  19.             bytestr = k$
  20.             PUT #1, , bytestr 'send to COM port
  21.         END IF
  22.     END IF
  23. LOOP UNTIL k$ = CHR$(27)
  24. CLOSE #1: PRINT "Finished!"
  25.