I having trouble to send FNC1 symbol from my C# software to the printer through network communication.
The printer is Hitachi IJP 2D barcode printer, I had try to use the example from the SDK but there is only able to pass the string/character to the printer.
There sample code is as below :
if ( null == this.ijp )
{
throw new InvalidOperationException ( "Do connect the ink jet printer." );
}
// Get the current message.
IJPMessage message = ( IJPMessage ) this.ijp.GetMessage ();
if ( 2 > message.Items.Count )
{
message.AddColumn ();
}
// Change a text.
message.Items[ 1 ].Text = newText;
// Set the message.
this.ijp.SetMessage ( message );
Related
I'm trying to read user data from sector 0 block 1 of Mifare Classic cards in a Xamarin Forms Android app. On most devices it works perfectly every time, but on a Unitech EA510 the authentication consistently fails UNLESS I first read the card using the Mifare Classic Tool (https://play.google.com/store/apps/details?id=de.syss.MifareClassicTool). As soon as I've detected any tag with the Mifare Classic Tool my code works perfectly every time. I've checked the Mifare Classic Tool source code to see what else it's doing and borrowed the patchTag logic (it didn't help!).
Scan tag with the app first time:
Mifare Classic tag authentication failure: 8250A9B9
Scan tag using the Mifare Classic Tool
Re-scan the tag with the app:
Mifare Classic tag found: 8250A9B9 10240472
Scan another the tag with the app:
Mifare Classic tag found: 8250A9C7 10395802
public void OnTagDiscovered(Android.Nfc.Tag tag)
{
string tagId = string.Empty;
string[] techList = tag.GetTechList();
string sUid = string.Empty;
if (Array.IndexOf(techList, "android.nfc.tech.MifareClassic") > -1) {
MifareClassic mfc = null;
try {
sUid = BitConverter.ToString(tag.GetId()).Replace("-", "");
mfc = MifareClassic.Get(tag);
mfc.Connect();
bool bAuthenticated = false;
if (mfc.AuthenticateSectorWithKeyA(0, MifareClassic.KeyDefault.ToArray()))
bAuthenticated = true;
else if (mfc.AuthenticateSectorWithKeyB(0, MifareClassic.KeyDefault.ToArray()))
bAuthenticated = true;
else if (mfc.AuthenticateSectorWithKeyA(0, MifareClassic.KeyMifareApplicationDirectory.ToArray()))
bAuthenticated = true;
else if (mfc.AuthenticateSectorWithKeyB(0, MifareClassic.KeyMifareApplicationDirectory.ToArray()))
bAuthenticated = true;
else if (mfc.AuthenticateSectorWithKeyA(0, MifareClassic.KeyNfcForum.ToArray()))
bAuthenticated = true;
else if (mfc.AuthenticateSectorWithKeyB(0, MifareClassic.KeyNfcForum.ToArray()))
bAuthenticated = true;
if (bAuthenticated) {
int blockOffset = mfc.SectorToBlock(0);
byte[] block = mfc.ReadBlock(blockOffset + 1); // Sector 0/block 0 is the UID so go straight to block 1 for the payload
tagId = System.Text.Encoding.ASCII.GetString(block);
if (tagId.Length == 1 && tagId[0] == 0x04)
// Ignore if ReadBlock returns a single byte 0x04, which appears to happen if there's a delay between the tag discovery and ReadBlock (e.g. running in the debugger) and we don't want to treat it as a conventional tag by acciden
tagId = string.Empty;
else if (tagId.Length > 0 && tagId.Contains('\0'))
tagId = tagId.Substring(0, tagId.IndexOf('\0'));
} else {
Console.WriteLine($"Mifare Classic tag authentication failure: {sUid}");
}
}
catch (Exception ex) {
Console.WriteLine($"Mifare Classic tag read exception: {ex.Message}");
}
finally {
if (mfc != null && mfc.IsConnected)
mfc.Close();
if (tagId != string.Empty)
Console.WriteLine($"Mifare Classic tag found: {sUid} {tagId}");
}
}
if (tagId != string.Empty)
Do stuff
}
That looks a super hacky way of trying to enable Mifare Classic support when the phone does not support it and it won't fix all devices.
But your problem is the hack relies on modifying the Tag Object that your App has created from the Intent when you are using the old API enableForegrounDispatch
This old API has some other issues, where as you are using the newer and better enableReaderMode API (because you are using the method OnTagDiscovered) which gets directly give the Tag Object.
I've not been through the Android code to work all this out but my guess is that it is some form of shared memory object, it is though defined as a "oneway" callback.
Thus as your App process is not the creator of the Tag object you don't have the ability to modify it.
So this hack will probably only work if you are using the old enableForegrounDispatch where you de-Parcel the Parcelled object in your own App ( Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); ) and have full access to Tag object because your process created it.
The reason why your code works after using Mifare Classic Tool App is that once the Tag Hardware has been authenticated, it stays in the "authenticated" state until it is removed from the RF field and it looses power.
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.
I am using Unity3d (c#) with facebook API. I try to show my profile image on the screen when I run it on the unity simulator everything works perfect and I got the image. but when I build a version and try it on a real device I get nothing.
I know that there is a issue with facebook CDN. the result of the request is 302 and WWW class can't handle with redirects so I did something like this (c# is a new language for me):
WWW www = new WWW(url);
yield return www;
if( www.responseHeaders.ContainsKey( "LOCATION" ) ){
var redirection = www.responseHeaders[ "LOCATION" ];
WWW wwwRe = new WWW( redirection );
yield return wwwRe;
callback( wwwRe.texture, userID );
}else{
callback( www.texture, userID );
}
please help me I loose my mind, why all my personal data comes on the device except the image that works perfect in unity. what I did wrong?
thanks.
The solution:
I tried many options to get profile image on the device nothing worked.
finally I upgrade Facebook SDK from 6.2.1 to 6.2.2 and Unity from 5.1 to 5.1.3 remove the app again from the device ( clear all the data ) and it works. it looks like Facebook's issue ( this is not the first time that they release SDK with bugs ).
I accept Umair's answer even that his code have some syntax issues, he really tried to help me and basically his answer is right.
I used this code to test my image:
( hope it will help for someone )
private void getMyProfileData(){
// get profile image.
FB.API( Util.GetPictureURL( "me", 128, 128 ), Facebook.HttpMethod.GET, callBackGetProfilePicture );
}
private void callBackGetProfilePicture( FBResult result ){
// in case if there some error with the image.
if( result.Error != null ){
// call this method again
}
string ImageUrl = Util.DeserializePictureURLString( result.Text );
StartCoroutine(LoadPictureCoroutune( ImageUrl ));
}
IEnumerator LoadPictureCoroutune(string url){
var profilePicRequest = new WWW( (string)url );
yield return profilePicRequest;
if( profilePicRequest.error == null)
{
Texture2D profilePic = profilePicRequest.texture;
// my test image place
Image profileImage = FBavatar.GetComponent<Image>();
profileImage.sprite = UnityEngine.Sprite.Create( profilePic, new Rect(0,0,128,128), new Vector2( 0, 0 ));
}
else
{
Debug.LogError("Error While downloading Picture: " + profilePicRequest.error);
}
}
Use following Code to get Picture data from Facebook API:
FB.API ("/v2.4/me/?fields=picture", Facebook.HttpMethod.GET, RequestResponce);
In RequestResponce method:
void RequestResponce(FBResult result)
{
Debug.Log("requestResponce(): " + result.text);
if (!string.IsNullOrEmpty(result.Error))
{
Debug.Log("FB_API:ReadRequest:Failed:"+result.Error);
}
else
{
var data = SimpleJSON.JSON.Parse(result.Text);
string url = data["picture"]["data"]["url"];
StartCoroutine(LoadPictureCoroutune(url));
}
}
IEnumerator LoadPictureCoroutune(string url)
{
var profilePicRequest = new WWW(url);
Debug.Log("Going to Load Picture ");
yield return profilePicRequest;
if(profilePicRequest.error == null)
{
Texture2D profilePic = profilePicRequest.texture;
if(profilePic != null)
{
// Use ProfilePic to wherever you want to.
//SetPicture(ProfilePic);
}
}
else
{
Debug.LogError("Error While downloading Picture: " + profilePicRequest.error);
}
}
Does anyone know how to list NTFS permissions on all shares in a NETAPP vfiler using C#?
I tried to use NETAPP API but only get the share permissions, can't find a way to get the NTFS ones.
EDIT
Thanks Sobrique, here's the C# syntax:
var api = new NaElement("system-cli");
var args = new NaElement("args");
args.AddNewChild("arg", "fsecurity");
args.AddNewChild("arg", "show");
args.AddNewChild("arg", path);
api.AddChildElement(args);
s.InvokeElem(api)
For doing this though, I tend to use:
vfiler run vfilername fsecurity show /path/to/file/here
This will print the various ACL attributes (NTFS and Unix) for the file in question. You'll need to first enumerate your share paths to do this. (cifs shares is a start point).
There is a way to do it via the API - you need to use the undocumented 'system-cli' function that lets you remote execute commands and capture output.
Unfortunately doing this the output is ... about on a par with just running an ssh command.
However - craft your XML:
<!DOCTYPE netapp SYSTEM "/na_admin/netapp_filer.dtd">
<netapp version="1.7" xmlns="http://www.netapp.com/filer/admin">
<system-cli>
<args>
<arg>fsecurity</arg>
<arg>show</arg>
<arg>/vol/volname/qtreename/sharename/filename</arg>
</args>
</system-cli>
</netapp>
This will do the trick, although it will return you plain text cli-output element.
use strict;
use warnings;
use XML::Twig;
use LWP;
my $twig = XML::Twig->new( 'pretty_print' => 'indented' );
$twig->set_root(
XML::Twig::Elt->new(
'netapp',
{ version => 1.7,
vfiler => "somevfiler",
xmlns => "http://www.netapp.com/filer/admin",
},
)
);
my $api_req = $twig->root->insert_new_elt('system-cli');
my $args = $api_req->insert_new_elt('args');
$args->insert_new_elt( 'last_child', 'arg', 'fsecurity' );
$args->insert_new_elt( 'last_child', 'arg', 'show' );
$args->insert_new_elt( 'last_child', 'arg', '/vol/volname/qtree/filename' );
$twig->set_doctype('netapp SYSTEM "file:/etc/netapp_filer.dtd"');
$twig->set_xml_version("1.0");
$twig->set_encoding('utf-8');
$twig->print;
exit;
my $user_agent = LWP::UserAgent->new(
'ssl_opts' => {
'verify_hostname' => 0,
'SSL_version' => 'SSLv3',
}
);
my $request =
HTTP::Request->new( 'POST' =>
'https://myfilername/servlets/netapp.servlets.admin.XMLrequest_filer'
);
$request->authorization_basic( 'username_here', 'password_here' );
$request->content( $twig->sprint );
my $results = $user_agent->request($request);
if ( not $results->is_success ) {
print "Error: ", $results->status_line;
exit;
}
my $results_xml = XML::Twig->new( 'pretty_print' => 'indented_a' );
$results_xml->parse( $results->content );
$results_xml->print;
Please can anyone help me? I search some example how can i get information about speeching text in TTS through SAPI (I am programming my aplication in C# but it is not needed, SAPI is the same in C++, etc.)
Information what I need is for example:
User will write in textbox:
"This is a Text"..
tts.Speak("This is a text"); // this will "read" it..
ok, nice... but I need too get informations about "timing"..
for example:
"Th" (first sound (phoneme) of "This") was "read" in 0.01ms..
"i" (first sound of "is") was "read" in 0.5ms..
"e" (second sound of "Text") was "read" in 1.02ms..
when I save the .wav file generated by SAPI, I need to get information about the timing in the .wav for subsequent "processing" of the wav file.
Sorry for my english and sorry for my bad description of my problem but the problem is i think very simple and all will understand it. If not I will try to describe the problem again :) ^^..
I have used C++ and SAPI 5.1 to synthesize speech and have a virtual character move its lips accordingly. Here is some code that works with visemes. According to the documentation at http://msdn.microsoft.com/en-us/library/ms720164(v=vs.85).aspx, phonemes work the same, except replace SPEI_VISEME with SPEI_PHONEME.
DWORD WINAPI Character::sayMessage(LPVOID lpParam){
HRESULT hres;
try{
::CoInitialize(NULL);
ThreadParam * param = (ThreadParam *)lpParam;
wstring s = param->message;
//first check the string for null
if (s == L"") return false;
//http://msdn.microsoft.com/en-us/library/ms720163(VS.85,classic).asp is my source for this
//set up text to speech
//get the voice associated with the character
ISpVoice * pVoice;
pVoice = param->sceneObject->characterVoice;
if (pVoice != NULL){
pVoice->Speak( NULL, SPF_PURGEBEFORESPEAK, 0 );
SPEVENT event;
ULONG ul;
pVoice->SetInterest(SPFEI(SPEI_VISEME)|SPFEI(SPEI_END_INPUT_STREAM),SPFEI(SPEI_VISEME)|SPFEI(SPEI_END_INPUT_STREAM));
pVoice->SetNotifyCallbackFunction(&eventFunction,0,0);
pVoice->WaitForNotifyEvent(INFINITE);
if (param->sceneObject->age == CHILD){
s = L"<pitch middle=\"+10\">" + s + L"</pitch>";
}
hres = pVoice->Speak(s.c_str(),SPF_ASYNC,NULL);
bool isDone = false;
while(!isDone && pVoice != NULL && !FAILED(hres)){
if(pVoice->GetEvents(1,&event, &ul) == S_OK){
if(event.eEventId==SPEI_VISEME){
//get the viseme
int vis = LOWORD(event.lParam); //handle it however you'd like after this
}
else if(event.eEventId== SPEI_END_INPUT_STREAM){
isDone = true;
s = L"";
return true;
}
}
}
}
}
catch(...){
return false;
}
return !FAILED(hres);
}