Convert FreeBASIC code to Gambas stuck

Post

Posted
Rating:
#1 (In Topic #903)
Enthusiast
AndyGable is in the usergroup ‘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
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
Maybe this helps…
LOC - FreeBASIC Documentation
Online now: No Back to the top

Post

Posted
Rating:
#4
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
 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.
Online now: No Back to the top
1 guest and 0 members have just viewed this.