Java和RFID编程(Omron RFID) [英] Java and RFID Programming (Omron RFID)
问题描述
大家好,目前在尝试连接Omron V720系列RFID设备读取和写入标签时陷入困境.我在VB6的源代码中有它,但是我想在Java中创建它.我正在使用RXTX连接到RFID设备并发送代码,但是我做不到.是否有人对此主题有任何经验或想法?
我已经设法通过com端口连接到RFID设备,但是当我发送消息时,错误指示灯闪烁,并且出现了一些混乱的回复.
读取的代码为00RDSAAA0001
写入代码为00WTSAAA0001
在此先感谢大家!
Java代码
Hi guys, am currently stuck while trying to connect an Omron V720 series RFID equipment to read and write tags. I''ve have it in source code on VB6 but i want to create it in Java. I am using RXTX to connect to the RFID equipment and send the codes, however, i failed to do it. Does anyone have any experience or idea on this topic?
I have manage to connect to the RFID equipment through com port but when i send the messages, the error light blinks and some jumbled up reply came back.
The read code is 00RDSAAA0001
The write code is 00WTSAAA0001
Thanks in advance guys!
Code in Java
<pre lang="cs">#
try {
#
char charTwo = 2;
#
char charThree = 3;
#
char charQ = 12;
#
String unicode = "00RDSAAA0001" + charThree;
#
byte[] bytes = unicode.getBytes("US-ASCII");
#
String line1 = charTwo + "00ST" + charThree + bytes;
#
String line2 = charTwo + "00RDSAAA0001" + charThree + bytes;
#
String line3 = charTwo + "00WTSAAA0001" + "HelloWorld" + charThree + bytes;
#
#
#
portList = CommPortIdentifier.getPortIdentifiers();
#
while (portList.hasMoreElements()) {
#
portId = (CommPortIdentifier) portList.nextElement();
#
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
#
System.out.println("RFID Testing........");
#
if (portId.getName().equals("COM1")) {
#
System.out.println("RFID Testing....Port Found");
#
try {
#
serialPort = (SerialPort) portId.open("SimpleWriteApp", 2000);
#
RFIDTest wr = new RFIDTest(serialPort);
#
} catch (PortInUseException e) {
#
System.out.println("Port In Use " + e);
#
}
#
try {
#
outputStream = serialPort.getOutputStream();
#
} catch (IOException e) {
#
System.out.println("Error writing to output stream " + e);
#
}
#
try {
#
serialPort.setSerialPortParams(38400, SerialPort.DATABITS_7, SerialPort.STOPBITS_2, SerialPort.PARITY_EVEN);
#
} catch (UnsupportedCommOperationException e) {
#
}
#
try {
#
outputStream.write(line1.getBytes());
#
outputStream.write(line2.getBytes());
#
outputStream.write(line2.getBytes());
#
#
} catch (IOException e) {
#
System.out.println("Error writing message " + e);
#
}
#
}
#
} catch (UnsupportedEncodingException ex) {
#
Logger.getLogger(RFIDTest.class.getName()).log(Level.SEVERE, null, ex);
#
}
VB中的代码
Code in VB
Private Sub Form_Load()
CommCtrl.Settings = Brate & "," & Ptype & "," & DataBit & "," & StopBit
CommCtrl.CommPort = PortNum
CommCtrl.PortOpen = True
SendData ("00ST")
RecvData
ClerData
End Sub
Private Sub Form_Load()
CommCtrl.Settings = Brate & "," & Ptype & "," & DataBit & "," & StopBit
CommCtrl.CommPort = PortNum
CommCtrl.PortOpen = True
SendData ("00ST")
RecvData
ClerData
End Sub
Private Sub Form_Unload(Cancel As Integer)
SendData ("00ST")
RecvData
CommCtrl.PortOpen = False
End Sub
Public Function BCC(command) As String
Dim LRC As Integer
Dim i As Integer
If (LenB(command) > 0) Then
For i = 1 To LenB(StrConv(command, vbFromUnicode))
LRC = LRC Xor AscB(MidB(StrConv(command, vbFromUnicode), i, 1))
Next i
End If
BCC = Chr(LRC)
End Function
Public Function SendData(sData As String)
CommCtrl.Output = Chr(2) & sData & Chr(3) & BCC(sData & Chr(3))
End Function
Public Function RecvData() As String
Dim lcnt As Integer
Dim indat As String
Dim sts As Byte
RecvData = ""
lcnt = 0
sts = 0
Wait (25)
Do
Dim Dummy As Integer
Dummy = DoEvents()
If CommCtrl.InBufferCount <> 0 Then
lcnt = 0
indat = CommCtrl.Input
Select Case sts
Case 0
If indat = Chr(2) Then
RecvData = "" 'ŽóMƒoƒbƒtƒ@‰Šú‰»
sts = 1
End If
Case 1
If indat = Chr(3) Then
sts = 2
Else
RecvData = RecvData + indat
End If
Case Else
sts = 0
If BCC(RecvData & Chr(3)) = indat Then
Exit Do
End If
End Select
Else
lcnt = lcnt + 1
If lcnt > 200 Then '200‰ñƒ‹[ƒv‚µ‚½‚çI—¹
RecvData = "--"
Exit Do
'End Function
End If
End If
Loop
End Function
推荐答案
我已经设法通过com端口连接到RFID设备,但是当我发送消息时,错误指示灯闪烁并且有些混乱回复回来了.
I have manage to connect to the RFID equipment through com port but when i send the messages, the error light blinks and some jumbled up reply came back.
我没有使用该设备的经验,但是您所描述的内容暗示线路设置中可能存在问题.您将线路设置为7E2;您确定这些值正确吗?我在PC上使用COM设备的经验是,大多数设备在8N1下运行效果最佳.一种检查方法是使用像HyperTerm这样的简单终端程序,您可以在其中捕获数据.
I don''t have any experience of this device but what you describe suggests a possible problem in the line settings. You are setting the line to 7E2; are you sure these values are correct? My experience of COM devices on PCs is that most operate best at 8N1. One way to check it out would be to use a simple terminal program like HyperTerm where you can capture the data in and out.
这篇关于Java和RFID编程(Omron RFID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!