Click here to Skip to main content
15,897,187 members
Home / Discussions / C#
   

C#

 
GeneralRe: Entity Frame work Pin
Pete O'Hanlon14-May-13 3:53
mvePete O'Hanlon14-May-13 3:53 
JokeRe: Entity Frame work Pin
Richard Deeming14-May-13 3:59
mveRichard Deeming14-May-13 3:59 
GeneralRe: Entity Frame work Pin
Pete O'Hanlon14-May-13 4:01
mvePete O'Hanlon14-May-13 4:01 
GeneralRe: Entity Frame work Pin
Dave Kreskowiak14-May-13 3:59
mveDave Kreskowiak14-May-13 3:59 
GeneralRe: Entity Frame work Pin
TnTinMn14-May-13 11:12
TnTinMn14-May-13 11:12 
GeneralRe: Entity Frame work Pin
AspDotNetDev14-May-13 11:16
protectorAspDotNetDev14-May-13 11:16 
AnswerRe: Entity Frame work Pin
Dave Kreskowiak14-May-13 3:46
mveDave Kreskowiak14-May-13 3:46 
QuestionHow would you clear a tcp buffer or detect if there is data there ? Pin
Member 986287213-May-13 21:40
Member 986287213-May-13 21:40 
Ok, here is my problem:- I have a tcp connection to an instrument; it is the slave and I am it's master (it speaks only when spoken to). Below is an example of how this conversation might look:-
C#
//Clear RXstring.
Array.Clear(this.RXstring, 0, this.RXstring.Length);
//Build and send message.
sendMessage(buildMessage(Operation.Query));
//Couple of seconds delay is required before checking the data.
System.Threading.Thread.Sleep(2000);
try
{
  //Receive response from the Chamber Controller
  int len = this.tcp_com.Receive(this.RXstring);
  //Convert received ASCII bytes to string
  string temp = ASCIIEncoding.ASCII.GetString(this.RXstring, 0, len);
  if(temp.Contains("DYNAMIC")
  {
    this.dynamic = true;
  }
  else
  {
    this.dynamic = false;
  }

}


Problem is this:- Sometimes, the data can be truncated or for some reason, maybe too big for the buffer and so a bit gets left behind. If I try and read without there being any data, it becomes stuck so I have made my buffer 1024 bytes long and added some time to try and make sure it's all arrived.
I would like to be able to clear the port somehow so that I know that there is only valid data when I get a responce and not something left over from last rx. Alternativey, I would like to be able to ask if there is data there without it crashing; I could then retrieve and discard myself.
I know that there are other ways I could have implemented the tcp bit but this seemed the simplest at the time.
As usual, all thoughts and advise gratefully received...
AnswerRe: How would you clear a tcp buffer or detect if there is data there ? Pin
SoMad13-May-13 22:43
professionalSoMad13-May-13 22:43 
GeneralRe: How would you clear a tcp buffer or detect if there is data there ? Pin
Member 986287215-May-13 4:30
Member 986287215-May-13 4:30 
AnswerRe: How would you clear a tcp buffer or detect if there is data there ? Pin
Richard MacCutchan13-May-13 22:45
mveRichard MacCutchan13-May-13 22:45 
AnswerRe: How would you clear a tcp buffer or detect if there is data there ? Pin
jschell14-May-13 9:28
jschell14-May-13 9:28 
Questionruntime error Pin
n.nili13-May-13 19:04
n.nili13-May-13 19:04 
AnswerRe: runtime error Pin
Pete O'Hanlon13-May-13 21:22
mvePete O'Hanlon13-May-13 21:22 
AnswerRe: runtime error Pin
dusty_dex13-May-13 22:20
dusty_dex13-May-13 22:20 
Questionstring concatenation with all possibilities Pin
sethupathiram13-May-13 3:19
sethupathiram13-May-13 3:19 
AnswerRe: string concatenation with all possibilities Pin
Pete O'Hanlon13-May-13 3:30
mvePete O'Hanlon13-May-13 3:30 
AnswerRe: string concatenation with all possibilities Pin
Simon_Whale13-May-13 3:38
Simon_Whale13-May-13 3:38 
AnswerRe: string concatenation with all possibilities Pin
PIEBALDconsult13-May-13 4:33
mvePIEBALDconsult13-May-13 4:33 
AnswerRe: string concatenation with all possibilities Pin
Richard Deeming13-May-13 5:06
mveRichard Deeming13-May-13 5:06 
AnswerRe: string concatenation with all possibilities Pin
Anna King14-May-13 2:56
professionalAnna King14-May-13 2:56 
QuestionError 1 The type or namespace name 'Form1' Pin
Topias Jäppilä13-May-13 2:06
Topias Jäppilä13-May-13 2:06 
QuestionRe: Error 1 The type or namespace name 'Form1' Pin
Richard MacCutchan13-May-13 2:39
mveRichard MacCutchan13-May-13 2:39 
AnswerRe: Error 1 The type or namespace name 'Form1' Pin
Topias Jäppilä13-May-13 4:44
Topias Jäppilä13-May-13 4:44 
GeneralRe: Error 1 The type or namespace name 'Form1' Pin
Richard MacCutchan13-May-13 5:02
mveRichard MacCutchan13-May-13 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.