Using SerialPort class for modem to modem communication - c#

I'm rewriting a legacy app that sends pager messages via TAP and modems. So I'm having to write a new TAP client in C#. Using SerialPort is trivial but I'm not sure about how to handle conditions such as:
excessive ringing with no answer
no dialtone
busy signal detection (I understand that this isn't enabled in every modem so this is optional)
remote modem answers
Then also how do I read received data in a synchronous manner? TAP is synchronous so I will be issuing commands and then expecting some type of response from the remote machine. I think my biggest issue is figuring out how data will be terminated. Is it standard for modem data to be terminated by a CR or maybe CR-LF?
Some pointers would be great and any references that I could go read myself is wonderful too.

Is this a question regarding Serial Communication or the TAP? I've never had to work with TAP, but I have had to work with serial communication hardware (albeit quite a few years ago.)
I just found this PDF specification document and I searched for "terminat". It brings up 8 different words with that series of text, 7 of which appear to be in reference to your request.
I'm not sure of how much experience you have with serial communication or legacy communication systems & hardware but you may find HyperTerminal to be immensely useful and it is part of Windows. There is other serial/terminal software out there, but HyperTerm is free and simple to use.
You can use HyperTerm to send and receive codes to your devices and inspect the data that is sent/received. Then, you can use the communication dumps to reverse-engineer the TAP communication.
-- EDIT --
In regards to interacting with the modem, I'd research a bit about the Hayes command set. Hayes was a company that made modems in the early 80's. According to what I've read their modem commands have become pretty standard ever since then. Glancing at the available modem commands, I think there is a solution for your questions but you may need to do a bit of experimentation.
I'll be honest, I've never had to work directly with modem hardware, so the information that I am providing is based off of the research I've found this afternoon. These tips are what I would assume and attempt if I were in your shoes. For more information, google "Hayes Command Set" or check this article.
Hope that helps.

Related

Can I receive a phone call over my modem in C#

I'm working a piece of software that in a perfect world would never lose an internet connection, and I could send an audio feed between two clients flawlessly. My problem is that this world is far from that. In the event of a failed internet connection and a dropped audio feed, my service is effectively worthless.
My question is this:
Is there a way in C# to attach to my systems modem and either make a call, or receive a call, (or preferably both,) and push/play audio to/from two points?
The approach is deprecated, but nearly a necessity in my scenario, and I couldn't find much on Google, so any help would be appreciated.
Thanks ahead of time.
No, modems (dial-up I assume you mean) do not have the ability to insert raw audio on a pots line (perhaps if you rewrite the driver though) but you may want to look into asterisk that has some really cool stuff you can mess with. But to the main point unless you forget the modem and use an ip-phone solution the answer is no.
You should look at using a service like Twilio to handle voice calling. They have a .net client: http://www.twilio.com/docs/libraries

C# server sends UDP packets to a Java Client

im working on a project where i should transfer data from a c# server to an Java client (running on android device).
i need to use UDP protocol for a real time data and to maintain performance.
searching the web. didnt find any similar example and i really dont know where to start.
can you please suggest if this can be done ?
Thanks in advance.
Yes, it can be done. That's one of the beautiful things about the Internet protocols: support for standard sockets is so widespread and common that disparate devices running vastly different CPU architectures and software environments can interoperate with nearly no trouble.
Please make sure that UDP is really the best tool for the job. Do you need reliable delivery? Do you need in-order delivery? How much packetloss can you tolerate? How much packet re-ordering can you tolerate? Will your application handle 540 byte packets as gracefully as it will handle 1500 byte packets? Does your application need to protect against man in the middle attacks? How?
TCP is an incredible protocol. Many attempts to use UDP "for speed" wind up re-implementing many of the things that TCP provides for you already -- but most re-implementations are not done nearly as well as the real thing. Please don't be so quick to dismiss TCP.
To get started, just about any network tutorial for Java and C# should include something like a chat or echo server, the network programming equivalent of "Hello World". And that'd be good enough for a simple environment. If you intend for your server to handle dozens of clients simultaneously, it'll be more work, and if you intend for your server to scale into the hundreds or thousands, it'll be a different style of programming altogether.
Have you tried reading this:
http://nickstips.wordpress.com/2010/09/03/c-creating-and-sending-udp-packets/
The client is irrelevant, it can be Java, C++, or any other language/platform. Doesn't matter.
The protocol is still the same.
Hope this helps.
Try the Oracle Documentation as a starting point with UDPs, there you can find an example which i in java but as mentioned the idea of the protocols is to support a language independent communication.

c# SerialPort MultiDrop connection

I have been reading up on the web and cannot find any information on working with a RS485 MultiDrop connection in c#
To give a bit of insight. I have written an application to communicate with a Serial device using the MODBUS RTU protocol. Now the client has informed me there devices may be hooked up using multidrop communications links. Being a novice when it comes to working with serial devices I am a bit lost here.
My question is simply: Where do I start? a Google search has thus far only produced hardware converters and wikipedia entries for different Serial Communication standards.
Thanks!
RS485 is a standard that defines the electrical characteristics of a particular multi-drop networking arrangement. I once used it as the internal bus for an instrument - the main control board drove various pumps which were arranged on an RS485 network.
You can get half-duplex and full duplex arrangements (half means that one device can talk at a time - full means send and receive can happen at the same time).
Really using it is not a whole lot different from using an RS232 or serial port, and as you've seen you can get serial to RS485 converters. You can use the serial port drivers in C# to use it.
SerialPort Class
Your main problem is that RS485 doesn't really address how it should be used - its a fairly low level electrical spec, it doesn't define how you should use it to make communication happen.
The main issue you need to consider is how you're going to coordinate all this. With RS232 - there are two things connected, which makes it easy - usually a computer and some device. With RS485, there are many things connected. So you need some way of addressing each device. You don't give any details about the 'device' referred to here - but if they are intended to be connected on RS485 - then there will be a way of addressing them. There are however several ways this could work - so I can't help you on specifics without more detail. With the system I developed, all communication was initiated by the 'master' device (i.e. my control board - or your c# application for example) and each message sent had the receiver's address on it - so the right pump knew that the instruction was intended for it.
I hope this is of some help. Really its not that complicated, but you need to think about what these devices do, how they are addressed, and think about the messages that you need to send back and forth. You can use the C# SerialPort classes to actually do the work.
The book referred to in the other answer looks great by the way. I really would consider buying it if this is all new to you. It covers serial port communications, and has a chapter on RS485.
I have not worked with RS485 but this book can be a help in understanding Serial port and USBs.
here is another link which discuss specs and here is another. I dont think they will be readily implemented in C# but could be.

C# COM port communication - errors with a USB to Serial Adapter

Here's the scenario - I have a C# application that reads from a COM port. Most of the time I use devices with a serial adapter and on a machine with a serial ports. However, machines with serial ports are increasingly difficult to come by so I have started using machines with a USB/Serial connection.
In some cases, the C# code that I have will work just fine with a "true" serial connection but fail with a USB/serial connection. The data comes in fragmented with the first part of the data coming in (like maybe the first 1 or 2 characters) and nothing else.
I'm using something basic like comport.ReadExisting() to pick up the data from the port. Is this part of the problem? Are there other methods that would guarantee that all the data would be read in a single string?
Finally, I want to add that I've already played around with some of the USB/serial settings in device manager AND the data comes in fine when using good, ole' hyperterminal . . . so it has to be something in the code.
With USB-serial converters, you MUST set your receive timeout, because the data can sit in the USB device for a long time where Windows doesn't know about it. Real serial ports hold data in the 16550 FIFO where the Windows driver can see it.
Most of the times you would want to use the SerialPort.DataReceived event ( http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.datareceived.aspx ).
This requires you to combine the chunks of data manually since you can receive parts of your string, but once you detect the boundary of a single 'record' you can fire of processing that record while letting the IO receive more events.
This allows some asynchronous IO which doesn't block your threads, and thus allows more efficient handling of the data in general. If it helps in your specific situation I don't know, but it has helped me in the past dealing with data reading issues, low speeds, thread pooling, and lock-ups.

Need to control some device via Wi-Fi using C#

I am working on an application that needs to control another device.
This control should be using Wi-Fi.
How can this be done in C#?
Important to know that the other device I want to make it.
I can afford the part of making and design but how to make it connect to PC using Wi-Fi?
I don't know about it.
I just need a key to start searching or some thing similar.
Connecting over Wi-Fi could be as easy as opening a socket on the server, and another on the client, and start streaming data. Of course this if both devices are compatible and has Wi-Fi receivers. Just think of them as two computers connected with a wire, or without a wire they will just behave the same.
The connection protocol will care about doing the magic of converting what you write on the socket, into RF signals received from the other device and converted back to bytes.
But if you are building your own antenna/receiver/protocol ... then things will be much more complicated.
If you have to ask then you're probably going to want a single board computer. Popular choices are:
gumstix
Zii EGG
nwg100 by Atmel
(XBee) --not too sure about these, I haven't used.
You can install a network stack and everything on them.

Categories