Le forum (ô combien francophone) des utilisateurs de Powerbuilder.
Bonjour,
Je tente de manipuler la dll ZBRGraphics.dll pour générer de l'écriture sur support carte PVC grâce à la Zebra ZXP Series 1.
// SE CONNECTER A L'IMPRIMANTE Private Function Integer ZXPOpen(String PrinterName, Ref Long hPrinter, & Ref Integer Err) & Library "ZBRGraphics.dll" Alias For ZBRGDIInitGraphics // SE DECONNECTER DE L'IMPRIMANTE Private Function Integer ZXPClose(Long hPrinter, Ref Integer Err) & Library "ZBRGraphics.dll" Alias For ZBRGDICloseGraphics // IMPRIMER Private Function Integer ZXPPrint(Long hPrinter, Ref Integer Err) & Library "ZBRGraphics.dll" Alias For ZBRGDIPrintGraphics // GENERER DU TEXTE Private Function Integer ZXPText(Integer X, Integer Y, String Text, & String Font, Integer FontSize, Integer FontStyle, Integer Color, & Ref Integer Err) & Library "ZBRGraphics.dll" Alias For ZBRGDIDrawText // GENERER UN CODE-BARRES Private Function Integer ZXPBarcode(Integer X, Integer Y, Integer BarcodeType, & Integer WidthRatio, Integer Multiplier, Integer Height, Integer TextUnder, & String Barcode, Ref Integer Err) & Library "ZBRGraphics.dll" Alias For ZBRGDIDrawBarCode
Puis :
/* SE CONNECTER A L'IMPRIMANTE */ If ZXPOpen(is_printer_name, ZXPHandle, ZXPError) = 0 Then up_error(ZXPError) lb_retour = False Else If ZXPText(up_zxp_mm_to_dot(6), up_zxp_mm_to_dot(44), & "69200 / 9", & "Arial", 12, ZXP_STYLE_BOLD, & 0, ZXPError) = 0 Then ZXPClose(ZXPHandle, ZXPError) up_error(ZXPError) lb_retour = False Else If ZXPPrint(ZXPHandle, ZXPError) = 0 Then up_error(ZXPError) lb_retour = False End If If ZXPClose(ZXPHandle, ZXPError) = 0 Then up_error(ZXPError) lb_retour = False End If End If End If
où
- up_zxp_mm_to_dot est une fonction de conversion mm -> inches -> dot
- up_error une fonction d'affichage de message d'erreur "en clair"
- ZXP_STYLE_BOLD est une constate qui vaut 1
- is_printer_name est le nom de mon imprimante
La dll ne me retourne aucune erreur, par contre l'imprimante m'affiche "command error" ce qui signifie que le texte que je désire imprimer est incorrect / la position est incorrecte / la police est incorrecte... Je penche donc pour l'instruction ZXPText fausse.
Pour info dans la doc en C#, le code équivalent serait :
[DllImport("ZBRGraphics.dll", EntryPoint = "ZBRGDIDrawText", CharSet = CharSet.Auto, SetLastError = true)] public static extern int ZBRGDIDrawText(int x, int y, byte[] text, byte[] font, int fontSize, int fontStyle, int color, out int err); ... byte[] text = ascii.GetBytes("69200 / 9"); byte[] font = ascii.GetBytes("Arial"); int fontSize = 12; int fontBold = 0x01; int fontColor = 0xFF0000; //black xCoord = 250; yCoord = 250; result = ZBRGDIDrawText(xCoord, yCoord, text, font, fontSize, fontBold, fontColor, out err);
Dernière modification par sbouvetJD (21-01-2014 16:19:55)
Hors ligne
Pour moi ça vient de ton passage de paramètres string "text" et "font" car la dll demande des tableaux de byte.
Pour moi il faut changer les types de ces paramètres et que lors de l'appel tu déclares des tableaux de bytes que tu remplis avec la conversion de tes chaînes de caractères.
Je sais pas s'il y a plus simple (et je suis dans le potage donc on est pas à l'abris d'une bourde ^^') mais avec un code de ce genre je pense que ça devrait passer.
/* des variables */ string chaines_a_convertir[] = {"69200 / 9", "Arial"} byte lbyte_text[], lbyte_font[], lbyte_caractere long ll_len_chaine int li_for_array, li_for_len blob lblob_caractere /* du code */ for li_for_array = 1 to 2 ll_len_chaine = len(chaines_a_convertir[li_for_array]) for li_for_len = 1 to ll_len_chaine lblob_caractere = Blob(mid(chaines_a_convertir[li_for_array],li_for_len, 1)) lbyte_caractere = Byte(lblob_caractere) if li_for_array = 1 then lbyte_text[li_for_len] = lbyte_caractere else lbyte_font[li_for_len] = lbyte_caractere end if next next If ZXPText(up_zxp_mm_to_dot(6), up_zxp_mm_to_dot(44), lbyte_text, lbyte_font , 12, ZXP_STYLE_BOLD, 0, ZXPError) = 0 Then /* du code */
Dernière modification par Van (21-01-2014 12:27:04)
Hors ligne
J'ai omis de préciser qu'en environnement de développement PB9, on oublie le type Byte (qui a été introduit en PB10.5 si je ne m'abuse)
J'ai trouvé cet article sur une méthode de conversion char -> byte, je vais voir ce que cela donne...
(How to)
Etonnant cependant, la méthode ZBRGDIInitGraphics requiert elle aussi un byte[] printerName, et lorsque je lui passe un String, ça ne semble pas lui poser de problème (puisque la communication s'opère)
Dernière modification par sbouvetJD (21-01-2014 13:11:51)
Hors ligne
J'ai effectué les remplacements suivants, sans succès :
- Utilisation de ZBRGDIDrawTextUnicode au lieu de ZBRGDIDrawText
- Remplacement de mes String par des Char[]
Hors ligne
Honte à moi... Avec les pilotes officiels ça va mieux (elle avait été installée en Generic/Text, comme les autres imprimantes de marque Zebra qui elles, peuvent recevoir du texte codifié ZPL...)
Hors ligne