This is all pretty new to me, but the UDS essentially has an IP address and a port(10000). I am looking at the Controller options in XOJO and I think I need the TCP connection, but how to use it is where I am getting confused.
I am hoping that someone here could point me in teh right direction as to what controller to use, and maybe an Example in XOJO that would get me communicating with the UDS that I can learn from.
Thanks. I am going to be doing the actual programming on this, and JimM’s question was what I was just going to post.
This device seems to appear as a switch (not sure if that is the right term) with an ethernet port and two serial ports. It is going to be necessary to direct TCP messages from the LAN side to the serial port side. Not sure which port number the connection is directed to and if it is all done in one step or two (to the TCP port first, then the serial port). The LanTronix docs (which I have not fully reviewed yet) probably has some details.
James - This Lantronics device supports TELNET and doesn’t look like it has a REST API nor any API. You may need to TELNET (TCP23) to it, run commands, and return the results. Then you can parse the results into structured data if you need to. Here is a link to my open source TELNET project I created years ago.
[quote=477544:@Andrew Lambert]Xojo’s TCPSocket class uses Winsock on Windows.
To establish a connection you create a new socket and assign the IP address/port to the Address/Port properties of the socket:
Dim mysock As New TCPSocket
mysock.Port = 10000
mysock.Address = "192.168.1.234"
mysock.Connect()
Once the connection is established the TCPSocket will raise its Connected event and you can start reading/writing from the socket.[/quote]
Sorry for taking so long on this. Where are the PROPERTIES located in the TCP Socket/control? I am trying to set up the above example, but I cannot find where to place this information
I guess the question is WHEN do you want that socket to try & connect to something ?
When you push a button maybe ?
Lets do that
Add a Generic Button and add the ACTION event to that button (drag it out from the right hand library and the nwhen you have it on the layout right click and add event handler)
If you have an instance that you already dragged onto the layout you do not need the first line
// Dim mysock As New TCPSocket // <<< not needed if you dragged an instance onto the window layout
This line would have created a new socket but you already have one on the layout
In the following lines replace MYSOCK with TCPSocket1 since that is the name of the instance on your layout
Now, believe it or not … you are mostly done although you wont see anything really happen
But when you click that button the socket instance on the layout will
set the port it is going to try to connect TO // TCPSocket1.Port = 10000
set the address that it is going to try to connect TO // TCPSocket1.Address = “192.168.1.234”
try to connect // TCPSocket1.Connect()
Responding to any data or other errors would be done by adding the EVENT HANDLERS to TCPSocket1
There are several you can add
Connected
Error
SendProgress
DataAvailable
SendComplete
What specific code should go in these will depend entirely on how the device / computer / etc you’re trying to connect TO expects to communicate
I dragged the TCPSocket into the workspace and its sitting at teh bottom of the screen. If I right click on it, and select INSPECT I get a panel on the right side where in the BEHAVIOR section I can put the IP address and PORT as opposed to the lines in the button action you have listed above -----Is this ok?
Ok. So I have created a button on Window 1 and added an action. In that action I have the following:
TCPSocket1.Connect()
I would like to put in the window some sort of indicator that I can, say change the color from RED to GREEN based on the connect status.
I have added a CONNECT handler to teh TCPSocket, but heres where I get lost…
How do I:
control teh indicator on the main window to show the CONNECT status?
what kind of indicator should I use for this status?
[quote=485242:@Jim Marquardt]I dragged the TCPSocket into the workspace and its sitting at teh bottom of the screen. If I right click on it, and select INSPECT I get a panel on the right side where in the BEHAVIOR section I can put the IP address and PORT as opposed to the lines in the button action you have listed above -----Is this ok?
[/quote]
Yes
OK good start
In the code for the CONNECTED event you may get a response (this is the part that I cant tell / test since I dont have one)
In that event you can change the color of “something” or set a status that can be used to control the color of something
Just about anything will do but lets start simple
Drag a CANVAS control out onto the window
dont make it too big
we’ll use this to indicate the status
Add a PROPERTY to your window
Called “Connected” and make it a boolean
in the CANVAS Paint event put
if self.connected then
g.forecolor = &c00FF00 // depending on what version youre using this may need to be g.drawingcolor
else
g.forecolor = &cFF0000 // depending on what version youre using this may need to be g.drawingcolor
end if
The in TCPSOCKET1 Connected event put
self.connected = true
and in TCPSocket1 Error event put
self.connected = false // this might not strictly be true but this illustrates the point
OK, I mde some progress! It looks like I was able to connect to the Lantronix server! Yipee.
Now to write a simple “Hello World” to the socket to come out the RS232 port on the other side, and also to receive data from the device.
I was trying to display the error codes on a text box, but was unable to do this. How do I upload my project for review? Or to point me in teh right direction in writing and reading
PROGRESS!
Jim
EDIT:
I see Norman replied as I hit POST. I was able to use a button and the buttons ENABLE to show if I connected or not. I will try the canvas button in the morning.
I tried your example and I see nothing on teh screen where I placed teh canvas. I was expecting to see a little box colored RED or GREEN, but there is nothing in that area.
heh … missed one line in the PAINT event for the canvas (what I get for writing code just in the forums text editor field)
if self.connected then
g.forecolor = &c00FF00 // depending on what version youre using this may need to be g.drawingcolor
else
g.forecolor = &cFF0000 // depending on what version youre using this may need to be g.drawingcolor
end if
g.fillrect 0,0,g.width, g.height
it only SET the color but never used it to fill the canvas with that color