question about PORT - c#

I have written a program in C# that sends text to COMx.
I wish to test it using HyperTerminal, meaning I want to read the text that I send with my program. When I set the WAIT FOR CALL in HyperTerminal, my program is refused access to the given port.
How can I test my program? Is it possible?

The best answer I can give is that the serial port is locked by your program and hence HyperTerminal cannot access the port as it is in use by your program. The best thing is to use a null modem cable loopback device in which you can send data and it will get looped back, like what EricLaw suggests.
Hope this helps,
Best regards,
Tom.

tommieb75 and EricLaw's answers are both right. When an application opens a serial port, the port is opened exclusively and no other app can work with it.
In order to test my serial applications I always use com0com. You can create a pair of virtual linked serial ports and setup your app to write to one of them and the HyperTerminal to listen to the other one.
This tool has helped me countless times. I strongly recommend it.

Take your serial cable and solder in on your RX or TX side of the COM port. Now, connect this to another COM port on your PC. Tada - now you can monitor what you are sending or receiving on this port by listening in on the other. Don't terminate TX on this other COM port so you don't disturb this connection. I have a couple of these cables in the office for this very purpose. I don't trust Serial Port monitoring software.

Your best bet would probably be to put a null-modem DB9 cable from COM1 to COM2 and use COM2 to talk to COM1.

Related

Bluetooth COM Ports

When I turn on the bluetooth on my laptop. I see there are 2 ports added under device manager COM&LPT
Why does it add 2 ports?
If I need to a read/write via bluetooth which port should I consider using?
Thanks.
If you're using Windows own Bluetooth software, two virtual port COM ports are created after pairing.
I believe one is being used for incoming connection requests and another is used to initiate connections to the device (outgoing).
To determine which one to "use" then please consider this post which should answer that for you.

Is it possible to simulate com port sending and receiving data using only C# programming?

I have a device which sends data by com port on my computer.
I know how to simulate it, but the controller must be plugged in to simulate sending data (using Proteus)
Is it possible to simulate the com port sending data without having any external device plugged in?
For example: I want to write a C# program which opens the com port and waits for data, and another c# program which writes data on the same port.
The best way to do this is to use a software COM port emulator. I use com0com :
Null-modem emulator
This provides virtual NM COM port pairs on the system (ie: what is output to one is input to the other and vice-versa). The devices show up in Device Manager just like a real COM port so you interact with them in C# as though they were real hardware devices.
For simplicity's sake, get yourself a com port or null modem emulator. You'll get very far off track, and maybe waste a lot of time, trying to do this yourself.
See this post, too:
Faking an RS232 Serial Port

Determine COM port to which a device locks

I have a micro-controller (Arduino) and wish to determine automatically to which port the micro-controller locks to. The idea is not to have to correct the COM port manually for every app on every computer. Can this be done ? Thanks !
Do you mean:
Micro-controller is an external hardware device
User plugs the device into a random serial port (COM port)
You want to know which COM port it's connected to
?
Also, you are talking about an old-style COM port, are you, not a USB?
Anyway if that is your question, the only way would be to:
Open each COM port on the machine and send data through it, to see (if the micro-controller sends back the expected resonse) whether it's talking to the expected device (e.g. if the device were a modem you might try sending "AT\r" and expect a modem to respond "OK", if there is a modem and if the modem is connected to that serial port).
And/or write a device driver or a service to do just this, instead of an application.

How to send data to another computer with C# like hyperterminal does through modem

I need to create a program that lets me send a string of data or a file through modem, like hyper-terminal does. Im trying to create a program that lets me send electronic billing data to Medicare, and since Medicare only accepts e-bills through modem, only hyper-terminal or another program called PC ACE Pro32 can be used.
I want to create my own program, since hyper-terminal is not user friendly, and the other program has too many things for just sending data.
I've never before had experience creating code for data communication. Can somebody please help me?
There are a lot of pieces here, so let me break this down into sub questions for you:
1) How do I do serial communication in C#?
There are plenty of examples on the internet. A quick search turns up this one and this one, both of which seem to be ok. There are also lots of questions here on SO about C# serial communication.
2) How do I control a modem?
Modems are operated by some version of the AT command set. If you're familiar with manually operating a modem in HyperTerminal, you're essentially doing the same thing, but in code. For example, to test if your modem is paying attention (i.e., that your serial line is talking to the modem properly), you send AT, and see if the modem replies with OK. To dial, you send the modem ATDT <phone number>. Once a modem establishes carrier, then whatever you send down the serial port is transmitted to the remote computer.
3) How do I communicate with medicare's electronic claims system?
This one is up to you! I'd be surprised if they didn't have a web-based claims service though. I would expect that would be a lot easier than doing it over a modem.
Define a receiving connection in remote computer.
Set up a connection to remote computer just like any dial-up connection.
Use socket programming (TCP) to send/receive data to/from remote computer. Note that you must create a client/server application that resides in both remote and local computer.
Seth, your answer is actually very promising. Ill be taking a look at those suggested links right away.
(yes, medicare should be moving to ethernet, but reality is that they are stuck in dialup because they say that "it's more secure than ethernet", when in reality it's not.

Is there any way to know if any device is connect to com1 (RS-232)?

Is there any way to know if any device is connect to com1 (RS-232) ?
thank's in advance
There is no way to tell directly, only indirectly via checking for a signal as Matthew has stated.
As well as DCD, the DTR and DSR signals are commonly used for this as a form of handshake, where each device raises the DTR line and connects it to the DSR input of the dvice it is connected to.
As far as I can tell, from my time working with serial devices, and Wikipedia, the closest you can get is checking the carrier detect (DCD) signal. This article may come in handy if you're doing RS-232 programming. It specifically has a FAQ section which answers "How do you detect when a device is connected or disconnected?"

Categories

Resources