[NA] C# programing [NA]

ron22

Cleared for Takeoff
Joined
Jun 19, 2008
Messages
1,446
Location
MN
Display Name

Display name:
Ron Hammer
Anyone here know C#? I have a program I wrote in C# now I need to modify it to send some a command over a TCP connection then receive the reply.
I have never dealt with TCP before and was hoping for some quick help.
I need to send
0000t
Then it will reply
0000*
0000?
0000startPASS#100.0#001#01#0359#0352#-003.8#100.0stop
or
0000*
0000?
0000startFAIL#000.0#000stop

All I need is the Pass/Fail line. I can then pull the data out of the reply I need.
Accualty it will be two differnt IP address I need to send to and pull the data from. But I figure if I can get one I should be able to get the second one working.
I used hyperterminal to get what the responce is.
 
Google is my friend but for some reason I am being real stupid about this.
Everything I read talks about a client and a server. In my app is there really a client or server? 1 thing is a peice of hardware that does a test the other is the computer. Like I said for some reason I can not get my head around this tonight.
 
Google is my friend but for some reason I am being real stupid about this.
Everything I read talks about a client and a server. In my app is there really a client or server? 1 thing is a peice of hardware that does a test the other is the computer. Like I said for some reason I can not get my head around this tonight.

Your program is the client, and the server is responding with
0000*
0000?
0000startPASS#100.0#001#01#0359#0352#-003.8#100.0stop
or
0000*
0000?
0000startFAIL#000.0#000stop
 
I would use the string.regex class to parse the return data. Effectively, you can parse out the text retuned and find the information you actually want.
 
Take a look at the TCPClient class, it is a really easy to use socket implementation, you just treat it like a simple serial device. The actual "Socket" class is great when you know what you're doing, but it can be a little heavy when starting out.

As for parsing the return values, that is pretty easy too! The data seems to follow a pretty strict grammar, and has easily tokanizable points (the '#' character looks like a delimiter), so it should be fairly trivial.
 
Ok thanks I got it working using TcpClient. I am sure I did not do it the most graceful way but it seems to work. I currently only have 1 of the 2 Cameras with me so I can not fully test it. So want to tackle the bitmap image that it can pass too :hairraise:
Like I said I do not claim to be a C# programmer. This was only going to be a simple HMI interface to the machine controller. Now they added the stupid TCP cameras. They do not need the image just the data I posted earlyer wich I can pull out now.
 
Ok thanks I got it working using TcpClient. I am sure I did not do it the most graceful way but it seems to work. I currently only have 1 of the 2 Cameras with me so I can not fully test it. So want to tackle the bitmap image that it can pass too :hairraise:
Like I said I do not claim to be a C# programmer. This was only going to be a simple HMI interface to the machine controller. Now they added the stupid TCP cameras. They do not need the image just the data I posted earlyer wich I can pull out now.

Now do it again in C or with MASM like a real man :D

My networking professor wouldn't let us do TCP in ANYTHING but C. At that time java was just getting popular and made TCP Programming as easy as falling off a log, using anything Microsoft was strictly forbidden.
 
Ok thanks I got it working using TcpClient. I am sure I did not do it the most graceful way but it seems to work. I currently only have 1 of the 2 Cameras with me so I can not fully test it. So want to tackle the bitmap image that it can pass too :hairraise:
Like I said I do not claim to be a C# programmer. This was only going to be a simple HMI interface to the machine controller. Now they added the stupid TCP cameras. They do not need the image just the data I posted earlyer wich I can pull out now.

Cool, glad it helped! I've done a bunch of socket programming both in and out of .Net, and do C# development professionally. If you have more questions, you're welcome to PM me and I can give you my work email, and I'll help out when I can.
 
Back
Top