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

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.

Related

Devcon Disable Port vs Digital Relay

I have a device connected to a USB and it periodically sends data to my PC. During the time it is not sending data, the USB cable needs to be removed, else, the device won't work (a fail-safe feature, if the USB cable is connected and attached to pc, the device is in communication mode, if the USB cable is disconnected from pc, it is in stand-alone operation mode).
I was thinking to use the Devcon so I font has to use another hardware, I'll just disable the USB port during an operation mode, then enable it during communication mode. However, the periodic transfer of data can be set to every 5,10,15,30 minutes depending on the settings.
My question is, will it be okay to disable/enable the USB port periodically? Say every 5 minutes? Won't it cause any problem in the long run? Or would it be more efficient for me to use external hardware, a switch to connect/disconnect the USB? Appreciate any advice or thoughts.
If devcon works for you, I don't see why it would cause any problems in the long run. There is no inherent reason why the hardware should get damaged when you run some commands in your software to disable a USB port.
Using external hardware to accomplish the same thing would not be more efficient because you'd have to pay for the hardware and maintain it.

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).

How can i emulate streaming data from a serial port?

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.

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.

communication to usb port by using vc++2008

I want to communicate to halios system(hardware) through usb port. I have a code which shows that the device is attached. I used USBTrace which shows that how many bytes are going in and out from the device to the host. But I do not know how to implement this is vc++2008 and by using windows xp.
If this is an evaluation board for an Elmos optical sensor IC I would guess that a USB to serial converter is involved. You could confirm this by watching Windows Device Manager for a new COM port appearing when you attach the device.
If that's the case you can use Basic example of serial communication with Windows XP/win32 but you may need to contact Elmos for the command protocol.