Finding out comm port settings of a running app - c++

The situation is as follows: I have a piece of hardware connected to a, windows running, PC via a serial port. This custom hardware is used to interface other hardware through GPIB. Now, the software that is used to operate this setup on the PC side needs to be changed without touching the hardware in the middle. The problem is getting a hold of the proper serial comm. parameters used for communication - setting them (the timeouts in particular - baud rates and bits are fine) to arbitrary values in the new software leads to a lot of comm errors so I'd like to know them precisely. The function GetCommTimeouts() would do the job, however you need the handle to the comm. device aquired via call to CreateFile() - only the original software has access to it. So the question is if one can get a hold of these settings from outside of the running, old app?
Thanks,
drinker

I would suggest using a tool like Process Monitor. This tool can monitor the calls that are used to open and configure a serial port.

Related

Qt Bluetooth stuck when connecting to Classic Bluetooth Device

I am currently trying to read out Bluetooth Signals from peripherals using classic BT to control my Qt application. Later on I might use a small BT joystick but for now I am trying to connect to the buttons on my paired headphones.
I have previously
..scanned for remote devices via the QBluetoothDeviceDiscoveryAgent, which returned the QBluetoothDeviceInfo of my headphones.
...scanned for the services on that device using the QBluetoothServiceDiscoveryAgent, which returned QBluetoothServiceInfo with QBluetoothUuid::AV_RemoteControl
...added a socket which should connect to the device, like so:
socket0 = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol);
connect(socket0, &QBluetoothSocket::stateChanged, this , &BluetoothController::socketStateChanged);
connect(socket0, &QBluetoothSocket::readyRead, this, &BluetoothController::readSocket);
connect(socket0, &QBluetoothSocket::connected, this, &BluetoothController::serverConnected);
connect(socket0, &QBluetoothSocket::disconnected, this, &BluetoothController::serverDisconnected);
connect(socket0, QOverload<QBluetoothSocket::SocketError>::of(&QBluetoothSocket::error),
this, &BluetoothController::serverError);
QBluetoothAddress address = info.device().address();
QIODevice::ReadOnly);
socket0->connectToService(address, QBluetoothUuid::AV_RemoteControl, QIODevice::ReadOnly);
At this point the socket state changes to ConnectingState, does not through an error, but also does not not trigger my readyRead() function.
I am new to Bluetooth and may be misunderstanding the concept of how connecting exactly works, so any help will be greatly appreciated.
PS.: I am working on Linux Ubuntu 18.04 and the application log also puts out:
qt.bluetooth.bluez: Missing CAP_NET_ADMIN permission. Cannot determine
whether a found address is of random or public type.
You are trying to run your software as a non-root user. The Bluetooth protocol stack for Linux checks two capabilities, which are required for operations like ones mentioned in your error log — CAP_NET_RAW and CAP_NET_ADMIN. Capabilities are an alternative to "all or nothing" approach with privileged user (root). This gives more fine-grained control over permissions to unprivileged user so it can gain only a part of root's privileges. For more details, read man 7 capabilities.
There're several techniques for leveraging capabilities, one of them are file capabilities. You can achieve the desired effect with setcap(8) like this:
sudo setcap 'cap_net_raw,cap_net_admin+eip' yourapplication

STM32 LWIP PPPos implementation

On my STM32F7 I have to connect a 3G modem using serial port.
I can communicate with the modem using AT commands.
I would like to use PPPos (PPP over serial) library from LWIP to enter in PPP mode. So I take a long look at the official documentation
http://lwip.wikia.com/wiki/PPP
and
https://github.com/tabascoeye/lwip/blob/master/doc/ppp.txt
I understand the guideline but I'm really surprise there is no implementation example with serial port. Indeed, I think there is a lot of modems that have a serial interface, so I thought i can easily find an example of use.
Anyone have already done that or has an example ?
While I cannot publish my example, the general idea when it comes to integrating TCP/IP stack of your choice with its PPP driver is the same among all serial modems and all TCP/IP stacks that I've worked with.
Generally as you've mentioned, you start with configuring the modem using AT commands - things like checking whether SIM card is present, whether it requires PIN, specifying PIN if needed, checking if it has successfully registered in the network. Possibly reading additional information data such as IMEI, IMSI as well as diagnostic data: signal quality, BER etc. Once you're done, you switch the modem to "data" mode (see ATD*99), wait for the modem to respond to that command and pass the responsibility to the TCP/IP stack, as at this point the modem starts talking PPP.
When it comes to integrating your modem with the stack so it can communicate with it, the implementations I've encountered all require implementing some form of low-level API functions for the stack. For LwIP, the wiki page you've linked in the "PPP over serial" section, it is described quite well how those functions should behave. Because TCP/IP stacks are just a software library not tied to specific hardware and they can be run on almost anything (assuming sufficient resources), specific API implementations such as the one discussed are not always provided - there would have to be a ton of examples for it to provide any value. Although if you google around for it, you might find someone having done it for the MCU that you use personally. Assuming you've already done the part where you successfully comminicate with your modem using AT commands, it shouldn't be much more other than using the send/receive functions you already have. Some slight changes may be required, such as adjusting their behavior (synchronous->asynchronous or vice versa) or redirecting received data to the TCP/IP API receive function instead of your AT command parser. Nonetheless, most of the necessary hard work should be done already.
Once the TCP/IP stack takes over, you continue with the modem using provided stack PPP API. For LwIP see functions such as: pppSetAuth, pppOverSerialOpen. Those will cause the stack to internally handle the necessary communication with the modem over PPP: LCP, PAP/CHAP, IPCP. Once that part is done (you retrieve IP configuration data from the network) it becomes transparent how this operates - it becomes one (of possibly multiple) network interfaces and you use it just as any other one, for example using socket API.

DFU issues on LPC microcontroler

I am writing an application for LPC4330 microcontroller, that will allow the user to update the firmware using USB DFU class. I wrote all of the code and I wanted to test it using dfu-util software. But when I try to do it few errors appear:
When I list the USB devices, two elements with the same parameters (vendor id, device id, configuration and interface) appear. The situation changes when I make a breakpoint in the application, in place where interrupt process function is called. Then only one device appears on the list.
I cannot detach the device because I get error "No USB device is DFU capable". Even when only one device is listed by dfu-util.
When only one device is listed I can start performing upload/download operation, but the application sends me an error, that interface cannot be claimed.
What could be a reason of these problems? Could it be connected with LPC4330 feature allowing user to flash the programme to the memory using dfu?
Thank you in advance for your answer!
You write your own DFU that is fine. Can I get to know from which mode you are trying to do firmware upgrade? Like downstream or upstream.
And if you are trying from any one of the mode please make sure that you are creating the device for particular mode only.
Detach will work, only when your DFU should have in run time mode. So please make sure that you are in run time mode or DFU mode. And before Detach try to reset your device by using software command

Testing Serial port application

I have a code to send data to serial port. I just want to make sure that it is sending the data properly. I checked the function's return value and the number of bytes written and it is success. Is there any other way to actually see the data whatever i am writing?
if(WriteFile(m_hSerialComm, pszBuf, dwSize, &dwNumberOfBytesWritten, NULL) != 0)
I tried to use "Advanced Terminal Port software"
but the data is not coming in that window.
There are several ways to test your software. If you have two serial ports then connect them with a cable and listen on the other port with a terminal application such as the one you mentioned. Otherwise, you could loop back on the same port by connecting pins 2 and 3 together. A hardware-free option would be to use virtual serial ports as provided by tools like com0com.
Assuming from your piece of code that you are developing on a Microsoft Windows operating system, I would recommend the Portmon for Windows "official" serial port monitoring utility. I have used it in in the past, and found it simple enough, and also quite useful specifically for its multiple filtering/search options (since sometimes the amount of data passed on your serial port is huge).
If all you want is a log of the data you have written to your own port, why not encapsulate your WriteFile (and maybe also your ReadFile) functions in some "utility" function(s) that reads/writes both on your serial port and in some log file? You could even add timestamps, and filter "whatever you are looking for" straight from your own code.
I found this last option really useful when remotely debugging applications with customers. You add a button in your application that toggles the logging on and off, then you simply have to ask your customer to hit the "log" button and to send you the results.

Is there a way for C++ application function to turn on the computer?

i need to find away to turn on the pc from c++ application ,
is there any way to do this?
Thanks
If the computer is off, it can't be executing code, and therefore can't turn itself on programmatically.
ACPI changes that somewhat, but for us to be able to help, you have to be more specific about your exact requirements.
If you need to turn on a different computer, take a look at Wake-on-LAN.
You will not be able to write a program to turn a computer on that the program itself is installed on.
If you need to write an application that will turn on a different computer, Wake-on-LAN is the tool for you. Modern desktops have NICs that is always receiving power - even if the computer is in an S5 state. Assuming the BIOS supports it and it is enabled.
Wake-On-LAN works by sending a Magic Packet to the NIC. The details of what the payload consists of is outlined in the article.
This is possibly a duplicate of C#: How to wake up system which has been shutdown? (although that is C#).
One way to do it under windows is to create a timer with CreateWaitableTimer(), set the time with SetWaitableTimer() and then do a WaitForSingleObject(). Your code will pause, and you can put the computer into standby (maybe also hibernation, but not shutdown). When the timer is reached, the PC will resume and so will your program.
See here for a complete example in C. The example shows how to calculate the time difference for the timer, and how to do the waiting in a thread (if you are writing a graphical application).
I have to add, you can also schedule the computer to wake up using the Windows Task Scheduler ('Wake the computer to run this task'). This possibly also works when the computer is shut down. There is also an option in some computers BIOS to set a wake time.
Under Linux, you can set the computer to wake up by writing to a special file:
echo 2006-02-09 23:05:00 > /proc/acpi/alarm
Note that I haven't tested all of this, and it is highly dependent on the hardware (mainboard), but some kind of wake-up should be available on all modern PCs.
See also: http://en.wikipedia.org/wiki/Real-time_clock_alarm ,
and here is a program that claims to do it on windows: http://www.dennisbabkin.com/wosb/
Use strip. If you require a Windows computer to be turned on, the cross-tools i686-w64-mingw32-strip or x86_64-w64-mingw32-strip should be used. These command-line programs modify an executable, and the result is able to turn on a computer.
How could you turn on a computer from an application, when no processes are running on it when it's shut down ? You can turn on another computer (Wake on Lan), but not the one you are running.
It is possible.
First thing to do is configure Wake On Lan. Check out this post on Lifehacker on how to do it: http://lifehacker.com/348197/access-your-computer-anytime-and-save-energy-with-wake+on+lan.
(Or this link: http://hblg.info/2011/08/21/Wake-on-LAN-and-remote-login.html)
Then you need to send a magic packet from your C++ application. There are several web services that already do this from javascript (wakeonlan.me) , but it can be done from within a C++ application as well.
Chances are, that if you want to do this, you are working with servers.
In such case, your mainboard may should an IMPI baseboard management controller.
IPMI may be used to cycle the chassis power remotely.
Generally, the BMC will have its own IP address, to which you may connect to send control messages.