Posts: 6
Threads: 2
Joined: Jan 2024
Reputation:
0
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
Posts: 128
Threads: 12
Joined: Apr 2022
Reputation:
14
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
Posts: 3,981
Threads: 177
Joined: Apr 2022
Reputation:
220
01-23-2024, 05:16 PM
(This post was last modified: 01-23-2024, 05:18 PM by bplus.)
can you check that the filename$ is not empty before trying to Input from it?
Oh mdijkens beat me! and look he is making sure it's not empty!
b = b + ...
Posts: 6
Threads: 2
Joined: Jan 2024
Reputation:
0
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.
Posts: 128
Threads: 12
Joined: Apr 2022
Reputation:
14
01-23-2024, 07:16 PM
(This post was last modified: 01-23-2024, 07:17 PM by mdijkens.)
(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.
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
Posts: 6
Threads: 2
Joined: Jan 2024
Reputation:
0
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
'------------------------------------------------------------------------------
Posts: 3,981
Threads: 177
Joined: Apr 2022
Reputation:
220
what??
Code: (Select All) KILL1$ = "E:\SERVER\CPM\" + KILLFILE$
Kill KILL1$
b = b + ...
Posts: 128
Threads: 12
Joined: Apr 2022
Reputation:
14
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
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
01-23-2024, 09:56 PM
(This post was last modified: 01-23-2024, 09:59 PM by Kernelpanic.)
Quote:@MichelleL - I will confess, I have never used a SUB or a FUNCTION . . .
Finally something for fun and play again. 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
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
Oops, I was being too complicated there. That will go easier with the SUB.
Code: (Select All)
Sub auchEndpreis (eingabe As Double)
Print Using "Der Endpreis betraegt: ####,#.## Euro"; eingabe
End Sub
|