Convert FreeBASIC code to Gambas stuck
Posted
#1
(In Topic #903)
Enthusiast

Code
Dim status As String
Open COM "COM1:9600,N,8,1,CD0,CS0,DS0,rs" As #1
Print #1, Chr(10) & Chr(4) & 1
While Loc(1) =0
Sleep 1
Wend
status = Input(Loc(1), 1)
Print Bin(Val(status),8)
If Bit(Val(status), 3) = -1 Then
Print "Kickout connector high"
Else
Print "Kickout connector low"
EndIf
If Bit(Val(status), 4) = -1 Then
Print "Offline"
Else
Print "Online"
EndIf
If Bit(Val(status), 6) = -1 Then
Print "Waiting for Online Recovery"
Else
Print "Not Waiting for Online Recovery"
EndIf
If Bit(Val(status), 7) = -1 Then
Print "Paper fed by button"
Else
Print "Paper not fed by button"
EndIf
Close #1
This is some code I have been working on in FreeBASIC I have tried to convert it to Gambas (see below for the Gambas Version)
Code
Dim status As String
Write #Global.PrinterPort, Chr(10) & Chr(4) & 1
Global.PrinterPort.Send
While Loc(Global.PortName) = 0
Sleep 1
Wend
status = Input(Loc(Global.PrinterPort), 1)
Print Bin(Val(status), 8)
If Bit(Val(status), 3) = -1 Then
Global.AddToScreenList("Kickout connector high")
Else
Global.AddToScreenList("Kickout connector low")
Endif
If Bit(Val(status), 4) = -1 Then
Global.AddToScreenList("Printer is Offline")
Else
Global.AddToScreenList("Printer is Online")
Endif
If Bit(Val(status), 6) = -1 Then
Global.AddToScreenList("Waiting for Online Recovery")
Else
Global.AddToScreenList("Not Waiting for Online Recovery")
Endif
If Bit(Val(status), 7) = -1 Then
Global.AddToScreenList("Paper fed by button")
Else
Global.AddToScreenList("Paper not fed by button")
Endif
But when ever I run the code i get a "Unknown Identifier : Loc in FMain.class
I am now stumped as what direction to go in could someone help me out
Posted
Guru

Either find it in the original freebasic code or if it's a freebasic built in function find what it does and emulate it.
Posted
Guru

Posted
Enthusiast

So I've got to either become really smart over night or ask someone who is smarter then me on here to see if they could help me convert the code.
Posted
Guru

you will just have to use stream functions on the com port stream explicitly.
One command looked like a simple
While not EOF(hStream)
Another waits for the port to become open.
This is not "having to be an expert" but for stream functions yes, you will have to learn how gambas generally does it in order to convert.
Good luck. Looks like you're almost there.
1 guest and 0 members have just viewed this.



