I created a form with one button, my purpose is to send string over tcp/ip, I created this app in VB windows and it works fine but on gambas and linux mint I get some error compiling, plz correct me and thank in advance, the code is :
Public Sub Button1_Click()
Dim ipAddress As String = "192.168.100.237"
Dim port As Integer = 9100
Dim ZPLString As String =
"^XA" &
"~JA" &
"^XZ"
Try
Dim client As New System.Net.Sockets.TcpClient
client.Connect(ipAddress, port)
Dim writer As New System.IO.StreamWriter(client.GetStream())
writer.Write(ZPLString)
writer.Flush()
writer.Close()
client.Close()
Catch ex As Exception
End Try
End
Public Sub Form_Open()
End
Send command "string" over tcp/ip
Send command "string" over tcp/ip
- Attachments
-
- Screenshot_2018-02-21_21-29-34.png (63.67 KiB) Viewed 12313 times
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Send command "string" over tcp/ip
Hi agili and welcome to the site.
I am not an expert on VB but I have asked a friend of mine to look at your code, however I can point out a couple of things.
1/. Gambas requires that all 'Dim' statements are declared at the beginning of the routine, you can't just add one in the middle.
2/. 'Catch' does not require an argument. Click on 'Catch' in the IDE and press [F2] for help.
3/. 'Try' only works on one line. Click on 'Try' in the IDE and press [F2] for help.
4/. On this site you can add your code in between the 'gb' tags to get a better display. See here viewtopic.php?f=9&t=502
My friend has replied to me as I write this and suggests you look here for help with this http://gambaswiki.org/wiki/comp/gb/stream?nh
Gambas is similar to VB but it is not a clone.
If this does, or does not, help please come back to us and lets us know how you got on.
I am not an expert on VB but I have asked a friend of mine to look at your code, however I can point out a couple of things.
1/. Gambas requires that all 'Dim' statements are declared at the beginning of the routine, you can't just add one in the middle.
2/. 'Catch' does not require an argument. Click on 'Catch' in the IDE and press [F2] for help.
3/. 'Try' only works on one line. Click on 'Try' in the IDE and press [F2] for help.
4/. On this site you can add your code in between the 'gb' tags to get a better display. See here viewtopic.php?f=9&t=502
My friend has replied to me as I write this and suggests you look here for help with this http://gambaswiki.org/wiki/comp/gb/stream?nh
Gambas is similar to VB but it is not a clone.
If this does, or does not, help please come back to us and lets us know how you got on.
Re: Send command "string" over tcp/ip
Cogier: thank you alot, as I wrote this is my first time using gambas I needed to convert my vb code to gambas so I can use it with ubuntu. honnestly it seemed complicated I stil recieve error when compiling. My purpose is to send these string to a zpl printer using Tcp/ip protocol, I tried to find some example writen in gambas in google but no luck.
strings:
^XA
~JA
^XZ
These are commands usally sent throw terminal and must be a string per line as I wrote.
strings:
^XA
~JA
^XZ
These are commands usally sent throw terminal and must be a string per line as I wrote.
Re: Send command "string" over tcp/ip
You probably need to start again by creating a Gambas project including the gb.Net component. Then you can add a Button and a Socket to the Form.
Rename the Socket: ClientSocket
Use properties to set IP address and Port:-
ClientSocket.Host = "192.168.100.237"
ClientSocket.Port = "9001"
Add some button code, maybe something like this:-
Public Sub Button1_Click()
Dim strMessage as String
strMessage = "^XA" & gb.Lf & "~JA" & gb.Lf & "^XZ" & gb.Lf
ClientSocket.Connect()
If ClientSocket.Status > Net.Inactive Then
Wait 1
If ClientSocket.Status = Net.Connected Then
Write #ClientSocket, strMessage, Len(strMessage)
Else
Close #ClientSocket
Me.Text = "Error: Timeout"
End If
End If
End
Take a look at my post for more details: https://captainbodgit.blogspot.co.uk/20 ... ambas.htmlRe: Send command "string" over tcp/ip
stevedee thanks I tried that but stil get error on compiling:
- Attachments
-
- Screenshot_2018-02-22_21-57-07.png (38.71 KiB) Viewed 12283 times
Re: Send command "string" over tcp/ip
Just delete Ser
Re: Send command "string" over tcp/ip
Hey Jornmo, any idea why the "If" in the first instance of "End If" in my post above is coloured pink not blue?
I'm sure it has to be something obvious.
I'm sure it has to be something obvious.
Re: Send command "string" over tcp/ip
stevedee , cogier and jornmo many thanks for effort I finally got rid of errors while compiling I also getting used to gambas project. I wil test the code with the host printer and will tell the result. I used this method by stevedee:
Public Sub Button1_Click()
Dim strMessage As String
strMessage = "^XA" & gb.Lf & "~JA" & gb.Lf & "^XZ" & gb.Lf
ClientSocket.Connect()
If ClientSocket.Status > Net.Inactive Then
Wait 1
If ClientSocket.Status = Net.Connected Then
Write #ClientSocket, strMessage, Len(strMessage)
Else
Close #ClientSocket
Me.Text = "Error: Timeout"
End If
End If
End
....
ofcourse I added a gb.net componet to project and a socket to the form.
Public Sub Button1_Click()
Dim strMessage As String
strMessage = "^XA" & gb.Lf & "~JA" & gb.Lf & "^XZ" & gb.Lf
ClientSocket.Connect()
If ClientSocket.Status > Net.Inactive Then
Wait 1
If ClientSocket.Status = Net.Connected Then
Write #ClientSocket, strMessage, Len(strMessage)
Else
Close #ClientSocket
Me.Text = "Error: Timeout"
End If
End If
End
....
ofcourse I added a gb.net componet to project and a socket to the form.
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Send command "string" over tcp/ip
If you are still having problems I see there is an example in the Gambas Farm called 'ClientSocket'. You can access the 'Farm' from the 'Tools' menu in the IDE.
Re: Send command "string" over tcp/ip
Its the javascript on this site that takes care of the syntax highlighting that is a bit rough on the edges. I will see later if I can fix it. We got it from the gambas-club.de forum.