VB TCP/IP Response question
VB TCP/IP Response question
VB TCP/IP Response question
VB TCP/IP Response question
VB TCP/IP Response question
VB TCP/IP Response question VB TCP/IP Response question VB TCP/IP Response question VB TCP/IP Response question VB TCP/IP Response question VB TCP/IP Response question VB TCP/IP Response question VB TCP/IP Response question
VB TCP/IP Response question VB TCP/IP Response question
VB TCP/IP Response question
Go Back  Xtreme Visual Basic Talk > > > VB TCP/IP Response question


Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2010, 03:32 PM
Kovacs Kovacs is offline
Newcomer
 
Join Date: Jul 2010
Posts: 5
Default VB TCP/IP Response question


Hello!

I'm doing a project for school which involves running an experiment with the use of two different programs, E-Prime & LabVIEW, the two of them connected with a TCP/IP connection. E-Prime runs the experiment and LabVIEW gathers data.
Basically what I want to happen is for E-Prime to send a (starting) trigger to LabVIEW, after which LabVIEW will sent a specific response before E-Prime continues again.

E-Prime unfortunately involves some (visual basic) programming of which I have very little knowledge about. This script I found has helped me out quite a bit though:

Code:
Dim MySocket As SocketDevice
dim nRead as long
dim inputStr as String
Debug.enabled = true

Set MySocket = New SocketDevice
MySocket.Name = "MySocket"
Dim theSocketDeviceInfo As SocketDeviceInfo
theSocketDeviceInfo.Server = "Rorschach-pc"
theSocketDeviceInfo.Port = 4444
theSocketDeviceInfo.SocketType = ebSocketTypeTcp
theSocketDeviceInfo.ByteOrdering = ebByteOrderingLittleEndian

'Open
MySocket.Open theSocketDeviceInfo


'********Send Trigger *********
MySocket.WriteString "Trigger"
MySocket.FlushOutputBuffer

'*****receive the initial message********

do while MySocket.InputCount = 0
loop

dim initial_response as String

do until MySocket.InputCount = 0
nRead = MySocket.ReadString(inputStr)
initial_response = initial_response & inputStr
loop

debug.print "read from the server: " + initial_response

inputStr = ""
Now the script works fine until the last part.

Code:
'*****receive the initial message********
do while MySocket.InputCount = 0
loop

dim initial_response as String

do until MySocket.InputCount = 0
nRead = MySocket.ReadString(inputStr)
initial_response = initial_response & inputStr
loop

debug.print "read from the server: " + initial_response

inputStr = ""
After that I need to rewrite it a little so that E-Prime will only continue after receiving a specific response from LabVIEW (in this case I want it to be "1").
If I keep it the way it is it won't matter whether LabVIEW sends a "1" or "2" response as long as it's one or the other (and that won't do).
I'm pretty sure it involves ReadString and/or initial_response but I just can't figure out the specifics.

I have no clue where to look anymore so any help or advice would be highly appreciated.
Reply With Quote
  #2  
Old 07-30-2010, 11:17 PM
DougT's Avatar
DougT DougT is offline
Ultimate Antique

Administrator
* Expert *
 
Join Date: Sep 2005
Location: Maldon,Essex, UK
Posts: 3,939
Default

I think you need another loop which executes until initial_response = "1"

Perhaps something like
Code:
'*****receive the initial message********
do while MySocket.InputCount = 0
loop

dim initial_response as String
do until mid$(initial_response,1,1) = "1"
     do until MySocket.InputCount = 0
     nRead = MySocket.ReadString(inputStr)
          initial_response = initial_response & inputStr
     loop
loop
debug.print "read from the server: " + initial_response

inputStr = ""
The outer loop will continue to execute and ignore the input until the first character of input_response is a 1.
__________________
semel insanivimus omnes
S Data in context = Information, S Information in context = Knowledge, S Knowledge in context = Experience
S Experience in context = Wisdom= Data
Reply With Quote
  #3  
Old 07-31-2010, 02:05 AM
Kovacs Kovacs is offline
Newcomer
 
Join Date: Jul 2010
Posts: 5
Default

Quote:
Originally Posted by DougT View Post
The outer loop will continue to execute and ignore the input until the first character of input_response is a 1.
Thank you!
It works exactly like you said, but for some reason when it gets the "2" input first, it will not accept the right ("1") input afterwards anymore and gets stuck in an endless loop.
I'll toy around with it a little and see if I can adjust that.
Reply With Quote
  #4  
Old 07-31-2010, 02:37 AM
DougT's Avatar
DougT DougT is offline
Ultimate Antique

Administrator
* Expert *
 
Join Date: Sep 2005
Location: Maldon,Essex, UK
Posts: 3,939
Default

I think that initial_response should be set to Null in the outer loop
Code:
'*****receive the initial message********
do while MySocket.InputCount = 0
loop

dim initial_response as String
do until mid$(initial_response,1,1) = "1"
     initial_response = ""
     do until MySocket.InputCount = 0
     nRead = MySocket.ReadString(inputStr)
          initial_response = initial_response & inputStr
     loop
loop
debug.print "read from the server: " + initial_response

inputStr = ""
__________________
semel insanivimus omnes
S Data in context = Information, S Information in context = Knowledge, S Knowledge in context = Experience
S Experience in context = Wisdom= Data
Reply With Quote
  #5  
Old 07-31-2010, 11:09 AM
Kovacs Kovacs is offline
Newcomer
 
Join Date: Jul 2010
Posts: 5
Default

Cheers mate, that's exactly it.
Appreciate the help. =)
Reply With Quote
  #6  
Old 07-31-2010, 12:31 PM
DougT's Avatar
DougT DougT is offline
Ultimate Antique

Administrator
* Expert *
 
Join Date: Sep 2005
Location: Maldon,Essex, UK
Posts: 3,939
Default

Great, good luck with the Project
__________________
semel insanivimus omnes
S Data in context = Information, S Information in context = Knowledge, S Knowledge in context = Experience
S Experience in context = Wisdom= Data
Reply With Quote
  #7  
Old 08-18-2010, 07:12 AM
Kovacs Kovacs is offline
Newcomer
 
Join Date: Jul 2010
Posts: 5
Default

Project is coming along now, but now I'm uncertain if the trigger is actually sent. Using the piece of code below (which is identical to the one in my first post) it would appear that the connection is being established, but the trigger doesn't seem to come through.
I'm trying to find out on which end of the connection things go wrong. With LabVIEW (which is on the other end of the connection) I've created an indicator but the string ("Trigger") I'm sending over never shows up on it.
Might there be something wrong with the Trigger part of the code below, or do I have to look somewhere else?


Code:
Dim MySocket As SocketDevice
dim nRead as long
dim inputStr as String
Debug.enabled = true

Set MySocket = New SocketDevice
MySocket.Name = "MySocket"
Dim theSocketDeviceInfo As SocketDeviceInfo
theSocketDeviceInfo.Server = "Rorschach-pc"
theSocketDeviceInfo.Port = 4444
theSocketDeviceInfo.SocketType = ebSocketTypeTcp
theSocketDeviceInfo.ByteOrdering = ebByteOrderingLittleEndian

'Open
MySocket.Open theSocketDeviceInfo


'********Send Trigger *********
MySocket.WriteString "Trigger"
MySocket.FlushOutputBuffer
Reply With Quote
  #8  
Old 08-18-2010, 05:45 PM
DougT's Avatar
DougT DougT is offline
Ultimate Antique

Administrator
* Expert *
 
Join Date: Sep 2005
Location: Maldon,Essex, UK
Posts: 3,939
Default

My guess would be that you need to terminate the "Trigger" command with an "end of message" indicator (eg a Carriage Return line feed pair)
__________________
semel insanivimus omnes
S Data in context = Information, S Information in context = Knowledge, S Knowledge in context = Experience
S Experience in context = Wisdom= Data
Reply With Quote
  #9  
Old 08-19-2010, 04:32 AM
Kovacs Kovacs is offline
Newcomer
 
Join Date: Jul 2010
Posts: 5
Default

Cheers Doug, I really appreciate the help you've been giving me about this (since I know so little about it).
I'm gonna get cracking again.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
VB TCP/IP Response question
VB TCP/IP Response question
VB TCP/IP Response question VB TCP/IP Response question
VB TCP/IP Response question
VB TCP/IP Response question
VB TCP/IP Response question VB TCP/IP Response question VB TCP/IP Response question VB TCP/IP Response question VB TCP/IP Response question VB TCP/IP Response question VB TCP/IP Response question
VB TCP/IP Response question
VB TCP/IP Response question
 
VB TCP/IP Response question
VB TCP/IP Response question
 
-->