29 messaggi dal 17 settembre 2001
Ciao ragazzi,

premetto che non sono esperto in c#,infatti ho una classe di questo tipo, che utilizza una classe generica List.

public List<BarcodeDataResponse> GetBarcodes()
{
symbolBaseComm.Open();

List<BarcodeDataResponse> barcodes = new List<BarcodeDataResponse>();

byte[] bytes = { 0x07, 0x02, 0x00 };
bool fReceived = false;
PortData receivedData = null;

for (int i = 0; i < 5 && !fReceived; i++)
{
symbolBaseComm.Send(new PortData(bytes, bytes.Length));

receivedData = symbolBaseComm.Receive();
if (receivedData.NumBytes >= 10 && receivedData.Bytes[0] == 6)
{
fReceived = true;
}
else
{
Thread.Sleep(200);
}
}

symbolBaseComm.Close();

if (receivedData != null && receivedData.NumBytes > 9 && receivedData.Bytes[0] == 6)
{
int byteIndex = 10;

while (byteIndex < receivedData.NumBytes - 10)
{
int packetLength = (int)receivedData.Bytes[byteIndex];
if (packetLength > 0)
{
int packetType = (int)receivedData.Bytes[byteIndex + 1];
if (packetType > 0)
{
BarcodeDataResponse barcodeData = new BarcodeDataResponse();

barcodeData.Timestamp = ExtractPackedTimestamp(
receivedData.Bytes[byteIndex + packetLength - 3],
receivedData.Bytes[byteIndex + packetLength - 2],
receivedData.Bytes[byteIndex + packetLength - 1],
receivedData.Bytes[byteIndex + packetLength - 0]);

barcodeData.Code = Encoding.ASCII.GetString(receivedData.Bytes, byteIndex + 2, packetLength - 5);

barcodeData.CodeType = symbolBaseComm.CodeTypes[(byte)packetType];

barcodes.Add(barcodeData);
}

byteIndex += packetLength + 1;
}
else
{
++byteIndex;
}
}
}
else
{
return null;
}

return barcodes;
}

Vorrei inserire il return barcodes in una listbox, per esempio. Ma non capisco come estrapolare il dato. L'unica cosa che riesco è utilizzare il Count e contare quante righe ci sono.

Sicuramente qualcuno di Voi riuscirà a rispondermi.

Grazie mille,
Luca.

Luca.
quali proprietà espone BarcodeDataResponse? alla ListBox devi solo indicare i campi per il testo e per il valore associato ad ogni item

ciao marco

Chi parla senza modestia troverà difficile rendere buone le proprie parole.
Confucio

http://nostromo.spaces.live.com/default.aspx
29 messaggi dal 17 settembre 2001
BarcodeDataResponse espone..

public class BarcodeDataResponse
{
public DateTime Timestamp;
public string Code;
public string CodeType;
}

Ipotizzando un listbox1.items.add(), non devo agganciare GetBarcodes()?

Luca.
devi fare qualcosa del genere
listbox1.DataSource = GetBarcodes();
listbox1.DataBind();

prima di richiamare il metodo DataBind devi specificare la proprietà DataTextField e DataValueField

ciao marco

Chi parla senza modestia troverà difficile rendere buone le proprie parole.
Confucio

http://nostromo.spaces.live.com/default.aspx

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.
Community
Ultimi messaggi
UTENTI ONLINE
    In primo piano

    I più letti di oggi

    Media
    In evidenza
    MISC