App that analyses COM1 activity - serial-port

There's a old piece of software we run in our company that manages RFID cards tapping in/out to open doors.
We want to create an app who identifies who just touched in on a specific place (we have the id for that) and grab their 1st name, to say "Hi [NAME]" on a screen.
As I mentioned, the software is quite old and there are no APIs. It communicates with the RFID hardware via a serial port (COM1).
I was wondering if the best way to get the data I need is to somehow intercept the COM1 traffic and extract/look for the data I want.
Does this sound like the best way to go about it? Would it work, or would it be impossible to get names and numbers from the data being transferred?
Cheers,
Andre

Can you configure the software to use a port other than COM1, or configure the hardware so it's physical serial port is assigned to a different COM port?
If so, take a look at com0com. It's a Windows driver that creates two COM ports on your PC with a virtual NULL modem between them. Data going in on one side comes out on the other.
Here's how you'll set things up:
RFID Reader connected to physical COM port (COMx)
your program bridging COMx to COMy and sniffing the traffic
com0com linking COMy (for your program) to virtual COM1 (for the legacy software)
legacy software
You'll need to write a program to pass data between COMx and COMy while monitoring it for the information you're looking for. Make it simple yet robust, since if it goes down you're reader will stop working.
A Simpler Solution
If you only need to monitor one side of the communications, create a cable that connects the GND and RX pin of COM1 to another COM port. Now your program can monitor that side of the conversation, without interfering with the legacy software.

Well, generally, you can look at RS232 signals, if that's the way you want to do it. It's tricky because you need to "sniff" the signals, which means buying or making a rig that allows the original signals to go through, and then gives you a way to attach to them as well. And, you need to send the transmit and the receive signals to TWO serial ports (on the RX lines). Then you'll probably want to get some "sniffing" software that allows you to look at what you're getting in time sequence (ideally, with time-stamps). Some cutesy protocols also will use modem lines, so you may need to monitor those as well.
Or, try searching for "free serial port monitor" or "serial sniffer".
Good luck!

Related

How can I manually change DSR/CTS signals?

I am using WinAPI to tinker with RS232 ports. Using SetCommState function I've set fRtsControl: RTS_CONTROL_HANDSHAKE and fDtrControl: DTR_CONTROL_HANDSHAKE, so from my understanding both DTR/RTS handshakes are now enabled, and now additionaly I need to set fOutxDsrFlow and fOutxCtsFlow to true, to make this flow work, right?
Having it all set up how can I manually change DSR/CTS to high/low, so I can see what happens?
Or perhaps are RTS/DTR handshakes and DSR/CTS signals completely separate things and I am understanding it incorrectly?
The DSR/CTS signal has only a passive function of acquiring the state or notifying the change as an event.
If you want to actively control it, you need to prepare another hardware or software for it and use another interface independent of the target serial port.
It's relatively easy to have two virtual COM port device drivers with loopback or port-to-port connectivity.
For example, in the case of software, there is something like this.
Connecting to serial port (com port) over network
The same thing is to prepare two USB serial port dongles in terms of hardware and connect them with a cable that crosses DTR/DSR and RTS/CTS.
Both need to be programmed to test the target port/software and run on the opposing port.

Porting Arduino serial communication to standalone atmega328

I have a fairly complex project done on Arduino2560, which I want to port to a standalone Atmega328. My problem is that one feature in the project is that it can communicate with my computer via serial (I made a C# program to handle it on the computer side, using the COM3 port). However, Arduino uses the USB communication for a virtual serial port, and I got a bit confused about how it could be done for the Atmega. It has the RX-TX lines, but what's next? Maybe use some serial-USB converters? What's the best approach for this? Is there anything I should be careful about?
Thanks.
Considering you mention a specific port COM3 on your computer I guess we can assume you have a native RS-232 port (one of those with the sub-D9 male connector that we were used to in the old days but are not so common anymore).
If that's the case, then you can get an RS232 level shifter. You'll just have to make the connections to RX, TX, Vcc, and GND and this device will change the RS-232 voltage levels to whatever your board requires (most likely 5V or 3.3V). Some (maybe most) high-end development boards include this kind of level shifter so maybe check yours in case you already have it (if you do you'll probably see a MAX232 IC somewhere). Or if you are crafty you can also DIY.
If you prefer to connect to a USB port (then, of course, it won't be COM3unless you explicitly change the configuration on Windows Device Manager) you can go for a USB-to-serial adaptor. On that front, you have many choices, starting from the cheapest at maybe 5$, but I'd rather choose one based on the FTDI chip, which is nowadays quite ubiquitous and has proven its reliability. This one is a good example, and at the same cost as the level shifter.
Now, are there any differences between using the native RS-232 or the USB adaptor? The answer is, for most practical purposes, no. If you go to the fine details, like buffer sizes, there will be differences, but if you need to go there you'll need to study the details in both cases to see if the port you have (or the one you're planning to add) meet your needs. For most scenarios, I would choose the USB, if only because you have it everywhere (most laptops don't have a native RS-232).
All of the above (based on RS-232 and/or USB) will work fine for cables running up to 5 meters (~15 ft.) for USB or maybe 10 to 15 meters (~30-45 ft.). This should be enough for most hobbyist or at-home projects. If you want to run longer cables you'll have to go for something like RS-485.
If you choose now the USB adaptor and you think you might need to relocate your board in the future to end up more than 20 meters (15 of RS-232 + 5 of USB) away from your computer just make sure your adaptor includes a TX Enable signal (TXEN). Most adaptors based on the FTDI chip will have this signal on a pin (like the one I linked above), and that will make your life way easier if you want to use RS-485 on a two-cable half-duplex bus.
EDIT: based on the feedback below there is new info that deserves a quick update.
First, you don't have an old school RS-232 port on your PC and second you have to design the connection on the microcontroller's side.
With that in mind it's clear you have to go for the USB solution. But you need to choose if you shift both sides to RS-232 levels or you stay at TTL. That decision depends again on the length of your bus. If it'll be really short (up to 2 meters) then you can stay on TTL, otherwise better shift to RS-232 to be on the safe side. There are many people who will tell you they have much longer serial links but how reliable they are you'll never know.
Since you have to design the board, I guess it makes sense to integrate the MAX232 and a sub D-9 connector there and get the cable you mentioned for your PC.
Or, you can add only a connector on the board and get the Sparkfun level shifter I linked above for the micro's side plus the same USB to RS-232 for your PC.

Serial communications over stlink with stm32f4discovery, is it possible?

I have the following: STM32F407G-DISC1. My goal is to communicate (sending strings back and forth) between my pc and the mcu over serial and I currently am able to do so using the micro-usb (otg) port, while powering separately using the mini-usb st-link port (so using two cables).
Is it possible to use the mini-usb port for serial communications? (eliminating one of the cables)
I have read the user manual and my interpretation is that this is not possible without physical modifications. But I am a beginner and would like to verify I am correct in this interpretation. I have researched thoroughly however most sources seem to not refer to this specific board and it is my understanding with the newer version of st-link it uses this should be achievable.
It is possible - just send the messages via the USART2
You need to solder those two wires as they screw up the design.

Check for Serial Port GSM Modem Connection status

I have a GSM ModeM connected to a serial port, and I use it so send SMS upon certain events.
Since it is not Plug-and-Play, I am confused as to how I'll detect its connection status. Win APIs like GetCommState will obviously not work.
I could periodically send packets of data and check whether the data is being consumed or not, but I'm wary about the risks of polling over performance and clogging up the buffers which might be in use.
So, is there any other method, or some interrupt based thing, which I could use to check whether is still connected, via a serial port, to my system?
I'd be grateful for any help on this.
Thanks.
From Windows 7 onwards, use Windows Mobile Broadband API to get information about a GSM modem.
Serial ports are very primitive communication devices, they date from the very early days of computing. It is what you plugged your ASR-33 teletype into to start banging in your Fortran program. The only reason they are still around is because they are simple, hardware vendors like them because they don't have to spend money developing and supporting a custom api to use their device.
Still, even back in the sixties did a computer have a need to find out if a teletype was attached. Which is done through the hardware handshake signals. The DSR signal, Data Set Ready, is turned on by the device when it is powered up. If you use the .NET SerialPort class then you can check that signal with the SerialPort.DsrHolding property. If you use the winapi then use GetCommModemStatus(), MS_DSR_ON flag.
That still only tells you that some device is attached. If you want to find out that it is the modem that you wrote your program for then you can interrogate it with AT commands, a protocol that's specific to modems. No vendor implements this exactly the same way but you can usually count on an identification from the modem with the ATI command. Check the programming manual for the modem for details.

Serial port - how to perform safe search for my device?

Im writing application that communicate (via serial port) with electronic device which i designed myself.
When my PC application starts - it opens available COM ports one by one and it sends some string ("What are you?" for example).
My device is programmed, to reply to that "magic question" with own ID (for example: "I am evil device for supervising employees").
When my PC software receive that "magic reply" it starts working normally and its not searching other ports anymore.
Of course im not using stupid questions in data transmission, its just example.
Question is - can i send strings like on all (not busy) ports, to discover my device?
If I can - how that "question" string should look? Are there any normalized standards?
This is not first project like this on my desk, but now im developing solution for little industry and i need to pay more attention what my application is doing, because there may be other devices connected to COM ports and I do not know how they can react.
Im sorry, if i made some language mistakes, english is my third language.
Thanks in advance for replies.
After Alvin Wong confirmed my concerns I thought about it again and redesigned my device discovery functionality, because I don't want to abandon that idea.
I will send unique-complicated-ID every 1-5 seconds from device.
When my PC starts - it will try to open sequentially all available ports and will listen for that ID for few seconds.
If application receive that ID - it will be confirmation, that port number/name is correct and I my connection is established.
No, you wouldn't want to do that.
When you are using COM serial port, you have no idea what is plugged into the port. It could be nothing, your device, a modem, a mouse (though I believe nobody uses this anymore...) or whatever you can't even imagine.
Imagine if it is connected to another computer (probably a Linux/router), sending things may lead to execution of "that command", thus creating unexpected effects (though your program may not notice). Or if it is some badly-programmed device, it may trigger a bug in the firmware, thus failing the device and making it malfunction.
In short, in the worst case, you can cause a catastrophic event.
Serial (RS232 or UART I assume) communications don't have a designated transfer protocol (in contrast to USB which has one) to identify a device, so it isn't fail-safe. The user must make sure he selected the correct port. This is probably one of the reasons why hardware manufacturers choose USB, and one of the reasons why USB is so popular, even to computer idiots.

Resources