Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Struggling with serial comms
#1
<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } -->
I am having a problem with one of the example 'Help' programmes. Under LOC 'Help' is a simple programme for RS232 communication with a peripheral via COM1.

OPEN "COM1: 9600,N,8,1,OP0" FOR RANDOM AS #1 LEN = 2048 ' random mode = input and output
  DO: t$ = INKEY$ ' get any transmit keypresses from user
    IF LEN(t$) THEN PRINT #1, t$ ' send keyboard byte to transmit buffer
    bytes% = LOC(1) ' bytes in buffer
    IF bytes% THEN ' check receive buffer for data"
      r$ = INPUT$(bytes%, 1)          ' get bytes in the receive buffer
      PRINT r$; ' print byte strings consecutively to screen"
    END IF   
  LOOP UNTIL t$ = CHR$(27) 'escape key exit
CLOSE #

My peripheral is a Summagraphics digitising pad - this has a movable puck with four buttons; you position the puck, press one of the buttons, and it sends the numeric x y coordinates of the puck and a numeric flag for the button to its RS232 port in effectively csv format. Thus the output may be  16958,11142,1<CR><LF>  for one press, ie 15 bytes. It also receives input from its RS232 port to configure it. It is thus acting very like a modem.

The above programme in QB64 2.0.2 fails at line 17 with the message "Bad file mode" when I press a keyboard key. Clearly it doesn't like the "Print #1" command.

Which I am not surprised at because isn't "Print #n" a sequential file command and the comms buffer has been opened as "Random"?

And then - if I eliminate the 't$=' and 'IF Len' lines to concentrate on the receive, I get an 'Input past end of file' error at the 'r$=" line, despite LOC returning 15 bytes in the buffer. If I overwrite bytes% with 1, to get the first character in the buffer, I still get 'Input past end of file'.

What is going on? Are these bugs? Any help gratefully received.
Reply


Messages In This Thread
Struggling with serial comms - by Wolstan Dixie - 05-05-2022, 11:01 AM
RE: Struggling with serial comms - by mdijkens - 05-05-2022, 01:55 PM
RE: Struggling with serial comms - by moci - 05-20-2022, 09:58 PM
RE: Struggling with serial comms - by Pete - 05-05-2022, 04:52 PM
RE: Struggling with serial comms - by mdijkens - 05-06-2022, 10:43 AM
RE: Struggling with serial comms - by Pete - 05-06-2022, 05:00 PM



Users browsing this thread: 1 Guest(s)