A Gambas Newbie questions

Post

Posted
Rating:
#1 (In Topic #508)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi All,

is it possible to make a Screenless application in Gambas? I ask as I have a lot of Point of sale Printers that I support and I was thinking about creating a "driver" app for each printer.

If it is possible can i use Socket in Gambas so the apps can talk to each other?

Also last question can I convert BASIC code to Gambas?

Code

Sub StandardCashDrawer

   Dim As String A, B, keyprs
   Dim aint             As Integer
   Dim t                As Double
   Dim errflag          As Integer
   Dim timeropen          As Double
   
   Do
        a = Input$(LOC(PoSPrinter),1) 'clears data from serial buffer
        a = ""
        
        If JournalType = "Paper" Then    
              Print #PoSPrinter, ESC ; "="; Chr(1); ' Select Printer ONLY
        EndIf
        
        Print #PoSPrinter, Chr(29);Chr(114);Chr$(2); ' get the status from the printer
        errflag = 0
        t = Timer
        
        If cashdrwopen <> 9999 Then timeropen = Timer
        
        While Loc(PoSPrinter) = 0
            
            If Timer - t > TimeOutLimit Then
                cashdrwopen = -1
                Exit Do
            End If
            Sleep 1
        Wend        
        
      A = Input$(PoSPrinter,1)
      Aint = Val("&H" & Hex(Asc(A),2))


        If (Aint And 1) = 0 Then ' Cash Drawer open
            a = ""
            CashDrwOpen = 9999
            
            If CashDrawerAudioAlarm ="Yes" Then
               If Timer - timeropen > 30 Then
                  Sound(c1, dur)
                   font.fontindex = 3 'small font                 
                    font.backcolor = Black
                  font.forecolor = white
                  font.drawstring (," C L O S E    D R A W E R ",200,360)                     
               End If
            End If
        End If

        If (Aint And 1) = 1 Then ' Cash Drawer closed
            Exit Do
        End If
        Sleep 100
    Loop
    
      If CashDrwOpen = -1 Then
         'comm timeout
         Locate 1,1
         Print "No response from cash drawer"
      Else
         If CashDrawerFucntion = "SaleScreen" Then
            dailyCash -= ChangeDue       'update the cash figure with the change out
            DailyCustomerCount += 1      'add 1 to customer count
               
            If MSSavedValue > 0 And PrintMSSummary = "No" Then YouSavedTodayPrint
      
            Select Case PrintReciptOption
               Case "Allways"
                  SelectEndOFRecipitPrint
               
               Case "AtClose"
                  PrintRecipit ' Prints recpit when the cash drawer closes
            End Select
               CreateTimeSaleFile
               DisplayMovingMessgae
               ResertDataFigures
         End If
             
          If CashDrawerFucntion = "NoSale" Then
             DailyNosale += 1
             DisplayMovingMessgae
            ResertDataFigures
          End If
          
          If CashDrawerFucntion = "SafeDrop" Then
            ResertDataFigures
          End If
      End If
End Sub
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’

AndyGable said

…is it possible to make a Screenless application in Gambas? I ask as I have a lot of Point of sale Printers that I support and I was thinking about creating a "driver" app for each printer. …

Yes, when you start Gambas and create a new Project Type, the first option is: Command-line application

You basically work with a Public Sub Main() rather than a Public Sub Form_Open() routine.

Here is a simple example:-

Code (gambas)

  1. ' Gambas module file
  2.  
  3. hTimer As Timer
  4. fTime As Float
  5.  
  6. Public Sub Application_Signal(x As Integer)
  7.  
  8.   Print "Program stopped after " & fTime & " seconds"
  9.   Quit
  10.  
  11. Public Sub Main()
  12.  
  13.   hTimer = New Timer As "IntTimer"
  14.   Print "Press [Ctrl] + " & Chr(92) & " to stop"  '<ctrl><\>
  15.   Signal[Signal.SIGQUIT].Catch
  16.   hTimer.Delay = 500
  17.   hTimer.Start
  18.  
  19. Public Sub IntTimer_Timer()
  20.  
  21.   Print Rand(0, 100)
  22.   fTime += 0.5

You may also be interested in my old post: Captain Bodgit: Gambas: command-line programming

You can even do Gambas command line programming without using the IDE, by using Gambas Script: Captain Bodgit: a WifiScanner written in Gambas Script
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
stevedee is in the usergroup ‘Regular’

AndyGable said

…If it is possible can i use Socket in Gambas so the apps can talk to each other?…

I think its better to keep things simple, so long as the solution meets the requirements.

For example, lets suppose App1 reads a barcode and needs to transfer it to App2, and that we are happy as long as this takes less than (say) 500ms.
One simple solution might be for App1 to write the barcode as text into a file called CurrentCode.txt
The App2 program would then need to check for the presence of the CurrentCode.txt file periodically (at least <500ms). If/when it finds the file, it would extract the barcode string and delete the file. This is very simple to understand, test & debug.

I hope this helps.

I have a sockets example, but it may not be directly relevant to your needs: http://captainbodgit.blogspot.com/2016/08/using-sockets-with-gambas.html
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
Regarding your code there are quite a few changes to make. I don't understand all the 'printing' parts of the code but here are a few tips:-

Sub StandardCashDrawer change to Sub StandardCashDrawer()
Dim As String A, B, keyprs change to Dim A, B, keyprs As String
Dim t As Double change to  Dim t As Float
End sub change to End
Exit Do change to Break Note that Break will get you out of any loop type.

Sleep 100 with stop the program for 100 seconds! Sleep Wait
Online now: No Back to the top

Post

Posted
Rating:
#5
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

cogier said

Regarding your code there are quite a few changes to make. I don't understand all the 'printing' parts of the code but here are a few tips:-

Sub StandardCashDrawer change to Sub StandardCashDrawer()
Dim As String A, B, keyprs change to Dim A, B, keyprs As String
Dim t As Double change to  Dim t As Float
End sub change to End
Exit Do change to Break Note that Break will get you out of any loop type.

Sleep 100 with stop the program for 100 seconds! Sleep Wait

Hi Cogier,

the Print #PoSPrinter, ESC ; command  send commands to the Printer to get the status of the cash drawer. In Windows Ican use OPoS to control the cash drawer but in Linux nothing like that exists (well they have JavaPoS but that is WAY to complicated)
Online now: No Back to the top

Post

Posted
Rating:
#6
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

stevedee said

AndyGable said

…If it is possible can i use Socket in Gambas so the apps can talk to each other?…

I think its better to keep things simple, so long as the solution meets the requirements.

For example, lets suppose App1 reads a barcode and needs to transfer it to App2, and that we are happy as long as this takes less than (say) 500ms.
One simple solution might be for App1 to write the barcode as text into a file called CurrentCode.txt
The App2 program would then need to check for the presence of the CurrentCode.txt file periodically (at least <500ms). If/when it finds the file, it would extract the barcode string and delete the file. This is very simple to understand, test & debug.

I hope this helps.

I have a sockets example, but it may not be directly relevant to your needs: http://captainbodgit.blogspot.com/2016/08/using-sockets-with-gambas.html

I have tried using text files before but they are not very reliable and with some of the information that would be shared between the apps I
would have to encrypted it.

I have had a look at your example and for what I need that looks like it will be perfect (sending printer commands to the printer app etc)
Online now: No Back to the top

Post

Posted
Rating:
#7
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

stevedee said

AndyGable said

…is it possible to make a Screenless application in Gambas? I ask as I have a lot of Point of sale Printers that I support and I was thinking about creating a "driver" app for each printer. …

Yes, when you start Gambas and create a new Project Type, the first option is: Command-line application

You basically work with a Public Sub Main() rather than a Public Sub Form_Open() routine.

Here is a simple example:-

Code (gambas)

  1. ' Gambas module file
  2.  
  3. hTimer As Timer
  4. fTime As Float
  5.  
  6. Public Sub Application_Signal(x As Integer)
  7.  
  8.   Print "Program stopped after " & fTime & " seconds"
  9.   Quit
  10.  
  11. Public Sub Main()
  12.  
  13.   hTimer = New Timer As "IntTimer"
  14.   Print "Press [Ctrl] + " & Chr(92) & " to stop"  '<ctrl><\>
  15.   Signal[Signal.SIGQUIT].Catch
  16.   hTimer.Delay = 500
  17.   hTimer.Start
  18.  
  19. Public Sub IntTimer_Timer()
  20.  
  21.   Print Rand(0, 100)
  22.   fTime += 0.5

You may also be interested in my old post: Captain Bodgit: Gambas: command-line programming

You can even do Gambas command line programming without using the IDE, by using Gambas Script: Captain Bodgit: a WifiScanner written in Gambas Script

Great thank you

does that mean I can start the program with the ./ProgamName & command?
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Regular
stevedee is in the usergroup ‘Regular’

AndyGable said

…does that mean I can start the program with the ./ProgamName & command?

Well, for my example I could use:-

./cliSignal.gambas

…if terminal is running in the directory that holds the file.

What is: & command?
Online now: No Back to the top

Post

Posted
Rating:
#9
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 According to google the & command will start the program but will not make it take focus (so basically it will load the program into the background)

What I would like to do is start my application and have it then load other apps as it needs then
for example it would show on the screen


Welcome to PoS
Starting Epson Printer App…… (and then it would start the epson driver application)
or

Starting IBM Printer App…… (and then it would start the IBM driver application as IBM use different commands for thier printers)

The idea is the drivers would use the same commands from the main software (PoS) but will send to the printers the required commands for that given hardware
Online now: No Back to the top

Post

Posted
Rating:
#10
Guru
BruceSteers is in the usergroup ‘Guru’

AndyGable said

If it is possible can i use Socket in Gambas so the apps can talk to each other?

A Pipe would be better and simpler.
/lang/pipe - Gambas Documentation

But yes a socket or pipe is a way to make apps communicate to each other.

Here i posted a simple pipe example..
Gambas One - Gambas ONE
once the app is open you can type …
echo "hi there" >>/tmp/FIFO1
and the app will pick it up.

with a pipe a program can watch a file for input and in your other app you can use echo to send text to the pipe file and the app watching it can react.

Here's a more complicated example that opens a pipe file when it first runs, then any other commands to run the app while it's already open cause the newly run app to send it's args to the pipe and quit, then the first open app gets the args and reacts as it would when first run.
I call it the "single instance" example
Gambas One - Gambas ONE


AndyGable said

Also last question can I convert BASIC code to Gambas?

You can but there are not apps to do it, it does not take long to do it by hand.
It won't take you long to learn the little differences.

Happy gambassing
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Regular
stevedee is in the usergroup ‘Regular’

AndyGable said

According to google the & command will start the program but will not make it take focus (so basically it will load the program into the background)

What I would like to do is start my application and have it then load other apps as it needs…

Re: loading a program in the background, that only makes sense if you only have one instance of a shell. As an example, my Pi based Internet Radios don't run a GUI. So each program that needs to run must run in the background, so the next will still be loaded and run.
So (as far as I can see) you can load several programs via different Shells from your Gambas program, and they won't block or inhibit the others.

One thing is clear, and that is that this is not a trivial application. So with that in mind I'm going to ask you to fully check your requirements and assess whether you are taking the best approach. Obviously its your choice how you do this, but I don't want to give advice regarding a possibly flawed approach.

Q1: Why do you want a separate program to perform this printing process?
Reason for question: It looks like you only want to print…when you want to print.
If you launch a separate program, you may need some kind of feedback to ensure that it is still running. You may end up checking its running each time, then restarting it if its not, then sending data to print. If that's the case (and you still want a separate program) you could just call it when you need it (via Exec or Shell) and let it close gracefully when its finished.

If you just want the code to be modular, have you considered just putting the printer code in a Module, creating a Class or creating and using a Library?

Like I say, its better to ask these questions now.


Incidentally, the only time I've found the need to create 2 Gambas programs to work together was for my bat call capture software. The first program had to take a quick decision on whether an audio stream contained ultrasonic signals, and then buffer each 'good' file. While the second had to go through each file and determine whether it contained a possible bat call or just other noise. So each file was either saved (along with analysis data, including frequency) or deleted. As the bats could make the sounds much faster than Gambas could classify them, I needed this 2 program (multi thread) approach.
Online now: No Back to the top

Post

Posted
Rating:
#12
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

stevedee said

Q1: Why do you want a separate program to perform this printing process?

Hi Stevedee,

the Reason I would like each printer to have its own program is because each printer uses different commands to print to the printer (these are not standard printers so I can not use the in built linux print functions) I am using Epson Retail printers and IBM as well as NCR and Wincor Nixdorf Printers (they all use thier own version of ESC/PoS)

I have not yet looked into the full features of Gambas but so far it looks like It may be what i want to drop windows from our Point of sale systems (well at the front end anyway)

and I am not using a GUI as such I have a Basic install of xserver and I can start the PoS with startx ./NPoS/NPoS (that is the name of the application) and the software starts up

the Reason I would want to have each other program running in the background would be because they do not have any user interfaces so they do not need to be interfaced with (they only talk to the main PoS application)

I am hoping to be able to add support for Scales in the Linux version (I have this in the Windows version but it is using OPoS and that is not supported in Linux)

Also I have a custom wrote DLL that handles the tills promotions (written in VB.net) I did not write this I paid someone to do that for me can I still use it with Gambas?
Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
Hi AndieGamble

Also I have a custom wrote DLL that handles the tills promotions (written in VB.net) I did not write this I paid someone to do that for me can I still use it with Gambas?

DLL or Dynamic Link Libraries are a Windows thing and will not run on linux.
Also, all the code would probably be very Windows specific when it comes to how to approach hardware.

You could  try to rewrite the DLL as a Gambas library if you have access to the source code of the DLL.
You should be aware that things work differently on linux compared to Windows when recoding.

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: Yes Back to the top

Post

Posted
Rating:
#14
Avatar
Regular
stevedee is in the usergroup ‘Regular’

AndyGable said

….the Reason I would like each printer to have its own program is because each printer uses different commands to print to the printer (these are not standard printers so I can not use the in built linux print functions)…


From what you say, I would agree that you need to keep the printer stuff modular. But I'm not convinced that that means a bunch of separate programs, and that these need to be running in the background.

Presumably, at some point the main program will say "let's print some stuff to printer type A". The type A bit will direct the code to call a Module or a Class or maybe Library code to do the rest.

Note that when I say Class, I'm thinking of an OOP (object orientated programming) type class with common Methods and Properties (and possibly Events) which would handle the printing, even though the implementation details differ significantly between printer types. So in use, you would create an instance of your printer class for (say) the Type F printer and configure various Properties (and maybe run certain Methods) to suit the printers protocol. Then you just call a Method to 'print this'.

On the other hand, if you write separate independant programs for each printer, you still need to get them to talk to one another, and your overall testing time will be longer, and software quality may suffer.


The bottom line is that you probably need to fully familiarise yourself with the Gambas concepts of Modules, OOP Classes, and Libraries before taking a final decision on which approach to adopt.

Sorry if that is not the answer you were looking for.
Online now: No Back to the top

Post

Posted
Rating:
#15
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

gbWilly said

Hi AndieGamble

Also I have a custom wrote DLL that handles the tills promotions (written in VB.net) I did not write this I paid someone to do that for me can I still use it with Gambas?

DLL or Dynamic Link Libraries are a Windows thing and will not run on linux.
Also, all the code would probably be very Windows specific when it comes to how to approach hardware.

You could  try to rewrite the DLL as a Gambas library if you have access to the source code of the DLL.
You should be aware that things work differently on linux compared to Windows when recoding.

I have full access to the source code of the DLL (as it was written for my company) is it hard to do a libary for Gambas? Ive never done anything like that before
Online now: No Back to the top

Post

Posted
Rating:
#16
Avatar
Regular
stevedee is in the usergroup ‘Regular’

AndyGable said

… is it hard to do a libary for Gambas? Ive never done anything like that before

You will find my simple-starter-guide to Gambas libraries here: Captain Bodgit: Gambas: using external Gambas libraries

…or for using C libraries with Gambas: Captain Bodgit: Gambas: using external C libraries
Online now: No Back to the top

Post

Posted
Rating:
#17
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 Thank-you  Steve I shall have a Read of that and have a play with Gambas at the weekend
Online now: No Back to the top
1 guest and 0 members have just viewed this.