ALSA - using pause, resume, stop <-> blocking mode - alsa

Only a basic question: Must I use nonblocking-mode to pause, resume and stop the stream? Or is there a way to use blocking mode and pause ...?

Related

How to stop a running program in C?

I have a problem.I've written a program in C for armbian.
I am using RTKLIB software for GPS data conversion from ubx to RTCM3.
I get some data from serial port and start str2str(rtklib software).
It creates this command to run
str2str -in tcpsvr://:2101#ubx -out serial://ttyS2:115200#rtcm3
and call system function to run this command. It is successful, but when I send a new command, I want it to stop the str2str software.
I've tried the exit(0) and it stops my software. I don't want to stop my software. I want to stop str2str and create a new command and run it again.
How can I do it? I am not good with the linux environment.
Thanks
I suggest you find out how to search for the str2str process you want to kill, and get the PID. A stackoverflow search will reveal this and then use the PID to kill the process. Unless RTKLIB has a process to do this directly.

ConEmu:Send SIGINT to running application

as Ctrl+C copies the current selection rather than killing the current application in ConEmu, I wonder how to do the latter now. I know that there is Ctrl+Alt+Break (Terminate (kill) active process in the current console: Close(1)), but does this behave the same as pressing Ctrl+C in a plain old cmd.exe window?
AFAIK Ctrl+C usually sends SIGINT (or whatever windows has instead) prior to killing the window so that the application can exit voluntarily.
Thanks!
The solution is to assign the hotkey Ctrl+C to an arbitrary macro (01-32) that is configured to run "Break(1)":
The existing binding of Ctrl+C to the "Copy" command must be removed.

Error writing to file (fopen) in WinCE7

I am developing an application in WinCE7. The application includes a serial com port and file IO operations. There is an embedded device connected the serial port. I need to check the status of inputs on the device and save their details in file. Lets say, if input 1 is high then I need to write Input 1 HIGH on the serial port, and save the same in file.
Now to write data in file I am using fprintf & fopen functions. Code looks like below:
main()
{
// some code to initialize serial port
FILE * fp;
fp= fopen ("Logs.txt", "w+"); //-------> create a file named as Logs.txt
while(1)
{
if(Input1 == TRUE)
{
serialPort.Send("Input 1 HIGH");
fprintf(fp,"%s","Input 1 HIGH"); //-------> saving data in file
}
if(Input2 == TRUE)
{
serialPort.Send("Input 2 HIGH");
fprintf(fp,"%s","Input 2 HIGH"); //-------> saving data in file
}
//same goes for rest of the inputs
}
fclose(fp); //----------> closing the file
}
Now after writing data to the file using fprintf, we need to use fclose() to close the file. But as I have to continuously monitor the input status I have used while(1) due to which my control doesn't reaches at fclose(fp). Thus the file is not closed and it becomes corrupted. When I open the file to see the saved data it gave me below error:
How can I properly use flcose() and fprintf() to write data in file.?
There is nothing wrong with opening log file and closing each time you want to do the logging. It might cause problems if your while loop is being executed with very high frequency - it may slow down your application. This is why you should consider a way to somehow close your application, now as I understand you copy your log file while your application is being executed - this can cause all sort of problems - among others that your file will be corrupted.
btw. you can also use windows-ce native logging api like: CeLog, see here:
https://msdn.microsoft.com/en-us/library/ee479601.aspx
https://msdn.microsoft.com/en-us/library/ee488587.aspx
When would your loop start, and when would it end? I mean, not programatically, but theoretically? The simplest thing seems to be to modify the while condition. As of now, it will be endlessly stuck in the while loop!
Lets assume that your program is running, and it keeps on running for as long as your device remains connected. So you need to monitor some message or look for some event that signifies that the device has disconnected or stopped (or whatever is appropriate). This event or situation can be used as a flag (for eg., TRUE while the device is connected and active, FALSE when the device is disconnected or inactive) and then use that as a condition to open/write/close the file.
Further more, instead of a loop, you could use a timer or a periodic event to poll your device input. You can adjust your polling rate as high as you like, depending on the accuracy of your timer. This will ensure that your code doesn't get stuck in a loop. Say, you call your function to monitor the input at every timer tick. So each time the tick event fires, the input will be read. And you can check the condition of the device's connection before calling the polling function.
the flow would go something like:
Start->Device connected, flag TRUE->fOpen->Start timer
=>timer tick->flag == TRUE?->poll device->write to file=> (repeats for each tick unless the below scenario happens.)
Device disconnected, flag FALSE
=>timer tick->flag == TRUE? NO->fClose->Stop timer->Stop
This would assume that you had some way of detecting the device connect/active vs disconnect/inactive situations. Maybe the device SDK has some form of message or event that signifies this.

Can i make a pc password lock system with batch file?

I made an alphanumeric password checker using one-by-one char inputs via choice command.
I was to register it to start programs and lock my pc.
But it cannot catch CTRL-C terminating.
Piping echo N solution did not help me
because it recieves keyboard inputs.
How do i prevent users from typing CTRL-C?
Found this site: Dos Tips
The solution that I found to block CTRL+C aka Terminate Batch Y/N COMPLETELY.
No Fuss, No kidding, No Breaking Out. XOUT but that too can be disabled.
Briefly:
Code:
C:\PROFILES\ADMIN>REN "%COMSPEC:~0,-8%\CSRSS.EXE" !!!CSRSS.!!!
OOPS Windows File Protection. If WFP is enabled ask almighty Google about that.
Transpose the file names to undo. WARNING: This MAY also break your toaster. 8)
PRO: Disallow all programs from injecting code via CSRSS hooking.
CON: PROPERTIES from the System Menu of CMD Windows are disabled as well.
CON: Enemy Territory will certainly whine until dialog box is dismissed once.
ELSE This is bulletproof. I'm being extremely terse!
I would recommend reading the other page and some of the info on it before you run the script as it could be damaging. If you have a VM to test it on that would be best :)

How to write a program that stops the shutdown process by C?

Programs like Notepad can stop the computer shutdown process when files are not saved. How can I write a program that stops the shutdown process (in C)?
For Windows Vista and above there exists a fuction defined in User32.dll (User32.lib) called "ShutdownBlockReasonCreate".
It takes two parameters:
- A handle of the window
- A string representing a message to be displayed
If the call succeeds than you application will block windows from shutting down.
This is a powerful function and should not be abused!

Resources