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);
#
}
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 = ""
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
RecvData = "--"
Exit Do
End If
End If
Loop
End Function