I have many serial ports, but i want to select a particular one i.e /dev/ttyUSB0 to send and receive data, how to set port as /dev/ttyUSB0, i don't want user to select from a number of available ports, i just want to use /dev/USB0 only.
You can construct a serial port object using QSerialPort port("/dev/ttyUSB0"). This QSerialPort constructor accepts port name in the form it's present in QSerialPortInfo::portName(). It's not documented that this name is in the "/dev/ttyUSB0" form but it appears to be so.
Related
Quick question...
Can the ESP32 AsyncWebServer port be set/reset AFTER the server has been declared?
The server is declared after the global variables, but before any functions, with the line:
AsyncWebServer server(PortNumber);
Usually, the port number is 80 (the default HTTP port).
However, I have the need to use a different port and the port will be chosen by the user from a WiFi credentials page and then stored in NVS.
So, I need to retrieve the port number from the NVS before I execute the AsyncWebServer command, or be able to change the port number on the fly.
How can I achieve this?
Looking at the ESPAsyncWebserver declaration there doesn't seem to be a way to change or set the port after creating an instance of it. But isn't the solution to your problem as simple as creating the server later, after your configuration settings have been read? Something to this tune:
uint16_t port = config.read("server_port");
ESPAsyncWebserver* server = new ESPAsyncWebserver(port);
The answer to this is here: Answer
I emulate the firmware of a embedded device with qemu-system-arm. The output of the console is working fine by appending "console=ttyAMA0" to the kernel. On the guest there is a binary which opens another serial port for communication (bi-directional) on /dev/ttyGS0 and listens on that port. Now I need to connect to this port from the host, to send commands to the binary and receive the output.
I already tried different things like creating character devices and pseudo ttys, but I don't know how to define the serial device for the guest.
Is there a way to do this?
Thanks in advance.
If you pass multiple -serial options to QEMU they will be interpreted as defining what you want to do for UARTs 0, 1, 2, etc. So for example "-serial stdio -serial tcp::4444,server" will send UART 0 to your terminal and connect UART 1 to a TCP server on port 4444 which you can then connect to with netcat or similar utility. (You can connect serial output to a lot of different backends, not just stdio or TCP: check the QEMU documentation.)
(NB: this relies on your board model actually creating multiple UARTs and wiring them up to the command line options correctly, of course.)
I have a machine with 4 Ethernet Interfaces (ensf1s1, ensf1s2, ensf1s3, ensf1f4) and using GNAT.Sockets I need to be able to send/recieve data over each interface.
The code I am using is
Create_Socket(SendFrom1, Family_Inet, Socket_Datagram);
Create_Socket(SendFrom2, Family_Inet, Socket_Datagram);
...
Bind_Socket(SendFrom1, SendFrom1Address);
Bind_Socket(SendFrom2, SendFrom2Address);
...
Channel1 := Stream(SendFrom1, SendToAddress1);
Channel2 := Stream(SendFrom2, SendToAddress2);
...
With IP addresses configured as 192.168.1.(101/102/103/104) I am getting all messages sent over a single interface with the correctly specified Source and Destination IPs in the packet.
I read in another question that having multiple NICs on the same subnet could cause a problem to some OS's so I changed to 192.168.1.101, 192.168.2.102 etc with a Subnet mask of 255.255.0.0. Using the same code with Addresses corrected this only sent data intended for the interface which previously sent all messages but nothing on the other 3.
Have I missed something in my Socket configuration to ensure a Socket is binded to the adaptor with the SendFromAddress specified? The OS is RHEL 7 if that's relevant.
Your question is related to how sockets are working.
If you bind your socket to a specific address, you will receive packets only for that destination address.
To receive packets from any of your four interfaces, you may bind to the INADDR_ANY address. You will do this as follows:
Address : GNAT.Sockets.Sock_Addr_Type;
SendFromAll : GNAT.Sockets.Socket_Type;
...
Address.Port := 0; -- Or whatever fixed port you like
Address.Addr := GNAT.Sockets.Any_Inet_Addr;
GNAT.Sockets.Bind_Socket (SendFromAll, Address);
Using this implementation, the SendFromAll socket will receive data from any interface. With Receive_Socket, you can get the sender address. Then when you send data back to the client using the SendFromAll socket, the system will pick an interface depending on the destination address and the network routing tables. On Linux, it will depend on the routing policy (ip rule) and on the routing tables (ip route).
Client : GNAT.Sockets.Sock_Addr_Type;
Buffer : Ada.Streams.Stream_Element_Array (0 .. 8192);
Last : Ada.Streams.Stream_Element_Offset;
....
GNAT.Sockets.Receive_Socket (SendFromAll, Buffer, Last, Client);
GNAT.Sockets.Send_Socket (SendFromAll, Buffer (Buffer'First .. Last), Last, Client);
Now if you really need to bind a socket to an interface, you must get the IP address of that interface. If you have several interfaces, you have to get their own IP addresses. There is no easy way with GNAT.Sockets to do this. You can use the Get_Host_By_Name function but you must setup different names for each interface (otherwise you'll get the same IP for each socket).
Another way which is not possible with GNAT.Sockets is to use the SO_BINDTODEVICE socket option. You bind the socket to the interface name (you don't need to get the IP).
What may happen to you is that you are using the same IP address for each Bind_Socket call.
these are the write commands towards a serial port:
sendCommand(SendCOM3,"hallo\r\r") --- text format
sendCommand(SendCOM4,"\u0001\u0012\u0123\u000F\r\r") --- binary format
and works fine.
Now, who can tell me what I have to do to get the response message over the same serial port ?
Thanks
Ciao
marco
Since you're already writing to the port, I'm assuming you have the serial binding as an addon and the serial ports enabled.
Create a new item and bind it to the serial port to assign incoming data. For example,
String Hallo1 "Hallo [%s]" (hall0) {serial="SendCOM3"}
The data is a string that you'll need to parse. Restart OpenHAB, check the logs and you should see your item updated.
Add serial binding .jar file to your addons directory
org.openhab.binding.serial-1.7.1.jar
And add item to yourschema.items:
String MySerialDevice "MySerialDevice [%s]" { serial="/dev/ttyUSB0" }
change ttyUSB0 to your real tty serial device.
QNetworkConfigurationManager::configurationChanged() signal is not getting called by the system when I am inserting a LAN cable with a valid IP(Ethernet interface).
It is getting called for WLAN and USB interface but not for ETHERNET config changes
Hope to get some pointers on this.