How can i emulate streaming data from a serial port? - gps

I have a text file containing NMEA (GPS) data that I' like to replay to a COM port so the application I'm building can read it.
I considered writing a quick C# console app to loop over the file but I don't have any COM ports. This appraoch would require a virtual COM port and I'm not sure what challenges that would entail.
I also looked at GPSGate. Nice product but it doesn't seem to replay NMEA files over one of its virtual com ports.
How can I stream an existing text file to simulate GPS over a serial connection? I prefer a serial port, rather than mocking, to avoid reworking the application I'm developing and to facilitate use with other applications that use GPS over serial ports for which we don't have source code.
Update 1 - I downloaded a trial version of Virtual Serial Port Driver by Eltima and within a few minutes had some C# code writing to a serial port and appearing in Termite. Yes, it works but $100 seems excessive for what I'm trying to accomplish. Open source or free commercial would be preferred.

gpsfake is part of the gpsd project
gpsfake is a test harness for gpsd and its clients. It opens a pty (pseudo-TTY), launches a gpsd instance that thinks the slave side of the pty is its GPS device, and repeatedly feeds the contents of one or more test logfiles through the master side to the GPS. If there are multiple logfiles, sentences from them are interleaved in the order the files are specified.
You can port the output to a virtual serial via /usr/bin/gpspipe -r | socat - PTY,link=/tmp/gpsd.pty,raw using gpspipe, also from the gpsd project, to be picked up however you choose.
It is POSIX compliant.

You need a virtual serial port such as:
http://sourceforge.net/projects/com0com/
and a hyper terminal replacement.. in XP and earlier it was very easy with the shipped copy of hyperterminal as mentioned bellow..
You set up a virtual null modem connection
Null modem has a COM4 to COM5 Connection established as Null modem std gps is 4800Baud
Hyperterminal to COM5
Application to COM4
Copy paste your NMEA Values into Hyperterminal this isn't 1Hz like GPS though.. to enable 1Hz(or 1 line per second) you will need to find a different application than hyperterminal to send the messages at 1 second increments.

Related

Node-red "serial port temporarily unavailable, cannot lock serial port" problem

I am trying to control some sensors and a hydraulic system and a vane with a servo via raspberry pi and arduino. I use serial node to communicate with arduino. One serial node for incoming data from arduino and one for sending data to arduino over node-red. The problem is node-red cannot lock the usb serial port and cannot communicate with arduino while arduino ide can do it. In Node-red forum They have advised me to closed other programs that can use the serial port. I have closed arduino ide and reset Pi 4 but nothing changed. I have restart them but problem still stands.
Is there a way to solve this locking problem?
How can I see the serial ports and the programs that use the ports?
Can I prevent them to use these ports with a javascript or a python function code?
I have found the problem and fix it. There is no other program or software was using serial port /dev/ttyACM0 was being used by another flow in a passive node-red window. I have to delete that page and nodes.

Write data to ESP32 over USB connection with MicroPython

I have an ESP32 connected to a computer via USB port. I can use the ESP32 to send data over the serial connection using the print statement, I need to periodically write commands into the ESP32. How do I read what is coming over the COM port on the ESP32 in MicroPython? I unsuccessfully tried many variations of the following:
from machine import UART
uart = UART(115200)
while 1:
if uart.any():
msg = uart.read()
print(msg)
Print is for printing in REPL only. If you want to communicate with MCU via serial port you have to write to it.
The simplest example would be:
# your imports and initialization
msg = uart.read()
uart.write(msg)
And on your computer you have to run some serial console e.g. picocom or if you're Windows user then Putty. After connection just type something in terminal and hit enter. This is basically all you need to start echoing messages. You can use Python serial library on your machine but I suggest to stick with simplest tools until you connect successfully for the first time.
Two more things though:
Your init is incomplete imho. It should contain port and timeout options.
You can't use the same USB port for programming and communication (like in Arduino). REPL is going to blow your connection up. You need USB to serial adapter for $2 from China and connect to other UART pins (there are 3 UART interfaces on ESP32).

What is the best way to send data to PC from "MCU + Wifi Module"?

I don't know anything about wireless protocols. With this quick setup i want to get inside. I just want to write a windows desktop application which receives only a couple of bytes of data from a mcu+wifi module "NodeMCU" which is connected to the same router. I can write a simple desktop app with visual studio. But sending data over ip has many methods as far as i read.
What is the simplest way to achieve? (I'm experienced in STM32 mcu's and electronics except internet protocols.)
You can send the data from the embedded board (with the mcu) to a TTL-To-WiFi module. Then from your PC application you should open a socket and connect to the module IP to listen in the correct port the data from your board.. There are a lot of module in the market used as "bridge" or converter: you have only to setup in it the local IP address, the destination IP (your PC) and the TCP port where you want to send data. From point of view of the board you use a standard USART and the message is sent to the destination IP. In your PC application you should be able to create a socket and connect it to the wi-fi module.

how to transmit serial data from GPS device to computer through IP?

Well..I have found some third party application regarding sending data from com port to IP. but I have not found any basic tutorial regarding them. so can anyone help me with this? I have a GPS device which I will connect to my laptop through usb to serial adapter.Now I need to send that data from a laptop to another laptop on same network. Can I use putty to view that data in another laptop(receiver)? Is virtual serial port driver meant for this kind of application?
If you do not want to write your own tool for it, you can simply use ncat and set up a daemon that reads piped data from one process and broadcasts it to all connected clients.
If you want something that reads the data from the serial port and then transmits it to clients, you'll need to write a server application that accepts connections and sends data around, but there's entire books on this. It should be easy to do for your purposes as written here, but it depends on the amount of control you need.
Alternatively you can use a virtual serial port application as you had mentioned, which might be the easiest route. The two devices will need to be on the same network unless the application supports TCP based virtualization instead of the common Ethernet based implementation.
This Python script works very well as a free "device server". Just enter the serial port configuration and the IP address and port information.
https://github.com/jaredly/pydbgp/blob/master/symbian/serial_tcp_redirect.py
This can work on both Windows and Linux.
You need pyserial.
You can always try using stand alone hardware such as the SENA LS100 device server.

AT command with 3g modem while it is connected

I would like to query a modem using AT commands using hyperterminal while it is connected, but whenever I try to establish a hyperterm connection, it says that it is in use. I saw a similar post How can I communicate with a 3G modem via pySerial while it is connected? that has the same problem, but my system in running on windows xp, therefore i am unable to switch to a different tty.
Hence I would like to ask if there are any solutions or alternatives to query the modem. Thank you!
3G modems typically (always?) provides two serial interfaces that can be used for AT command communication. Those serial interfaces ends up as /dev/ttyACM0 + /dev/ttyACM1 or /dev/ttyUSB0 + /dev/ttyUSB1 on Linux, /dev/cuaU0 + /dev/cuaU1 on FreeBSD, and on windows machines they should end up as COM<N> + COM<M> for some N and M number (not necessarily next to each other).
So open the device manager and try to find the other serial interface which is not used by hyper terminal and use that one.