I have a TM-T20 Epson, I'm using this code to try to print : "Hello Printer" Message, and i keep tracking of some proprieties of the PosPrinter :
public void ImprintHelloPrinter()
{
//The Explorer
PosExplorer explorer = new PosExplorer();
////Get the device by its type LOGICAL NAME
DeviceInfo device = explorer.GetDevice(DeviceType.PosPrinter, "T20PRINTER");
//Create an instance
PosPrinter oposPrinter = (PosPrinter)explorer.CreateInstance(device);
//Opening
MessageBox.Show(#"Statue : " + oposPrinter.State.ToString());
oposPrinter.Open();
MessageBox.Show(#"Statue : " + oposPrinter.State.ToString());
//Checking if its really the printer
MessageBox.Show(#"Description : " + oposPrinter.DeviceDescription);
MessageBox.Show(#"Check Claimed : " + oposPrinter.Claimed.ToString());
oposPrinter.Claim(10000); //Here is My Exception
//Enabeling device
oposPrinter.DeviceEnabled = true;
//normal print
oposPrinter.PrintNormal(PrinterStation.Receipt, "Hello Printer");
}
Everything went OK, i checked that it is the right Printer and it opened and its not claimed, but when i try to Claim it i have the following Exception :
Method ClaimDevice threw an exception. Attempt was made to perform an illegal
or unsupported operation with the device, or an invalid parameter value was used.
Even in the Example application provided with the Microsoft Point Of Service SDK in the Sample Application Folder (C:\Program Files\Microsoft Point Of Service\SDK\Samples\Sample Application), i can find my printer, open it, but when i Claim it i have this error message :
POSControlException ErrorCode(Illegal) ExtendedErrorCode(10002) occurred:
Method ClaimDevice threw an exception. Attempt was made to perform an illegal
or unsupported operation with the device, or an invalid parameter value was
used.
Print Screen Of The Sample Application :
The error is because you have bad port configurated.
In my case, I use model FP-81 II connected to hardware NPort 5110 where I was configure port to 9100.
I hope help you.
Related
I'm trying to get device info using DeviceManager class in C# and i get the folowing error:
The runtime has encountered a fatal error. The address of the error was at 0x7170f7fc, on thread 0x1448. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
Here is my code:
// Create a DeviceManager instance
var deviceManager = new DeviceManager();
// Loop through the list of devices and add the name to the listbox
for (int i = 0; i <= deviceManager.DeviceInfos.Count; i++)
{
// Add the device only if it's a scanner
if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType)
{
continue;
}
// Add the Scanner device to the listbox (the entire DeviceInfos object)
listBox1.Items.Add(new Scanner(deviceManager.DeviceInfos[i]));
}
It started happening after i found a solution online to change the WIA service logon
Services -> Windows Image Acquisition (WIA) right click -> Properties -> Log On tab -> select local System Account and Allow service to interact with desktop.
I tried it, didnt work, so I turned back to "This account" with Local Service user.
I am trying to create and connect to a WLAN profile using Native WiFi (https://managedwifi.codeplex.com/). I am able to view all the Network BSS List and their parameters. However, when I am trying to create/overwrite a WLAN profile, I get the below mentioned error message (Error#1):
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in ManagedWifi.dll.
Additional information: The network connection profile is corrupted
However, when I created a profile normally from "Network and Sharing Center" of the Windows 7 control panel and then tried to connect using the ManagedWiFi, I get another error message(Error#2):
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Type 'NativeWifi.Wlan+WlanReasonCode' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed.
I noticed that this error occurs even if I try to connect/disconnect to a WLAN profile from the "Network and Sharing Center", with the windows application running in the background.
Here is the sample code that I am using:
Dim profileName As String = GlobalVariables.ssidname ' Provides the selected SSID name from the Network BSS List
Dim hexval As String = StringToHex(GlobalVariables.ssidname) ' Function to get the hexadecimal value for a provided string
Dim key As String = TextBox1.Text ' Security key from the textbook provided
Dim profileXml As String = String.Format("<?xml version=""1.0""?><WLANProfile xmlns=""http://www.microsoft.com/networking/WLAN/profile/v1""><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>WEP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>{2}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", 'GlobalVariables.ssidname, hexval, TextBox1.Text)
wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, True) 'Error#1 occurs here
wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName) 'Error#2 occurs here
From the forum "Type Native Wifi.Wlan + WlanReasonCode cannot be marshaled error", the issue (Error#2) seems to be within the WlanAPI.cs, where there is a line of code that checks for the size of the return code. This is the line:
int expectedSize = Marshal.SizeOf(typeof(Wlan.WlanReasonCode));
if (notifyData.dataSize >= expectedSize)
{
Wlan.WlanReasonCode reasonCode = (Wlan.WlanReasonCode)Marshal.ReadInt32(notifyData.dataPtr);
if (wlanIface != null)
wlanIface.OnWlanReason(notifyData, reasonCode);
}
Changing the above code to the below seems to fix the issue.
//int expectedSize = Marshal.SizeOf(typeof(Wlan.WlanReasonCode));
if (notifyData.dataSize >= 0)
{
Wlan.WlanReasonCode reasonCode = (Wlan.WlanReasonCode)Marshal.ReadInt32(notifyData.dataPtr);
if (wlanIface != null)
wlanIface.OnWlanReason(notifyData, reasonCode);
}
However, I am not sure on how to add this fix to my solution. I installed the ManagedWiFi from the NuGet Package Manager. Hence, not sure how to change the WlanApi.cs file. Any help regarding the above mentioned two issues are much appreciated.
The issue (Error#1) is now resolved. The profilexml file format was different for me. Here is the profilexml after I changed it.
Dim profileXml As String = String.Format("<?xml version=""1.0""?><WLANProfile xmlns=""http://www.microsoft.com/networking/WLAN/profile/v1""><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><MSM><security><authEncryption><authentication>WPA2PSK</authentication><encryption>AES</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMaterial>{2}</keyMaterial></sharedKey></security></MSM></WLANProfile>", GlobalVariables.ssidname, hexval, TextBox1.Text)
Also the second issue (Error#2) was resolved when I uninstalled ManagedWiFi package from my solution and added the whole ManagedWiFi project to the solution. Then I made the change in WlanApi.cs as mentioned in SimpleWiFi Or Type Native Wifi.Wlan + WlanReasonCode cannot be marshaled error.
I had a simpler task (read the SSID of the connected network), which was throwing the same error.
I solved it by switching to using SimpleWiFi entirely and ignore the ManagedWifi package.
Glancing at the source code, it looks like SW is a fixed reimplementation of some of the functionality in MW.
I can see a network share in explorer but when I use try to access it in my application I get "The network name cannot be found."
This is quite odd because the same server has other shares that I can access. For example:
string[] example_directories = new string[]{
Path.Combine(#"\\example01","vaqua"),
Path.Combine(#"\\example01","vaqua-pub"),
Path.Combine(#"\\example01","yesvirginiabeach"),
Path.Combine(#"\\example01","yesvirginiabeach-pub")
};
// output username
Console.WriteLine("User: " + WindowsIdentity.GetCurrent().Name);
// output each response to Directory.Exists
foreach (string directory in example_directories)
try
{
Console.WriteLine(directory + " : " + Directory.GetCreationTime(directory));
}
catch(Exception e)
{
Console.WriteLine(directory + " : " + e.Message.Trim());
}
Console.Read();
Output:
User: domain\myusername
\\example01\vaqua : 10/22/2013 7:34:30 AM
\\example01\vaqua-pub : 10/22/2013 7:57:42 AM
\\example01\yesvirginiabeach : The network name cannot be found.
\\example01\yesvirginiabeach-pub : 4/4/2013 10:31:07 AM
I can see all four of those shares on \example01 in explorer but the \example01\yesvirginiabeach share just doesn't exist to my application.
These four shares all have the same permissions and I even print out my username to ensure the app is running with my creds.
I have had our admin re-share the directory and re-apply permissions to no avail.
Solution: My admin misspelled the share name:
\\example01\yesvirginiabeach as \\example01\yesvirgniabeach.
(Answered and resolved in comments above...)
Double-check that the name "yesvirginiabeach" is correct. Make sure there's nothing crazy like a Unicode character that looks like an "i" but is really a different character. (Solution turned out to be that someone misspelled the name of the folder as "yesvirgniabeach".)
For similar problems one could try enumerating the shares to see what the program can see. There's also the NET USE command (open a Command Prompt and type net use /help; this tool shows all the shares currently being accessed and can open new shares from a command prompt, which sometimes gives useful status messages).
A line similar to the following threw the above exception:
PrintServer ps = new PrintServer(#"\\prntsrv");
When I use "Run..." on Windows the address above does work and take me to the list of print jobs so why does the line of code not work?
Apparently, the address \\prntsrv was a DNS alias to \\prntserv and the PrintServer constructor was unable to deal with it. To get around this issue I used the following code (I could also use just the code in the catch block instead and it would work, but preferred not to):
try
{
// Create object to monitor the printer queue
PrintServer printServer = new PrintServer(serverPath);
mPrintQueue = printServer.GetPrintQueue(printerName);
}
catch (PrintServerException ex)
{
// If the problem might be creating the server because the name is an alias
if (ex.Message.Contains("printer name is invalid."))
{
string actualServerHostname = "\\\\" + Dns.GetHostEntry(serverPath.TrimStart('\\')).HostName;
// Create object to monitor the printer queue
PrintServer printServer = new PrintServer(actualServerHostname);
mPrintQueue = printServer.GetPrintQueue(printerName);
// Write to log about the use of a different address
}
else
{
throw;
}
}
hey i was facing similar issue, this is what i observed and made following changes, just try and let me know.
This issue was occuring due to windows feature/role "Print and Document service" is missing on the system. This role is required for managing multiple printers or print servers and migrating printers to and from other windows servers.
To add the role Go To Control Panel->Turn windows feature on or off->click on check box "Print and Document Service"->install.
See with network administrator for installing this rule if you unable to add it.
After adding the role you can able to create print server object and get the all the printqueues on respective server.
Current C# POS.NET Printing Issue:
PrintNormal() Throws Exception = 'It is not initialized'
CheckHealth = 'It is not initialized'
'It is not initialized' exception when Printing to Epson TM-T88IV
Using POS for .NET 1.12 and the Epson OPOS ADK for .NET (v1.11.9) service-objects
Successfully able to Open, Claim and Set the DeviceEnabled-true for PosPrinter
Issue sending anything to the printer after this
PrintNormal() results in a 'It is not initialized' exception being thrown.
CheckHealth Utility that came with the Epson OPOS ADK results in exactly the same error. When using PrintNormal(PrinterStation.Receipt the exception is 'The specified station is not mounted."
printer prints fine using direct parallel
printer itself prints
How can we not throw the exemption with the message - 'It is not initialized'?
void K8POSPrint()
{
/// <summary>
/// PosPrinter object
/// </summary>
PosPrinter m_Printer = null;
try
{
//Use a Logical Device Name which has been set on the SetupPOS.
string strLogicalName = "PosPrinter";
try
{
//Create PosExplorer
PosExplorer posExplorer = new PosExplorer();
DeviceInfo deviceInfo = null;
try
{
// Device Info is not null when the printer has the logical name
deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName);
m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo);
}
catch (Exception ExDevice)
{
}
//Open the device
m_Printer.Open();
//Get the exclusive control right for the opened device. Then the device is disable from other application.
m_Printer.Claim(1000);
//Enable the device.
m_Printer.DeviceEnabled = true;
// ////CheckHealth.
//m_Printer.CheckHealth(Microsoft.PointOfService.HealthCheckLevel.Interactive);
// //As using the PrintNormal method, send strings to a printer, and print it [\n] is the standard code for starting a new line.
/// Current Issue Next Line thows an exception - 'It is not initialized'
m_Printer.PrintNormal(PrinterStation.Receipt, "Hey Now OPOS for .NET\n");
// the next line would throw the exception 'The specified station is not mounted.'
// m_Printer.PrintNormal(PrinterStation.Slip,"Hey Now Slip OPOS.NET\n");
}
catch (PosControlException)
{
}
}
catch (Exception ex)
{
}
}
Additional Information:
Programs installed while attempting to print on the pos printer are:
1. Installed APD4 Printer Driver Epson TI88IV
APD_412EWM.exe
https://www.epsonexpert.com/ee/techRes/index.htm?ProductId=570
After this set in control panel printers I can select the printer's properties & print a test to the printer successfully.
2. Installed Microsoft POS.NET 1.12
POSfor.NET.msi
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=eaae202a-0fcc-406a-8fde-35713d7841ca
3. Installed Epson OPOS ADK v2.67
ADK267ER4.exe
https://www.epsonexpert.com/ee/appDev/appDevOPOS.htm
4. Installed EPSON OPOS ADK for .NET 1.11.8
OPOSN 1 11 18.exe
https://www.epsonexpert.com/ee/appDev/appDevOPOS.htm
5. Installed OPOS Common Control Objects 1.13.001
OPOS_CCOs_1.13.001.msi
http://monroecs.com/oposccos_current.htm
6. SetupPOS - Added device & Logical Name
7. Check Health still throws the errors
It is not initialized
OPOS_E_ILLEGAL 10007 (0x00002717)
The problem might not be software, but hardware. I saw a similar question (at http://social.msdn.microsoft.com/Forums/vstudio/en-US/446fd4cc-db6b-4822-b3c8-7d9a98bf7eb4/it-is-not-initialized-when-trying-to-printnormal?forum=posfordotnet), where the developer was using an extension cable which was not parallel. As soon as he connected the parallel cable directly to the printer (without the extension cable), his software worked. This was after he called Epson and ordered a newer printer, because they told him his original printer was not compatible with .NET, so that could also be your problem.
I had the same error "It is not initialized" on brand new Epson TM-T88VI.
The printer came with IDN Card and default the ethernet card was partially blocked. You can use the ethernet card to connect to "Epson Net Config", but it did not work when you try to print by OPOS ADK for NET.
The solution was to set switches on IDN Card as:
DS1
DS2
DS3
DS4
DS5
DS6
DS7
OFF
OFF
OFF
OFF
ON
ON
ON
Make sure Power OFF when you changing the switches.