Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error when inputting ASCII text from COM port
#1
In my quest to port my QB45 code over to QB64, I am finding things are not 100% portable. Okay, but I'm plugging along trying to learn them. Anyway, my latest is an issue in inputting ASCII text from a COM port. The text would be from 1 to 12 characters followed by the 'enter' key getting pressed. Elsewhere in the program I have used the command 'Open "COM5:9600,N,8,1,RS0,CS0,DS0,CD0" For Random As #1' to handle COM port communications. But for this case, I get a 'Bad File Mode' error for the 'Line Input #1, FILENAME$' command.

If I change the 'Random' to 'Input' I then get the 'Input Past End' error; even though I have not typed a single thing in to send over the comm port. I have tried doing a straight Input #1, and a Get #1, still with errors right off the bat without sending any data. I'm at yet another loss as to what I am missing.....

DEL1: 'Request file deletion COM5
Close #1
Open "COM5:9600,N,8,1,RS0,CS0,DS0,CD0" For Input As #1
Line Input #1, FILENAME$
KILL1$ = "E:\SERVER\CPM\" + KILLFILE$
Kill KILL1$
Put #1, , EOT$
STATLINE$ = Date$ + " - " + Time$ + " - COM5 File Delete Request"
GoSub EVENTSAVE
GoSub PRINTSTAT
Return
Reply
#2
read serial like:

Code: (Select All)
Static receivedBytes$
Dim As String * 1 byte
Do While Loc(1) <> 0
Get #1, , byte
receivedBytes$ = receivedBytes$ + byte
Loop
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply
#3
can you check that the filename$ is not empty before trying to Input from it?

Oh mdijkens beat me! Smile and look he is making sure it's not empty!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#4
I will confess, I have never used a SUB or a FUNCTION (MBASIC & GW_BASIC mostly), so I guess I need to noodle out how to put this into one of them, and stick it somewhere... Oh well, the learning never stops. Smile


[Image: Untitled.jpg]
Reply
#5
(01-23-2024, 05:55 PM)MichelleL Wrote: I will confess, I have never used a SUB or a FUNCTION (MBASIC & GW_BASIC mostly), so I guess I need to noodle out how to put this into one of them, and stick it somewhere... Oh well, the learning never stops. Smile


[Image: Untitled.jpg]
Sorry, this came from a function I've created that also processed the bytes received.
You can delete that Static line

Use of function:
Code: (Select All)

serialin$ = checkSerial$()


Function checkSerial$()
  receivedBytes$ = ""
  Dim As String * 1 byte
  Do While Loc(1) <> 0
    Get #1, , byte
    receivedBytes$ = receivedBytes$ + byte
  Loop
  checkSerial$ = receivedBytes$
End Function
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply
#6
Well, this gets me to File Not Found; without even typing in anything on the computer waiting for me to input the filename so it can be transmitted. I've nulled out the KILLFILE$, and added a couple print statements which don't display anything, as if indicating there is nothing in them. And I have tried both Input and Random for how to open the comm port. I am perplexed.....

'------------------------------------------------------------------------------
DEL1: 'Request file deletion COM5
Close #1
Open "COM5:9600,N,8,1,RS0,CS0,DS0,CD0" For Input As #1
KILLFILE$ = ""
Dim As String * 1 byte
Do While Loc(1) <> 0
Get #1, , byte
KILLFILE$ = KILLFILE$ + byte
Loop
'Line Input #1, FILENAME$
KILL1$ = "E:\SERVER\CPM\" + KILLFILE$
Kill KILL1$
Put #1, , EOT$
STATLINE$ = Date$ + " - " + Time$ + " - COM5 File Delete Request"
GoSub EVENTSAVE
GoSub PRINTSTAT
Return
'------------------------------------------------------------------------------
Reply
#7
what??
Code: (Select All)
KILL1$ = "E:\SERVER\CPM\" + KILLFILE$
Kill KILL1$
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#8
I think you want to keep receiving bytes until an enter is received.
So probably something like
Code: (Select All)
Do
  If Loc(1) <> 0 Then Get #1, , byte
  If byte > Chr$(13) Then
    KILLFILE$ = KILLFILE$ + byte
  Else
    Exit Do
  End If
Loop

Furthermore, try changing the open statement to something like:
Code: (Select All)
Open "COM5:9600,E,8,1,BIN,CS0,DS0,RB8192" For Random As #1
QB64 is quite picky on serial
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply
#9
Quote:@MichelleL - I will confess, I have never used a SUB or a FUNCTION . . .
Finally something for fun and play again.  Big Grin  Examples of sub and function. 
One can also pass a function as an argument to a sub. - You should stop using GoSub these days and replace it with S&F; QuickBasic was already able to do that from 2.0(?)

kaufpreis = Purchase price
mehrwertSteuer = VAT
Endpreis/Gesamtpreis = Final price (total price)

Code: (Select All)

'Beispiel fuer SUB und Funktionen - 23. Jan. 2024

Option _Explicit

Declare Function Endpreis(kaufpreis, mehrwertSteuer As Double) As Double
Declare Sub auchEndpreis(eingabe As Double)

Dim As Double kaufpreis, mehrwertSteuer

Locate 3, 3
Input "Kaufpreis: ", kaufpreis
Locate 4, 3
Input "Mehrwertsteuer: ", mehrwertSteuer

Locate 6, 3
Print Using "Der Endpreis betraegt: ####,#.## Euro"; Endpreis(kaufpreis, mehrwertSteuer)

Locate 8, 3
'Function as an argument to a sub
Call auchEndpreis(Endpreis(kaufpreis, mehrwertSteuer))

End

Sub auchEndpreis (eingabe As Double)

  Dim As Double subGesamtpreis

  subGesamtpreis = eingabe
  Print Using "Der Endpreis betraegt: ####,#.## Euro"; subGesamtpreis

End Sub

Function Endpreis (kaufpreis, mehrwertSteuer As Double)

  Dim As Double gesamtpreis

  gesamtpreis = kaufpreis + ((kaufpreis * mehrwertSteuer) / 100)
  Endpreis = gesamtpreis
End Function
Reply
#10
Oops, I was being too complicated there.  Rolleyes  That will go  easier with the SUB.

Code: (Select All)

Sub auchEndpreis (eingabe As Double)

  Print Using "Der Endpreis betraegt: ####,#.## Euro"; eingabe
End Sub
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mac debugger not connecting, a user error! BlameTroi 0 99 02-07-2026, 06:18 PM
Last Post: BlameTroi
  ERROR MESSAGES COLORS ? aurel 5 383 01-02-2026, 11:26 AM
Last Post: aurel
  Using CONST & _RGB used together seem to error... Dav 12 680 12-12-2025, 12:29 AM
Last Post: Dav
  error doing image collision detection with _MemGet madscijr 55 4,655 10-01-2025, 03:25 PM
Last Post: bplus
  error on function returning _mem Herve 5 682 07-05-2025, 08:06 PM
Last Post: hsiangch_ong

Forum Jump:


Users browsing this thread: