I'm trying to get alsamixer & softvol to work together, but can't figure out how to combine them. They work fine on their own but error out once I try to combine them. Probably because I don't quite understand how it all works together.
I tried placing the plugequal as a slave to default, and to softvol afterwards - no luck.
Placing it after after softvol from default and then routing to plugequal also has the same result.
The error:
[src/libout123/modules/alsa.c:80] error: initialize_device(): no configuration available
main: [src/mpg123.c:309] error: out123 error 7: failed to open device
My asound.conf, softvol works.
pcm.!default {
type plug
slave.pcm softvol
# slave.pcm plugequal
}
ctl.!default {
type hw
card 0
}
ctl.equal {
type equal
}
pcm.plugequal {
type equal
slave.pcm "plughw:0,0"
# slave.pcm softvol # Nope..
}
pcm.equal {
type plug
slave.pcm plugequal
}
pcm.softvol {
type softvol
slave {
pcm dmix
# pcm plugequal # Yeah, no
# pcm "plughw:0,0" # Does not work..
}
control {
name "PCM"
card 0
}
}
Related
I'm trying to write a program to shift the key of a midi file. Basically, I just need to shift every note event by a given amount and live the rest unchanged. I found it easy to use MIKMIDI to read, parse, modify and write back the stream.
Unfortunately, I have a problem that I'm unable to solve. I've a loop in which I select the note events and add/subtract the desired shift value, but when I append the event in the output track I get a message from the MIKMIDI library:
"Warning: attempted to insert a NULL event".
The code I wrote is the following:
for event in inputTrack.events {
if event.eventType == .midiNoteMessage {
var tmpData = event.data
if (event.data[0] != 9) { // skip percussion channel
tmpData[1] = event.data[1] - shift
}
let outEvent = MIKMIDIEvent(timeStamp: event.timeStamp, midiEventType: .midiNoteMessage, data: tmpData)!
outputSeq.tracks[i].events.append(outEvent)
}
else {
outSeq.tracks[i].events.append(event)
}
}
BTW, the code works perfectly (the midi file is plays as expected), it is just that it takes minutes to execute in debugging mode due to the infinite sequence of warning messages printed in the debug screen.
Thanks!
I'm currently studying Powershell and working on a script that grabs Display configuration from windows system. I get 2 question:
Question 1. The script is:
"Display Config" >> system1.txt
"----------------------------------------------------------------------------
---------------------------------" >> system1.txt
add-type -assemblyName system.windows.forms
[system.windows.forms.screen]::AllScreens | Format-List Bounds | out-file -append system1.txt
The output is the result of resolution of 2 monitors, just like that:
Bounds : {X=0,Y=0,Width=1920,Height=1080}
Bounds : {X=1920,Y=0,Width=2560,Height=1440}
But I just want to extract values of 'Width' and 'Height', and the make output show like:
Width:1920
Height:1080
Width:2560
Height:1440
Question2: For this script:
Get-WmiObject WmiMonitorconnectionparams -Namespace root\wmi | format-List
VideoOutputTechnology | out-file -append system1.txt
I get results:
VideoOutputTechnology : 10
VideoOutputTechnology : 4
But the value 4 and 10 need to be decoded, ie '10 = Displayport External' according to an url: https://technet.microsoft.com/en-us/ff546605(v=vs.89)
How could I decode the value according to the URL and make the result only show like 'Displayport External' in the output txt?
I would greatly appreciate your reply.
Question 1:
LotPings has effectively provided a solution in a comment (PSv3+):
[system.windows.forms.screen]::AllScreens.Bounds |
Format-List Width, Height >> system1.txt
.Bounds is directly applied to the array returned by ::AllScreens, in which case an array of the array's elements' respective .Bounds property values is conveniently returned, which is a PSv3+ feature called member-access enumeration.
Format-List Width, Height then extracts the .Width and .Height property values from the resulting [System.Drawing.Rectangle] instances and displays them as a list.
Note: The purpose of all Format-* cmdlets is to create output for display only, i.e., to produce output that is friendly to the human observer, but ill-suited for further programmatic processing.
Since you're using Out-File -Append without additional options, >> is a convenient shortcut. (You'll get UTF16-LE-encoded ("Unicode") files.)
Question 2:
PowerShell has great built-in support for .NET enumerations ([enum]-derived types), but what WMI reports in your case are simple integers [System.UInt32], so you have to perform your own mapping.
In PSv5+ you can define your own [enum] types, however, in which case a simple cast to that type can help you:
enum VideoOutputTechnology {
D3DKMDT_VOT_UNINITIALIZED = -2
D3DKMDT_VOT_OTHER = -1
D3DKMDT_VOT_HD15 = 0
# ...
D3DKMDT_VOT_DVI = 4
D3DKMDT_VOT_DISPLAYPORT_EXTERNAL = 10
# ...
}
In PSv4- you can use `Add-Type -TypeDefinition` to define the enum via a string containing a _C#_ enum definition.
Note:
I've retained the original symbolic constant names from https://technet.microsoft.com/en-us/ff546605(v=vs.89), but you're free to rename to something friendlier; e.g., D3DKMDT_VOT_DISPLAYPORT_EXTERNAL -> Displayport_External - but note that embedded spaces and special characters are not allowed. If that isn't friendly enough, consider Theo's helpful solution.
You're creating a static copy of the symbolic constants, so the two sets could get out of sync, though new constants are probably added only rarely.
(I'm not aware of any preexisting .NET enum type that defines these constants and they seem to be defined in a *.h file that you cannot assume to be present on every machine; you could web-scrape the URL, but that is brittle.)
You can then apply the cast in the context of a calculated property in order to translate the raw integer into its symbolic name:
Get-WmiObject WmiMonitorconnectionparams -Namespace root\wmi |
Format-List #{
n='VideoOutputTechnology'
e={ [VideoOutputTechnology] $_.VideoOutputTechnology }
} >> system1.txt
This should yield:
VideoOutputTechnology : D3DKMDT_VOT_DISPLAYPORT_EXTERNAL
VideoOutputTechnology : D3DKMDT_VOT_DVI
As for the VideoOutputTechnology values. Yes, they are values from the D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY enumeration, but i believe you want to return a more descriptive string. In that case you could use a small function to translate the value to string:
function Resolve-VideoOutputTechnology {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, Mandatory = $true, Position = 0)]
[int64]$VideoOutputTechnology
)
switch ($VideoOutputTechnology) {
-2 { return 'Uninitialized connector' } # D3DKMDT_VOT_UNINITIALIZED
-1 { return 'Unknown connector' } # D3DKMDT_VOT_OTHER
0 { return 'VGA connector' } # D3DKMDT_VOT_HD15
1 { return 'S-video connector' } # D3DKMDT_VOT_SVIDEO
2 { return 'Composite video connector' } # D3DKMDT_VOT_COMPOSITE_VIDEO
3 { return 'Component video connector' } # D3DKMDT_VOT_COMPONENT_VIDEO
4 { return 'Digital Video Interface (DVI) connector' } # D3DKMDT_VOT_DVI
5 { return 'High-Definition Multimedia Interface (HDMI) connector' } # D3DKMDT_VOT_HDMI
6 { return 'Low Voltage Differential Swing (LVDS) or Mobile Industry Processor Interface (MIPI) Digital Serial Interface (DSI) connector' } # D3DKMDT_VOT_LVDS
8 { return 'D-Jpn connector' } # D3DKMDT_VOT_D_JPN
9 { return 'SDI connector' } # D3DKMDT_VOT_SDI
10 { return 'External display port' } # D3DKMDT_VOT_DISPLAYPORT_EXTERNAL
11 { return 'Embedded display port' } # D3DKMDT_VOT_DISPLAYPORT_EMBEDDED
12 { return 'External Unified Display Interface (UDI)' } # D3DKMDT_VOT_UDI_EXTERNAL
13 { return 'Embedded Unified Display Interface (UDI)' } # D3DKMDT_VOT_UDI_EMBEDDED
14 { return 'Dongle cable that supports SDTV connector' } # D3DKMDT_VOT_SDTVDONGLE
15 { return 'Miracast connected session' } # D3DKMDT_VOT_MIRACAST
0x80000000 { return 'Internally display device (the internal connection in a laptop computer)' } # D3DKMDT_VOT_INTERNAL
default { return 'Unknown connector' }
}
}
I need an example that use try..catch..finally clause where the finally is NECESSARY vs try..catch clause where finally is optional. The example below only demonstrated that finally is optional because with or without it, it won't make any different to my output.
My Example (note: $ErrorActionPreference is Continue):
try {
$value = 5 / 0
} catch {
Write-Output "illegal operation"
}
$t = Get-Date
Write-Output ("operation is done at " + "$t")
The reason is I need to know where finally clause become necessary vs just put finally clause no matter what.
A finally clause is just a logical construct saying "this statement or group of statements should always be run at the end of the try block, regardless of whether there was an error or not". It tells people reading the code that there is a logical connection between the code in the try and finally blocks (e.g. opening and closing a database connection). However, beyond that there is no essential difference between
try {
5 / 0
} catch {
'illegal operation'
}
'continued'
and
try {
5 / 0
} catch {
'illegal operation'
} finally {
'continued'
}
You can find some discussion of the subject here.
I think the only way it would make a difference is if you return or exit in the try block:
try {
'foo' # <-- displayed
exit
} finally {
'bar' # <-- displayed
}
'baz' # <-- not displayed
but maybe something like that is just bad design.
I need to specify to specman a maximal amount of dut_errors in the test, which after that limit the test should be terminated.
Currently i have the option to terminate the test when an error accord or never.
You can also change the check_effect to ERROR, so it will cause the run to stop. For example (I am taking here Thorsten's example, and modify it):
extend sn_util {
!count_errors: uint;
};
extend dut_error_struct {
pre_error() is also {
util.count_errors += 1;
if util.count_errors > 5 {
set_check_effect(ERROR);
};
};
};
AFAIK this does not work out of the box. You could count the errors by using a global variable and extending the error struct, something in the line of
extend sn_util {
!count_errors: uint;
count() is {
count_errors += 1;
if count_errors > 5 { stop_run() };
};
};
extend dut_error_struct {
write() is also { util.count() };
};
There might even be an object in global that does the counting already, but probably not documented.
I'm trying to read weight from Sartorius Weighing Scale model No BS2202S using the following code in C#.net 2.0 on a Windows XP machine:
public string readWeight()
{
string lastError = "";
string weightData = "";
SerialPort port = new SerialPort();
port.PortName = "COM1";
port.BaudRate = 9600;
port.Parity = Parity.Even;
port.DataBits = 7;
port.StopBits = StopBits.One;
port.Handshake = Handshake.RequestToSend;
try {
port.Open();
weightData = port.ReadExisting();
if(weightData == null || weightData.Length == 0) {
lastError = "Unable to read weight. The data returned form weighing machine is empty or null.";
return lastError;
}
}
catch(TimeoutException) {
lastError = "Operation timed out while reading weight";
return lastError;
}
catch(Exception ex) {
lastError = "The following exception occurred while reading data." + Environment.NewLine + ex.Message;
return lastError;
}
finally {
if(port.IsOpen == true) {
port.Close();
port.Dispose();
}
}
return weightData;
}
I'm able to read the weight using Hyperterminal application (supplied with Windows XP) with the same serial port parameters given above for opening the port. But from the above code snippet, I can open the port and each time it is returning empty data.
I tried opening port using the code given this Stack Overflow thread, still it returns empty data.
Kindly assist me.
I know this is probably old now ... but for future reference ...
Look at the handshaking. There is both hardware handshaking and software handshaking. Your problem could be either - so you need to try both.
For hardware handshaking you can try:
mySerialPort.DtrEnable = True
mySerialPort.RtsEnable = True
Note that
mySerialPort.Handshake = Handshake.RequestToSend
I do not think sets the DTR line which some serial devices might require
Software handshaking is also known as XON/XOFF and can be set with
mySerialPort.Handshake = Handshake.XOnXOff
OR
mySerialPort.Handshake = Handshake.RequestToSendXOnXOff
You may still need to enable DTR
When all else fails - dont forget to check all of these combinations of handshaking.
Since someone else will probably have trouble with this in the future, hand shaking is a selectable option.
In most of the balances you will see the options for Software, Hardware 2 char, Hardware 1 char. The default setting for the Sartorius balances is Hardware 2 Char. I usually recommend changing to Software.
Also if it stops working all together it can often be fixed by defaulting the unit using the 9 1 1 parameter. And then resetting the communication settings.
An example of how to change the settings can be found on the manual on this page:
http://www.dataweigh.com/products/sartorius/cpa-analytical-balances/