USB Printing for DOT Matrix POS printer - c#

I was trying to print to an usb printer using usbmanager, the App can detect the printer device but when i run it doesnt print. there are no errors and all passing data is ok.
Printer : Bixolon SRP 275III
Type: USB
private async void printReciept()
{
UsbManager m_usbManager;
m_usbManager = (UsbManager)Application.Context.GetSystemService(Context.UsbService);
var deviceList = m_usbManager.DeviceList;
IEnumerable<UsbDevice> deviceIterator = deviceList.Values.AsEnumerable();
UsbDevice m_usbdevice = null;
if (deviceIterator.Count() > 0)
{
var device = deviceIterator.ElementAt(0);
m_usbdevice = device;
string ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
var mPermissionIntent = PendingIntent.GetBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
m_usbManager.RequestPermission(m_usbdevice, mPermissionIntent);
UsbDeviceConnection deviceConnection = null;
try
{
using (var usbInterface = m_usbdevice.GetInterface(0))
{
using (var usbEndpoint = usbInterface.GetEndpoint(0))
{
mEndPoint = usbEndpoint;
deviceConnection = m_usbManager.OpenDevice(m_usbdevice);
byte[] bytesHello = Encoding.UTF8.GetBytes("Hello");
deviceConnection.BulkTransfer(usbEndpoint, bytesHello, bytesHello.Length, 0);
}
}
}
catch
{
}
}
}

You are sending the string to be printed directly to the bulk endpoint, or actually you are doing bulk transfer to the first endpoint found without knowing any of it's characteristics? I think it is a bit more complex than that.
First try to find out whether your printer supports USB printing class or some proprietary implementation. You can do this easily e.g. by connecting the printer to Windows PC and looking from the device manager, usbdeview or some other similar application.
If it supports printing class, read this document and implement your driver based on that (or use the one you may already have in Android). If it only supports proprietary implementation, you need to get the specifications for it or do some reverse engineering.
You may need to learn about PCL which may also be needed.

Related

C# How can I get the masterpeek value from a specific application with Naudio

I'm fairly new to C#. In my program, I can measure the masterpeek value of the computer. But what I need right now is only the masterpeek value of a particular application, rather than the masterpeek value of the computer. For example chrome.exe masterpeek value.
I'm importing audio output devices into ComboBox.
var deviceEnum = new MMDeviceEnumerator();
var devices = deviceEnum.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
foreach (var dev in devices)
{
comboDevices.Items.Add(dev.FriendlyName);
}
comboDevices.SelectedIndex = 0;
deviceEnum.Dispose();
I choose the output device.
using (MMDeviceEnumerator deviceEnum = new MMDeviceEnumerator())
{
var deviceList = deviceEnum.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active).ToList();
device = deviceList[comboDevices.SelectedIndex];
}
I can show the masterpeek value with the progressbar.
if (comboDevices.SelectedItem != null)
{
var mpValue = Math.Round(device.AudioMeterInformation.MasterPeakValue * 100);
progressAudioMeter.Value = Convert.ToInt32(mpValue);
}
But now what I want to do exactly is the volume value of a particular application instead of the total volume value. For example chrome.exe
An example image from the audio mixer
I did some research and couldn't find exactly what I wanted. Can you help me? I don't know how I can do this.

POS for .NET - Scanner - What could cause some QR code to not trigger DataEvent while other does?

We successfully run an App using POS for .NET for about a year now. This App basicaly read QRCode on network device to get MAC address. But recently we had a weird issue: some particular QRCode were not received by our App.
We did run our code using Step by Step Debugger and Breaking point. Most of QRcode are working properly but some others are not working at all.
I mean the Scanner.DataEvent is not fired for specific QRCode. We did also check with the OPOS tool provided by the scanner manufacturer (DualTest from Datalogic) and all data are well received.
2 sample of QRCode
F09FC2F09402-q2zZ2n is working in all case
18E8299096EC-qHERPC does not work with POS for .Net but is working fine with other OPOS tool.
To give more context here below a simplified version of our source code using POS for .Net 1.4.1:
public class CodeScanner
{
public event Action<String> DataReceived;
private Microsoft.PointOfService.Scanner _scanner;
public Boolean Connect()
{
Microsoft.PointOfService.PosExplorer posExplorer = new Microsoft.PointOfService.PosExplorer(); //null reference if POS .net is not installed
Microsoft.PointOfService.DeviceInfo device = null;
foreach (Microsoft.PointOfService.DeviceInfo d in posExplorer.GetDevices(DeviceType.Scanner))
{
if (d.ServiceObjectName == "RS232Imager")
{
device = d;
}
}
_scanner = (Microsoft.PointOfService.Scanner)posExplorer.CreateInstance(device);
_scanner.Open();
_scanner.Claim(1000);
_scanner.DataEvent += Scanner_DataEvent;
_scanner.DeviceEnabled = true;
_scanner.DataEventEnabled = true;
_scanner.DecodeData = true;
return true;
}
private void Scanner_DataEvent(Object sender, DataEventArgs e)
{
String data = System.Text.Encoding.UTF8.GetString(_scanner.ScanData);
Task.Run(() => DataReceived?.Invoke(data));
_scanner.DataEventEnabled = true;
_scanner.ClearInput();
}
}
Finally I ditched Pos for .Net by using the scanner as keyboard input and refactor my code accordingly.

Access mobile device property data

Is there a way to access a mobile devices properties through C#. The purpose would be to display the device's serial number and iOS version for USB connected like an iPhone.
Using a WMI query like below access is given to the basic info accessible through the Computer Manager like DeviceID or PnpDeviceID. However I have been unable to find a property that gives the device serial number etc.
ManagementObjectSearcher(#"Select * From Win32_USBHub WHERE Description LIKE 'Apple Mobile Device%'")
or
ManagementObjectSearcher(#"Select * From Win32_PnPEntity")
or
ManagementObjectSearcher("#Select * From Win32_USBControllerDevice")
The device property menu I am referring to is in the picture below accessed by right click on a device and then clicking properties.
Placing the code below after lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError(); you will be able to access values like the serial number or iOS version. This is only a crude example:
string t1;
string t2;
PlistHandle tested1;
PlistHandle tested2;
//Find serial number in plist
lockdown.lockdownd_get_value(lockdownHandle, null, "SerialNumber", out
tested1);
//Find IOS version in plist
lockdown.lockdownd_get_value(lockdownHandle, null, "ProductVersion", out
tested2);
//Get string values from plist
tested1.Api.Plist.plist_get_string_val(tested1, out t1);
tested2.Api.Plist.plist_get_string_val(tested2, out t2);
//Place data in textboxes
serialTXT.Text = t1.Trim();
verTXT.Text = t2.Trim();
If you want to access properties such as the iOS version, your best bet may be to use imobiledevice-net.
You can install the imobiledevice-net NuGet package and then run a command like this:
ReadOnlyCollection<string> udids;
int count = 0;
var idevice = LibiMobileDevice.Instance.iDevice;
var lockdown = LibiMobileDevice.Instance.Lockdown;
var ret = idevice.idevice_get_device_list(out udids, ref count);
if (ret == iDeviceError.NoDevice)
{
// Not actually an error in our case
return;
}
ret.ThrowOnError();
// Get the device name
foreach (var udid in udids)
{
iDeviceHandle deviceHandle;
idevice.idevice_new(out deviceHandle, udid).ThrowOnError();
LockdownClientHandle lockdownHandle;
lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();
string deviceName;
lockdown.lockdownd_get_device_name(lockdownHandle, out deviceName).ThrowOnError();
deviceHandle.Dispose();
lockdownHandle.Dispose();
}
The lockdown class will allow you to access other properties, such as the iOS version, as well.
It does come with a dependency on iTunes, though.

Microphone being used in .NET

Is there a way to find out whether a microphone/recording device is currently being used by an application in Windows?
I am aware that by using NAudio one can easily get a list of all recording devices as follows:
public void getAudioDevices()
{
DeviceNameByID = new Dictionary<string, string>();
var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
// Allows you to enumerate rendering devices in certain states
var endpoints = enumerator.EnumerateAudioEndPoints(
DataFlow.Capture,
DeviceState.Active);
foreach (var endpoint in endpoints)
{
float volumeLevel = endpoint.AudioEndpointVolume.MasterVolumeLevelScalar;
Debug.WriteLine($"Volume: {volumeLevel}");
DeviceNameByID[endpoint.ID] = endpoint.DeviceFriendlyName;
Debug.WriteLine($"{endpoint.ID}: {endpoint.DeviceFriendlyName} - {endpoint.State}");
}
NotificationClient nClient = new NotificationClient();
// Aswell as hook to the actual event
enumerator.RegisterEndpointNotificationCallback(nClient);
}
but I am not sure as to how/if one can get any knowledge on their current usage.

Play audio at two different Audiodevices simultaneously with Naudio

My question is similar to one here :
Play audio to two different Audiodevices simultaneously with Naudio
But i ask it here again since it has not been answered clearly in the link above.
I also have it at:
Play sound in both speaker and headset wpf
Inspiration from :
Play a sound in a specific device with C#
I am adding source code and adding the NAudio tag here as well.
I have an wpf application and i am using the soundPlayer class to play sound (for eg ringtone). Currently the tone plays either on speakers or on the headset (if its plugged in). I would like the application to play the tone on speaker even when the headsets are plugged in. I know there are ways to do this in android, but couldn't find any in wpf. I would also like an UI for the user to choose the devices in which he would like to hear sound. Any help is appreciated. Thanks !
public void detectDevices()
{
int waveOutDevices = WaveOut.DeviceCount;
switch (waveOutDevices)
{
case 1:
var wave1 = new WaveOut();
wave1.DeviceNumber = 0;
playSound(0);
break;
case 2:
var wave2 = new WaveOut();
wave2.DeviceNumber = 0;
playSound(0);
var wave3 = new WaveOut();
wave3.DeviceNumber = 1;
playSound(1);
break;
}
}
public void playSound(int deviceNumber)
{
disposeWave();// stop previous sounds before starting
waveReader = new NAudio.Wave.WaveFileReader(fileName);
var waveOut = new NAudio.Wave.WaveOut();
waveOut.DeviceNumber = deviceNumber;
output = waveOut;
output.Init(waveReader);
output.Play();
}
public void disposeWave()
{
if (output != null)
{
if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing)
{
output.Stop();
output.Dispose();
output = null;
}
}
if (wave != null)
{
wave.Dispose();
wave = null;
}
}
case eSelector.startIncomingRinging:
fileName = ("Ring.wav");
detectDevices();
I still hear ringtone just in one device (either in headset or speakers) using the code above.
You need two instances of WaveOut, one for each soundcard. And then the simplest way if you are playing from file, is to also have two instances of WaveFileReader. You can't easily synchronize them I'm afraid, you'll just have to start them both playing together and hope for the best.
The wave1, wave2 and wave3 classes in your code above do abosolutely nothing. The audio will be played with the WaveOut device you create in playSound. You seem to have a single class property called output and another called waveReader, when you need two of each.

Categories