serial programming in vc++ mfc - visual-c++

I am writing two applications one is continuosly listening to "COM3" port and printing data.
When i run other application which should write to that "COM3" port i am getting error serial port does not exist for writing.
can 2 applications open handle to access the same serial COM port in our system at the time

This is not possible, Windows doesn't allow a serial port to be shared between processes. Once one process opens a port, another will get error 5 (access denied) when it tries to open the same port. Serial ports are far too primitive to allow any kind of sharing protocol.
You need a null modem. Either in hardware by using two ports, connect RxD to Txd. Or in software, a device driver that emulates serial ports. Like this one.

Related

How to create a dummy "pipe" pseudo-serial device on Linux?

I need to write a program (C++) that uses a serial port to communicate with another device. The other device isn't even built yet so I need a software emulator For various reasons there is no point going into here, the software emulator needs to run on a different machine. I would like to send the data via UDP from the software emulator to the machine my program is running on and have it received by another serial interface type program that in some way acts as a serial port (serial tty device).
I also want to test my program in an automated fashion in a VM. Ideally my test program would also use UDP and would use the same UDP-serial interface program to forward the data back and forwards between my test program and the program under test.
Time is very tight. I don't really have time to learn to write and install kernel level device drivers.
I would be very grateful for any pointers as to how I can create some sort of "pipe" or "loopback" pseudo-serial device.
I am working on Linux.
Credit to meuh for his tip-off.
socat UDP:127.0.0.1:5001,bind=127.0.0.1:5000 \
PTY,link=/dev/ttyS0,raw,echo=0,waitslave
This listens on UDP port 5000 on the loopback network interface. All data received is sent to the virtual serial device at /dev/ttyS0. All data received on the virtual serial device is sent to UDP address 127.0.0.1:5001.
The IP address can be remote.
The command must be run as root, as must the process connecting to the serial port. To avoid this use a different file path, e.g. /tmp/ttyS99.
Apparently the file path specified must not already exist. However my PC has /dev/ttyS0 all the way to /dev/ttyS31 despite not having any serial ports, and using /dev/ttyS0 works fine. I suppose if I actually had a real serial port this wouldn't work.

how do you open FTDI serial ports ttyUSBx such that we can run 2 applications on it?

I am writing a python pyserial app and need to debug it. It is not getting anything on its rx beyond the prompt. I would like to open up a parallel minicom on same tty and be able to see the port rx.
Is this possible without hardware logging ? Can I simply use a serial settings to allow 2 apps to run simultaneously on ttyUSB0 ?
Short answer: No, you can't access your serial ports from two processes at the same time.
There are workarounds that can give you a much cheaper solution than purchasing a hardware sniffer or a scope with serial decoding capabilities though.
You will have to define a couple of virtual serial ports and use port forwarding. This procedure has been explained here: on Linux and Windows 1, 2.

serial port on laptop with usb adapters

I was tasked to do a serial port related software and I'm trying to do some initial preparations. I'm using windows 7.
My laptop physically only has USB ports (besides the screen), is it possible to check serial ports like this at all? Will any cable adapters help?
Windows 7 device manager shows nothing is connected to serial ports, which makes sense. However I've written a small application (in node.js) to list the connected serial ports. It lists COM3 as a connected port (though no information on manufacturer or any id). Is there an explanation to this?
To software, a USB-to-RS232 adapter is no different than any other RS232 serial port. It will show up on COM1 or whatever just like a physical port would.
If you have a serial port showing up on your system on COM3, then something is there. It isn't uncommon for RS232 ports to be on the motherboard, but not be exposed externally. Also, if your laptop has a dial-up modem, then this would be on the COM port as well. If you have a cellular radio, these are often on COM ports.

Pseudo serial connection for testing

There is an application which wirtes to a serial connection and reads from a serial connection. I am testing it and can not change it. My test environment contains two computers and applications on that two computers send something to each other over the serial connection. I want to create a pseudo serial connection in order to test on only one computer. So that, one application will write to that pseudo serial connection and the other one, which is on the same computer, will read it.
Is such a pseudo serial connection possible? My test computer has only one serial connection but if it is required I can use a virtual machine which has got two serial connections.
i found this com0com. http://sourceforge.net/projects/com0com/files/com0com/3.0.0.0/
It will create two virtual serial ports. You can test it by using two Putty windows. Just chose different COM port.
Let me know if it was helpful.
You could use USB-to-RS232 adapters to get additional COM ports. Hook your two COM ports together with a null modem cable. Then your test program can open one port and talk to your app under test.

how to read from and write to a serial port (ttys0) from another pc via ethernet (eth0) on Ubuntu/Debian?

Well, there are two pc's connected via Wi-Fi and one of those (let's call it A) has a serial port printer (in ttys0) and a measure serial port device (in ttys1) connected too. So B needs to read some values from the mesure device connected on A and then write to the printer connected on A using a network connection.
ser2net is a good solution for this
aptitude install ser2net
Then edit the config in /etc/ser2net.conf
You can then make a tcp connection to a defined port and be connected to the serial port on the remote computer - very useful.
I don't know if Ubuntu has anything built-in, but you could run a couple of daemons using netcat. Of course, if you want it to be secure, you'd need to do a little more work.

Resources