Socket Commication Help
Posted
#1
(In Topic #652)
Enthusiast

I am trying to talk to another program of mine via Socket
I have I think the server working correctly but when I run the code I get status number of 5
This is the code
Code (gambas)
Where am I going wrong (this is the client code) I can post the Server code if needed
Posted
Regular

AndyGable said
…I am trying to talk to another program of mine via Socket…
Take a look at my post: Captain Bodgit: Using Sockets with Gambas which will walk you through the process.
Your logic is wrong with this line:-
…as clearly the rest of the If…Then… will not execute if you have an active connection.
Posted
Enthusiast

stevedee said
AndyGable said
…I am trying to talk to another program of mine via Socket…
Take a look at my post: Captain Bodgit: Using Sockets with Gambas which will walk you through the process.
Your logic is wrong with this line:-
…as clearly the rest of the If…Then… will not execute if you have an active connection.
Hi Stevedee,
Do i need to change my code to
I did follow your guide but I think my issue is I am using a CLI application with out any GUI interface so I could not fully follow your guide.
do you have a guide that would work on a CLI application? (the reason why I have selected CLI is this app is to run in the background and it only handles data that has to be sent to the printer it does not need to have a graphical interface. (unless you know a way to load a GUI application with out it showing a GUI interface.
I aI am doing it this way so I do not have to hard code support for every printer I support with in my NPoS application (also allows me to add support for newer printers when they come along)
This is what I had in mind at the moment (this all runs so far from the main command line) If someone know how to start programs from another program when the desktop has loaded I would like to see a example (also can you shut down the desktop once it has loaded and only have say my boot up program running (in window I could terminal the Explorer.exe and then my startup app would take over and load the
rest of the system)
I am loading all my add on modules before starting XServer (I do this by using for example ./NPoS/AddOn/Printer-Epson.gambas &) the & at the end will load the program and return control right back to the Opearting system)
once every add on is loaded I would then use startx ./NPoS/NPoS.gambas to start x server and boot into my NPoS application (that then uses the sockets to talk to the Printer add on module)
Posted
Enthusiast

I know for a fact the Printer code works perfectly as I can run the same code in another application that talks directly to the printer
Code (gambas)
- ' Gambas module file
- 'Printer Only Fucntions
- ' Printer Fucntions Declares
- 'Public PrintStoreLogo1 As String = Chr$(&H1B) & "a" & Chr$(48)
- 'Public PrintStoreLogo2 As String = Chr$(&H1B) & "a" & Chr$(48)
- 'Public PrintStoreLogo3 As String = Chr$(&H1B) & "a" & Chr$(48)
- 'Public PrintStoreLogo4 As String = Chr$(&H1B) & "a" & Chr$(48)
- ' Printer Serial Settings
Code (gambas)
- Print "Loading Epson Printer Module..."
- LoadPrinterSettings
- Print " Data Loaded from Settings file"
- Print " Print The Plain Pound Symbol"
- Print " Print The Pound Symbol by using chr$(156)"
- Print " One Module has loaded Print a test page"
- Print " No test page set to print once module has loaded"
- Print " Print The First stored logo as the Store logo"
- Print " No Graphical Logo set to print"
- Print " Opening Commication to the Printer please wait..."
- ConnectToPrinter("Open")
- Print "Sending Test Print to the Printer"
- SendTestPrint
- 'Open Port ready for the PoS to connect to the module
- StartConnection
- ConnectToPrinter("Close")
Code (gambas)
- 'This will Load the PoSSettings.conf file
- '******* PoS Settings Section *******
- LinesToFeed = SettingsLocalFile["Printer Settings/LinesToFeed"]
- UsePlanPoundSymbol = SettingsLocalFile["Printer Settings/UsePlanPoundSymbol"]
- PrintTestSlip = SettingsLocalFile["Printer Settings/PrintTestSlip"]
- PrintGraphicalLogo = SettingsLocalFile["Printer Settings/PrintGraphicalLogo"]
- PrinterPortName = SettingsLocalFile["Printer Settings/PortName"]
- PrinterBandRate = SettingsLocalFile["Printer Settings/BandRate"]
- PrinterFlowControl = SettingsLocalFile["Printer Settings/FlowControl"]
- PrinterDataBits = SettingsLocalFile["Printer Settings/DataBits"]
- PrinterStopBits = SettingsLocalFile["Printer Settings/StopBits"]
- PrinterParity = SettingsLocalFile["Printer Settings/Parity"]
Code (gambas)
- With SerialPort1
- .PortName = PrinterPortName
- .Speed = PrinterBandRate
- Case "Hardware"
- .FlowControl = SerialPort1.Hardware
- Case "Software"
- .FlowControl = SerialPort1.Software
- Case "None"
- .FlowControl = SerialPort1.None
- .DataBits = PrinterDataBits
- .StopBits = PrinterStopBits
- Case "None"
- .Parity = SerialPort1.None
- Case "Odd"
- .Parity = SerialPort1.Odd
- Case "Even"
- .Parity = SerialPort1.Even
- Case "Open"
- .Open
- Case "Close"
Code (gambas)
- Write #SerialPort1, PrinterInitialize
- Write #SerialPort1, CentreAlignText & DoubleWidthHeightFont & "THIS IS A TEST PRINT" & CancelFontMode & PrinterNewLine
- Write #SerialPort1, CentreAlignText & DoubleWidthFont & "Printed from Linux" & CancelFontMode & PrinterNewLine
- Write #SerialPort1, LeftAlignText & NormalFont & "Epson ESC/PoS Control module for algPoS Point of sale" & PrinterNewLine
- Write #SerialPort1, LeftAlignText & NormalFont & "Version : " & Application.Version & PrinterNewLine
- Feed_CutPaper(LinesToFeed)
- SerialPort1.Send
Code (gambas)
Code (gambas)
- ThisSocket = PoSConnection.Accept()
- Print " Connection Establed with PoS Application"
- Exit
- Socket_read
This is the code I am currenly using to send the data to the Printer add on module
Code (gambas)
Posted
Regular

AndyGable said
…I did follow your guide but I think my issue is I am using a CLI application with out any GUI interface so I could not fully follow your guide…
It doesn't matter whether you are using cli or gui. When I suggested that you follow my guide, I meant open a new Gambas Project and start from there. Gain an understanding of how it works and then create your own implementation in your final code/project. You won't be able to copy 'n paste my code into your project.
I'm sorry if I've misunderstood your question or your code, but I'm too pushed for time at the moment to invest a lot of time on this.
Maybe someone else can pick this one up.
1 guest and 0 members have just viewed this.



