2009-08-27 8 views
3

J'ai un scanner de codes barres de Metro Technologies et j'utilise Microsoft POS pour détecter l'entrée du scanner. Il est connecté à mon système en utilisant le port USB . Mais le scanner n'est pas identifié par le POS.Scanner non reconnu par Microsoft POS

public Form1() 
{ 
InitializeComponent(); 
explorer = new PosExplorer(this); 
explorer.DeviceAddedEvent += new 
DeviceChangedEventHandler(explorer_DeviceAddedEvent); 
} 


void explorer_DeviceAddedEvent(object sender, DeviceChangedEventArgs e) 
{ 
if (e.Device.Type == "Scanner") 
{ 
scanner = (Scanner)explorer.CreateInstance(e.Device); 
scanner.Open(); 
scanner.Claim(1000); 
scanner.DeviceEnabled = true; 
scanner.DataEvent += new 
DataEventHandler(activeScanner_DataEvent); 
scanner.DataEventEnabled = true; 
scanner.DecodeData = true; 
} 
} 

void activeScanner_DataEvent(object sender, DataEventArgs e) 
{ 
UpdateEventHistory("Data Event"); 
ASCIIEncoding encoder = new ASCIIEncoding(); 
try 
{ 
// Display the ASCII encoded label text 
txtbScanDataLabel.Text = 
encoder.GetString(activeScanner.ScanDataLabel); 
// Display the encoding type 
txtbScanDataType.Text = activeScanner.ScanDataType.ToString(); 

// re-enable the data event for subsequent scans 
activeScanner.DataEventEnabled = true; 
} 
catch (PosControlException) 
{ 
// Log any errors 
UpdateEventHistory("DataEvent Operation Failed"); 
} 
} 
+1

Je suppose que "Microsoft POS" ne signifie pas ce que cela signifie habituellement quand je vois ce terme en ligne. :-) –

+0

J'espère vraiment que POS signifie point de vente ... et non ... ce que T.E.D. pense à. –

Répondre

0

Je ne suis pas familier avec le scanner que vous utilisez, mais avec tout ce que j'ai travaillé avec avant que vous voulez généralement pour vous assurer que le scanner lui-même est configuré pour le mode correct/réglages/etc. Habituellement, cela est fait en passant par une séquence de configuration qui est dans le manuel où vous allez scanner différents codes à barres qui programment le périphérique. Si rien d'autre vous pouvez exclure un problème avec la configuration matérielle par opposition à votre code.

Le explorer_DeviceAddedEvent est-il toujours allumé?

Où sont scanner et activeScanner initialisés?

[EDIT]

Vérifiez le scanner lui-même ou la documentation qui l'accompagne pour un ID matériel (HID), essayez d'ajouter la ligne suivante à votre code.

[HardwareId(@"this is where the HID goes")] 

Voyez si vous obtient plus loin ... voir here pour plus d'informations, vous pouvez fournir le HID ou ajouter cette information dans un fichier de configuration XML

+0

L'événement explorer_DeviceAddedEvent ne se déclenche pas. Donc, il n'atteint jamais le code où l'objet scanner est créé. Le scanner doit-il être configuré de manière spécifique pour fonctionner avec Microsoft POS? – RRR

+0

poster le reste du code s'il vous plaît, même l'utilisation des déclarations – curtisk

+0

Publié le code entier ci-dessous – RRR

0

Voici le code entier

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using Microsoft.PointOfService; 
using System.Collections; 

namespace MicrosoftPOSScannerSample 
{ 
    public partial class Form1 : Form 
    { 
     private PosExplorer explorer; 
     private Scanner scanner; 

     public Form1() 
     { 
      InitializeComponent(); 
      explorer = new PosExplorer(this); 
      explorer.DeviceAddedEvent += new DeviceChangedEventHandler(explorer_DeviceAddedEvent); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
     } 

     private void UpdateEventHistory(string newEvent) 
     { 
      txtbEventHistory.Text = newEvent + System.Environment.NewLine + txtbEventHistory.Text; 
     } 

     void explorer_DeviceAddedEvent(object sender, DeviceChangedEventArgs e) 
     { 
      if (e.Device.Type == "Scanner") 
      { 
       scanner = (Scanner)explorer.CreateInstance(e.Device); 
       scanner.Open(); 
       scanner.Claim(1000); 
       scanner.DeviceEnabled = true; 
       scanner.DataEvent += new DataEventHandler(scanner_DataEvent); 
       scanner.DataEventEnabled = true; 
       scanner.DecodeData = true; 
      } 
     } 

     void scanner_DataEvent(object sender, DataEventArgs e) 
     { 
      UpdateEventHistory("Data Event"); 
      ASCIIEncoding encoder = new ASCIIEncoding(); 
      try 
      { 
       // Display the ASCII encoded label text 
       txtbScanDataLabel.Text = encoder.GetString(scanner.ScanDataLabel); 
       // Display the encoding type 
       txtbScanDataType.Text = scanner.ScanDataType.ToString(); 

       // re-enable the data event for subsequent scans 
       scanner.DataEventEnabled = true; 
      } 
      catch (PosControlException) 
      { 
       // Log any errors 
       UpdateEventHistory("DataEvent Operation Failed"); 
      } 
     } 

    } 
} 
+0

mis à jour la réponse principale avec plus d'info pour essayer – curtisk

2

de certains forums, et aussi dans la documentation POS SDK:

Vous devez ajouter ceci dans un fichier xml dans le répertoire:

C:\Program Files\Common Files\microsoft shared\Point Of Service\Control Configurations\ 


<PointOfServiceConfig Version="1.0"> 
<ServiceObject Type="Scanner" Name="Example scanner"> 
    <HardwareId From="HID\VID_04B4&amp;PID_0100&amp;REV_0001" To="HID\VID_04B4&amp;PID_0100&amp;REV_0001" /> 
</ServiceObject> 
</PointOfServiceConfig> 

Vous devez vérifier le matériel Id de votre appareil et de le remplacer dans la balise <HardwareId>

Ceci est prise et la configuration jouer.

+0

Merci cela fonctionne, aussi l'addition pour ce jeu de réponses nom de fichier Configuration.xml – Jamaxack

-1

J'ai trouvé la configuration ici (plate-forme Windows 7):

C: \ Documents and Settings \ All Users \ Application Data \ Microsoft \ Point de service \ Configuration \ Configuration.xml

Questions connexes