2012-07-12 39 views
1
public void writeToCard2(string sourceText, string cardType) 
    { 
     Cursor.Current = Cursors.WaitCursor; 

     int itemLength = sourceText.Split(',').Length; 
     sourceText = itemLength.ToString() + "," + sourceText + ","; 
     byte[] dataByteArray = Encoding.GetEncoding(932).GetBytes(sourceText); 
     //textBox2.Text = BitConverter.ToString(dataByteArray); 

     int dataByteLength = dataByteArray.Length; 
     int writeLength = dataByteLength + 11; 
     byte[] writeByteArray = new byte[writeLength]; 

     writeByteArray[0] = 0x02;//STX 
     writeByteArray[1] = 0x00;//アドレス 
     writeByteArray[2] = 0x78;//コマンド 
     writeByteArray[3] = Convert.ToByte(dataByteLength + 4);//データ長 
     writeByteArray[4] = 0xa1;//詳細コマンド 
     writeByteArray[5] = 0x00;//書き込み開始ブロック番號 
     writeByteArray[6] = Convert.ToByte(dataByteLength);//書き込みバイト數 
     for (int i = 0; i < dataByteLength; i++) 
     { 
      writeByteArray[i + 7] = dataByteArray[i];//書き込みデータ 
     } 
     writeByteArray[dataByteLength + 7] = 0x40;//オプションフラグ 
     writeByteArray[dataByteLength + 8] = 0x03;//ETX 
     byte sum = 0x00; 
     for (int i = 0; i <= dataByteLength + 8; i++) 
     { 
      sum += writeByteArray[i]; 
     } 
     writeByteArray[dataByteLength + 9] = sum;//SUM値 
     writeByteArray[dataByteLength + 10] = 0x0d;//CR 

     //string tempStr = BitConverter.ToString(writeByteArray); 

     //port.Write(writeByteArray, 0, writeByteArray.Length); 
     serialPort1.Write(writeByteArray, 0, writeByteArray.Length); 

     writeCardType = cardType; 

     Cursor.Current = Cursors.Default; 
    } 

上述方法在該行上的RFID標籤寫入數據寫入RFID

serialPort1.Write(writeByteArray, 0, writeByteArray.Length); 

writeByteArray是被超過RFID變量的限制的數據的大小,我的老闆說將其轉換爲ascii代碼,然後寫入RFID

此幫助可以減少數據的大小嗎?

是否有其他方式使用不同的圓形使用RFID標籤?

+0

限制是標籤可以存儲的數據量,而不是您用來與RFID控制器通信的協議。這是一個很難設計的限制,除了丟棄所有標籤並獲得其他類型之外,您無法做出任何改變。您必須找到更智能的方法將信息編碼到可用位中,例如使用一個字節來編碼兩位數字。 – 2012-07-12 09:36:00

+0

@HansPassant是啊我試圖尋找更聰明的方式,但現在我找不到一個....改變類型的rfid是其中一個選項,但它會增加項目的成本 – 2012-07-13 00:10:35

回答

1

您的老闆說要轉換爲ASCII導致設備讀取信息byt每字節。我與那些設備一起工作,這是他們通常讀取傳遞給他們的數據流的方式。

沒有任何分配在這方面的好處,導致數據的大小保持不變,信息rapresentation是什麼變化。那是。