Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Jul 18, 2019 8:31 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: TCP Socket question
PostPosted: Tue Jul 03, 2012 1:26 am 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
I have a piece of software running on my PC that installs a TCP socket to communicate with some industrial PLCs (conveyors etc.). Data is sent to this socket from another manufacturing software running on a separate server, telling the PLC what to do by means of specially formatted messages. The PLC needs to read the messages and send an acknowledge message back to the manufacturing software using the TCP socket as the only interface point.

I'd like to build a RB program capable of reading messages sent to that TCP socket from the manufacturing software and send aknowledge messages to the same, emulating the PLC. What's the best approach for that?

NB: all of this is being tested on a local network.

Regards,
- Oskar


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Tue Jul 03, 2012 1:55 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Drag a TCPSocket to your window, assign it the port number that the PLC uses, and call Listen. Put code in the socket's DataAvailable event to handle the messages coming from the manufacturing software. Use Write to send the response back.


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Tue Jul 03, 2012 6:06 am 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
timhare wrote:
Drag a TCPSocket to your window, assign it the port number that the PLC uses, and call Listen. Put code in the socket's DataAvailable event to handle the messages coming from the manufacturing software. Use Write to send the response back.

Hey thanks a lot for your input: I'll give it a try asap.


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Tue Jul 03, 2012 4:47 pm 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
Any specific reason why the Write + Flush methods can freeze the application?


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Thu Jul 05, 2012 1:48 am 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
Oskar wrote:
Any specific reason why the Write + Flush methods can freeze the application?
Can this be happening because of an infinite loop maybe? I mean the socket writing to itself? Sorry for the beginner question but I am rather new to network developments.

Regards,
- Oskar


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Thu Jul 05, 2012 9:06 am 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
Ahh, I don't see too many others working with PLC's on here. :)

Does your application free indefinitely? It could be looping if you're doing a "Hi" -> "Hello" -> "Hi" -> etc... routine with the software. But I don't know the commands and what their responses are, so I can't say for sure. Can you give more information on the command protocol you're working with?

Also, you don't need to flush the buffer every time you write. Flushing interrupts everything to send the write buffer, as opposed to waiting for the system to do it of its own accord — in the vast majority of scenarios, it's best just to write and leave it be.

Hope this helps. :)

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Thu Jul 05, 2012 2:07 pm 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
I found out the TCPSocket apparently does not connect (checked with IsConnected).
I am using something like this:

mySocket.Address="127.0.0.1"
mySocket.port = 8000
mySocket.Connect

Is this usually correct?

Regards,
- Oskar


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Thu Jul 05, 2012 2:22 pm 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
So long as you mean to be connecting to yourself via port 8000, then yes. Now the software you're trying to connect to, is it listening on port 8000? I'm not asking if it uses port 8000 to communicate with the PLC, but it's actually listening for you to connect at the time you go to connect?

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Thu Jul 05, 2012 4:47 pm 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
Jason_Adams wrote:
So long as you mean to be connecting to yourself via port 8000, then yes. Now the software you're trying to connect to, is it listening on port 8000? I'm not asking if it uses port 8000 to communicate with the PLC, but it's actually listening for you to connect at the time you go to connect?

Well in the manufacturing software I can configure the IP address and port of the PLC so I set 127.0.0.1 and 8000; since my goal is to emulate the PLC then I used the same settings with the TCPSocket instance in my RB app. What's interesting is that I can listen to the messages and read them using the DataAvailable event. What I can't achieve is the connect + send side of things.


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Thu Jul 05, 2012 6:18 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
You don't have to connect to send messages. A socket is 2-way. Initially, one side listens while the other connects, but after that, both can read and write as they wish.

In your socket DataAvailable event, put code like

me.Write(theResponse)


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Fri Jul 06, 2012 3:18 pm 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
timhare wrote:
You don't have to connect to send messages. A socket is 2-way. Initially, one side listens while the other connects, but after that, both can read and write as they wish.

In your socket DataAvailable event, put code like

me.Write(theResponse)

Thanks, I am testing that and with no flush also no freeze but the manufacturing software is not receiving my message. I'm really struggling with this. I can read but I can't message back!
I must be doing something wrong: can a proper use of netstat help identify where the problem is maybe?

Regards,
- Oskar


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Sat Jul 07, 2012 2:20 am 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
Well I managed to create an example with two TCPsockets exchanging messages with each other. Still unable to send the message to the manufacturing software though...

Regards,
- Oskar


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Sat Jul 07, 2012 3:47 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Do you know the exact format the software expects? Unless you get it exactly right, it may just give you the blank stare. Can you capture the response from the PLC and reproduce it byte for byte?


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Sat Jul 07, 2012 11:53 am 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
I analyzed further and the problem is that the manufacturing software is unable to connect to the port (at least according to the log messages in that software). I must be doing something wrong at network level, as the Firewall is now off.


Top
 Profile  
Reply with quote  
 Post subject: Re: TCP Socket question
PostPosted: Sat Jul 07, 2012 2:00 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
If the manufacturing software is trying to connect to 127.0.0.1:8000 your code should be listening on that port - not trying to connect

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group