Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a badge reader which has an IP address and TCP port assigned to it. I can telnet into the IP and port and see the badge number every time it reads one. The session stays open and just sends a badge number and newline on every read. I want to do something similar in C#, but cannot figure out the best way to do it.

I've used TCPClient and Socket classes, but the best I can do is read the first badge and that's all. I've done it blocking and async, but again I can only read the first badge and then the code continues.

My main questions are:

1 - Will I need a thread to continually go back to a read state after every read? I was hoping there was something built in so I wouldn't have to do that.

2 - If I do go the threading route, will I need to close and re-establish the TCP session every time for a read, or just keep the session open and read new data?

Otherwise, are there better ways of doing it?

Any help is greatly appreciated.

Thanks,

David




Update:

Wow Sergey... You went right by the point there. Sometimes I wonder if people answer something without even halfway reading the question.

Thanks for the info and link Zoltan.

I can capture all bytes, and am basically getting a 6 digit number and a carriage return. That's all good. I can even configure the device to send me different data and formats. No problem there. I am just looking for a way in C# to open a TCP/IP connection to something and read every time it sends data.

I dont know if I need a thread to keep it actively reading for data or what.
Posted
Updated 21-May-13 11:39am
v2

If you can telnet/putty to the device and you see what you need, than probably the telnet protocol is good enough. But even if telnet is simple, it is not that simple, there are several terminal emulations that can trick you. So I suggest use putty first and capture all bytes to see what really comes. Than try a more advanced library like these: http://sourceforge.net/projects/dotnettelnet/[^], http://www.thoughtproject.com/Libraries/Telnet/[^]. But if you decide to do it yourself, make sure to use async read, this might be also useful: http://robjdavey.wordpress.com/2011/02/11/asynchronous-tcp-client-example/[^]
 
Share this answer
 
You really need to address to the manufacturer's documentation or even their customer support. In fact, we don't even have an idea on what protocol is used, forget all technical detail.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900