Convert FreeBASIC code to Gambas stuck

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 189
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Convert FreeBASIC code to Gambas stuck

Post by AndyGable » Tuesday 20th September 2022 9:26pm

Code: Select all

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: Select all

   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

BruceSteers
Posts: 887
Joined: Thursday 23rd July 2020 5:20pm

Re: Convert FreeBASIC code to Gambas stuck

Post by BruceSteers » Wednesday 21st September 2022 1:22pm

You are missing a function called Loc()

Either find it in the original freebasic code or if it's a freebasic built in function find what it does and emulate it.
Last edited by BruceSteers on Wednesday 21st September 2022 1:26pm, edited 1 time in total.

BruceSteers
Posts: 887
Joined: Thursday 23rd July 2020 5:20pm

Re: Convert FreeBASIC code to Gambas stuck

Post by BruceSteers » Wednesday 21st September 2022 1:25pm


AndyGable
Posts: 189
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Convert FreeBASIC code to Gambas stuck

Post by AndyGable » Wednesday 21st September 2022 2:51pm

Ohh thanks that is a FreeBASIC function

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.

BruceSteers
Posts: 887
Joined: Thursday 23rd July 2020 5:20pm

Re: Convert FreeBASIC code to Gambas stuck

Post by BruceSteers » Wednesday 21st September 2022 4:08pm

I dunno looks like fairly simple file handling routines. But freebasic uses Loc for the recent handle
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.

Post Reply