Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Struggling with serial comms
#2
(05-05-2022, 11:01 AM)I've implemented these function to handle serial: Wrote:
Code: (Select All)
Function ser.open% (ser$) ' e.g. ser$="COM1:9600"
  On Error GoTo Errhandler
  Open ser$ + ",N,8,1,BIN,CS0,DS0,RB8192" For Random As #88
  If errorNum = 0 Then serBytes$ = ser.read$
  On Error GoTo 0
  ser.open% = errorNum
End Function

Function ser.close$ ()
  ser.close$ = ser.read$
  Close #88
End Function

Sub ser.send (bytes$)
  Dim b As String * 1
  For i% = 1 To Len(bytes$)
    b = Mid$(bytes$, i%, 1)
    Put #88, , b
  Next i%
End Sub

Function ser.read$ ()
  Dim b As String * 1: resp$ = ""
  Do While Loc(88)
    Get #88, , b: resp$ = resp$ + b
  Loop
  ser.read$ = resp$
End Function
Most important parts:
",BIN,CS0,DS0,RB8192" in open statement
to read:  Do While Loc(88):Get #88, , b: resp$ = resp$ + b:Loop
to write:   Dim b As String * 1:b = Mid$(bytes$, i%, 1)Tongueut #88, , b
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
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)