2015-09-25 1 views
2

Je ne peux pas imprimer plus de 380 caractères dans un code qr.EPSON ESCPOS QRCode> 380 caractères non imprimés

suit le code en C#:

protected ASCIIEncoding m_encoding = new ASCIIEncoding(); 
string QRdata = @"35150909165024000175590000193130072726117830|20150924062259|50.00||hdMEPiER6rjZKyKA+4+voi1nncxsAGFbYsEEqnh04SbvUEI/haUF4GUBPxT6Q2Uhf9f8QYgxiwxWo3GxRrvj4WnNeTYgAqUAYmOANPItNkOw0CppmZ4R8i1ZOlnftVhksCM0zrl4RiKgoazbN44hUu2nQf0W/JLvFXzXu12JlcSThNtmyJ6m9WBsMc/sf9BE14HDoXMyKRIQYt5TkEjilHH9Ffa0saRyUIp+Fji89/Moq8YCCFC+qC44XGxsvNCeeHUNOc1LgPP0DbU1miwpVnrBlEl87RU8Iy0r8fN/fNhbcStkwfTEvhYvZz42nEKHrmGTpGZYkHuTFCNZPq7aCA=="; 
     int store_len = QRdata.Length + 3; 
         byte store_pL = (byte)(store_len % 256); 
         byte store_pH = (byte)(store_len/256); 


         string txt = m_encoding.GetString(new byte[] { 29, 40, 107, store_pL, store_pH, 49, 80, 48 }); //FUNCTION 180 
      txt += QRdata; 
      txt += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 69, 48 });//FUNCTION 169 
      txt += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 67, 5 });//FUNCTION 167 
      txt += m_encoding.GetString(new byte[] { 29, 40, 107, 4, 0, 49, 65, 50, 0 });//FUNCTION 165 
      txt += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 81, 48 });//FUNCTION 181 

Lorsque vous essayez d'imprimer apparaît comme suit:

print

+1

Montrez, s'il vous plaît, comment utilisez-vous la chaîne? Si je comprends bien, vous l'envoyez au port série. Pourquoi n'utilisez-vous pas le tableau d'octets alors? Il semble que l'ASCII soit votre problème, car il s'agit d'un codage 7 bits, mais votre partie basse de longueur dépasse 7 bits, donc vous obtenez '?' Dans la variable 'txt'. Vous pouvez utiliser 'Encoding m_encoding = Encoding.GetEncoding (" iso-8859-1 ");' et définir le même encodage pour le port série, ou utiliser le tableau d'octets depuis le début. BTW, pouvez-vous essayer d'imprimer le code QR avec votre code actuel pour le texte ayant une longueur comprise entre 128 et 255? –

+0

J'utilise Winspool pour imprimer. J'ai changé mon code pour envoyer un octet au winspool avec cet encodage et cela a fonctionné parfaitement. Avant d'imprimer jusqu'à 380 caractères. Maintenant, cela a fonctionné, merci beaucoup pour votre aide! –

+1

Heureux que cela a aidé, j'ai posté une réponse au cas où quelqu'un chercherait le même problème. –

Répondre

3

ASCII est un problème, car il est le codage 7 bits, mais store_PL La valeur est supérieure à 127 (8 bits). Ce qui suit est la démonstration de ce qui se passe:

ASCIIEncoding m_encoding = new ASCIIEncoding(); 
string QRdata = @"35150909165024000175590000193130072726117830|20150924062259|50.00||hdMEPiER6rjZKyKA+4+voi1nncxsAGFbYsEEqnh04SbvUEI/haUF4GUBPxT6Q2Uhf9f8QYgxiwxWo3GxRrvj4WnNeTYgAqUAYmOANPItNkOw0CppmZ4R8i1ZOlnftVhksCM0zrl4RiKgoazbN44hUu2nQf0W/JLvFXzXu12JlcSThNtmyJ6m9WBsMc/sf9BE14HDoXMyKRIQYt5TkEjilHH9Ffa0saRyUIp+Fji89/Moq8YCCFC+qC44XGxsvNCeeHUNOc1LgPP0DbU1miwpVnrBlEl87RU8Iy0r8fN/fNhbcStkwfTEvhYvZz42nEKHrmGTpGZYkHuTFCNZPq7aCA=="; 
int store_len = QRdata.Length + 3; // 414 
byte store_pL = (byte)(store_len % 256); // 158 
byte store_pH = (byte)(store_len/256); // 1 
byte[] data = new byte[] { 29, 40, 107, store_pL, store_pH, 49, 80, 48 }; //FUNCTION 180 
string txt = m_encoding.GetString(data); 
byte[] invalidData = m_encoding.GetBytes(txt); 

La valeur d'origine des données (expected un):

1d 28 6b 9e 01 31 50 30 

Les données réelles du port série reçoit (en raison de défaut de encodent valeur 158 en 7 ASCII -bit):

1d 28 6b 3f 01 31 50 30 

comme vous pouvez le voir, la valeur 158 (0x9e) est changée en 63 (0x3f), car symbole inconnu a été codé comme ?.

Donc, il y a 2 solutions au problème. La première consiste à utiliser le codage Encoding m_encoding = Encoding.GetEncoding("iso-8859-1");, ou tout autre codage ASCII étendu, mais il doit être synchronisé entre le codage par octet que vous utilisez dans votre code et les paramètres du port série. Et une autre solution est de ne pas utiliser de chaînes du tout, mais d'utiliser des tableaux d'octets.