這是Omron V系列。
-
- Dim Cancelpressed, acknowledged As Boolean, PageNumbers(1 To 30) As Integer
- Dim pagemax As Integer '¤@­ÓTAGªº³Ì¤j­¶¼Æ¡C
- Dim command As String '¤G¦ì¼Æ©R¥O½X2
- Dim commandtosend As String '©R¥O¶Ç°e
- Dim appropriatelength As Integer
- Dim Version As String
- Option Explicit
- Private Sub allshow()
- '¨Ï©Ò¦³ªº³]©w­È­P¯à
- Action.Enabled = True
- TagsizeFrame.Enabled = True
- Port.Enabled = True
- DataFormat.Enabled = True
- ByteSelectionFrame.Enabled = True
- Triggertypeframe.Enabled = True
- PageSelection.Enabled = True
- End Sub
- Private Sub allhide()
- 'This makes all the settings frames disabled, so that they cannot be changed (usually during FIFO operations)
- Action.Enabled = False
- TagsizeFrame.Enabled = False
- Port.Enabled = False
- DataFormat.Enabled = False
- ByteSelectionFrame.Enabled = False
- Triggertypeframe.Enabled = False
- PageSelection.Enabled = False
- End Sub
- Private Sub initarray()
- 'This initializes the array of bits for page specification
- 'ªì©l¤Æ©Ò¦³RFID Page bits
- Dim counter As Integer
- For counter = 1 To 30
- PageNumbers(counter) = 0
- Next
- End Sub
- Function buildopcode() As String
- Dim opcode As String
- ' set the hex / binary part of the opcode
- If FormatASCII Then
- opcode = "1"
- Else: If FormatHEX Then opcode = "0"
- End If
- 'set the trigger type part of the opcode
- Select Case TriggerType
- Case "Single Trigger"
- opcode = opcode + "0"
- Case "Single Auto"
- opcode = opcode + "1"
- Case "FIFO Trigger"
- opcode = opcode + "8"
- Case "FIFO Auto"
- opcode = opcode + "9"
- Case "FIFO Continue"
- opcode = opcode + "A"
- Case "FIFO Repeat"
- opcode = opcode + "B"
- End Select
- buildopcode = opcode
- End Function
- Function EndCodetext(Code As String) As String
- 'convert the opcode recieved into the description for the opcode
- Select Case Code
- Case "00"
- EndCodetext = "Normal End"
- Case "01"
- EndCodetext = "Parity Error"
- Case "11"
- EndCodetext = "Framing Error"
- Case "12"
- EndCodetext = "Overrun Error"
- Case "14"
- EndCodetext = "Format Error"
- Case "18"
- EndCodetext = "Frame Length Error"
- Case "70"
- EndCodetext = "Transmission Error"
- Case "71"
- EndCodetext = "Verification Error"
- Case "72"
- EndCodetext = "Tag Absence Error"
- Case "7A"
- EndCodetext = "Address Specification Error"
- Case "7B"
- EndCodetext = "Outside of Write Area Error"
- Case "7D"
- EndCodetext = "Write Protection Error"
- Case "7F"
- EndCodetext = "ID System Error"
- Case "7C"
- EndCodetext = "Antenna Hardware Error"
- End Select
- End Function
- Function pageformat() As String
- Dim string1, string2, string3, string4 As String
- Dim count1, count2, count3, count4, count, multiplier As Integer
- 'Determine the decimal equivalent of the 8 bit groups for the page specification
- multiplier = 4
- For count = 1 To 6
- count1 = count1 + (PageNumbers(count) * multiplier)
- multiplier = multiplier * 2
- Next
- multiplier = 1
- For count = 7 To 14
- count2 = count2 + (PageNumbers(count) * multiplier)
- multiplier = multiplier * 2
- Next
- multiplier = 1
- For count = 15 To 22
- count3 = count3 + (PageNumbers(count) * multiplier)
- multiplier = multiplier * 2
- Next
- multiplier = 1
- For count = 23 To 30
- count4 = count4 + (PageNumbers(count) * multiplier)
- multiplier = multiplier * 2
- Next
- 'Determine the Hex equavilent of the page specifications
- string1 = Hex(count1)
- If Len(string1) = 1 Then string1 = "0" + string1
- string2 = Hex(count2)
- If Len(string2) = 1 Then string2 = "0" + string2
- string3 = Hex(count3)
- If Len(string3) = 1 Then string3 = "0" + string3
- string4 = Hex(count4)
- If Len(string4) = 1 Then string4 = "0" + string4
- pageformat = string4 + string3 + string2 + string1
- End Function
- Private Sub ByteAcknowledge_Click()
- 'sets the acknowledged flag for FIFO Continue Operations
- acknowledged = True
- End Sub
- Private Sub Bytes128_Click()
- 'Sets the tag parameters for 128 Byte tags
- pagemax = 14
- VScroll1.Min = 14
- VScroll3.Min = 111
- VScroll2.Min = pagemax - Val(StartPage) + 1
- If Val(StartPage.Text) > pagemax Then StartPage.Text = pagemax
- End Sub
- Private Sub Bytes256_Click()
- 'Sets the tag parameters for 256 Byte tags
- pagemax = 30
- VScroll1.Min = 30
- VScroll3.Min = 240
- VScroll2.Min = pagemax - Val(StartPage) + 1
- If Val(StartPage.Text) > pagemax Then StartPage.Text = pagemax
- End Sub
- Private Sub Bytewrite_Click()
- 'Makes the appropriate frames visible when Byte Write is selected
- ByteSelectionFrame.Visible = True
- Triggertypeframe.Visible = True
- ByteWriteButton.Enabled = True
- ByteWriteCancel.Enabled = False
- DataFormat.Visible = True
- PageSelection.Visible = False
- WriteDataFrame.Visible = False
- ReadDataFrame.Visible = False
- ByteWriteFrame.Visible = True
- StringSent.Text = ""
- StringRec.Text = ""
- ResponseCodeNumber.Text = ""
- ResponseCodeDescription.Text = ""
- End Sub
- Private Sub ByteWriteButton_Click()
- Dim startingaddress As String
- Dim opcodeforbytewrite, bytebuffer As String
- Dim byteendcode As String
- Dim satisfied As Boolean
- 'Performs the sending of data for a Byte Write operation
- If Not MSComm1.PortOpen Then MSComm1.PortOpen = True
- Cancelpressed = False
- acknowledged = False
- ByteWriteButton.Enabled = False
- ByteWriteCancel.Enabled = True
- If Int(Len(ByteWriteData.Text) / 2) <> (Len(ByteWriteData.Text) / 2) Then ByteWriteData.Text = ByteWriteData.Text + "0"
- startingaddress = Hex(StartingByte.Text)
- If Len(startingaddress) = 1 Then startingaddress = "0" + startingaddress
- opcodeforbytewrite = buildopcode
- MSComm1.Output = "04" + opcodeforbytewrite + startingaddress + ByteWriteData.Text + Chr$(13)
- StringSent.Text = "04" + opcodeforbytewrite + startingaddress + ByteWriteData.Text
- satisfied = False
- allhide
- Do
- bytebuffer = ""
- Do
- DoEvents
- bytebuffer = bytebuffer & MSComm1.Input
- Loop Until InStr(bytebuffer, Chr$(13)) Or Cancelpressed
- If Not Cancelpressed Then StringRec.Text = Left(bytebuffer, Len(bytebuffer) - 1)
- 'parse out end code
- If Not Cancelpressed Then byteendcode = Left(bytebuffer, 2)
- If Not Cancelpressed Then ResponseCodeNumber.Text = byteendcode
- If Not Cancelpressed Then ResponseCodeDescription.Text = EndCodetext(byteendcode)
-
- If TriggerType = "Single Auto" Or TriggerType = "Single Trigger" Then satisfied = True
- If TriggerType = "FIFO Trigger" Then satisfied = True
- If TriggerType = "FIFO Continue" And Cancelpressed Then satisfied = True
- If TriggerType = "FIFO Repeat" And Cancelpressed Then satisfied = True
- If TriggerType = "FIFO Auto" Then satisfied = True
- If TriggerType = "FIFO Continue" And (Not Cancelpressed) And byteendcode = "00" Then Beep
- If TriggerType = "FIFO Continue" And (Not Cancelpressed) Then
- Do
- DoEvents
- ByteAcknowledge.Visible = True
- Loop Until acknowledged Or Cancelpressed
- End If
- If acknowledged Then
- MSComm1.Output = "11" + Chr$(13)
- ResponseCodeNumber.Text = ""
- StringRec.Text = ""
- ResponseCodeDescription.Text = ""
- End If
- acknowledged = False
- ByteAcknowledge.Visible = False
- If (Not Cancelpressed) And ResponseCodeNumber.Text = "00" Then Beep
- Loop Until satisfied
- allshow
-
-
- Cancelpressed = False
- MSComm1.PortOpen = False
- ByteWriteButton.Enabled = True
- ByteWriteCancel.Enabled = False
- End Sub
- Private Sub ByteWriteCancel_Click()
- Dim inbuffer As String
- Cancelpressed = True
- MSComm1.Output = "13" + Chr(13)
- Do
- DoEvents
- inbuffer = inbuffer & MSComm1.Input
- Loop Until InStr(inbuffer, Chr$(13))
- End Sub
- Private Sub CancelRead_Click()
- Dim inbuffer As String
- Cancelpressed = True
- MSComm1.Output = "13" + Chr(13)
- Do
- DoEvents
- inbuffer = inbuffer & MSComm1.Input
- Loop Until InStr(inbuffer, Chr$(13))
- End Sub
- Private Sub ReadAcknowledge_Click()
- 'sets acknowledged flag for FIFO Continue operations
- acknowledged = True
- End Sub
- Private Sub Readtag_Click()
- Dim Hold As Integer, Temp As String, Buffer As String
- Dim count As Integer
- Dim pagespecification, endcode As String
- Dim opcodeforread As String '2 digit option code
- Dim satisfied As Boolean
-
- initarray 'sets array of page markers to 0
- For count = Val(StartPage) To (Val(StartPage) + Val(NumberofPages) - 1)
- PageNumbers(count) = 1
- Next
-
- pagespecification = pageformat()
- If Not MSComm1.PortOpen Then MSComm1.PortOpen = True
- Cancelpressed = False
- acknowledged = False
- Readtag.Enabled = False
- CancelRead.Enabled = True
- 'Build string to send
- command = "01" 'Selects write for Command
- 'build opcode
- Buffer = ""
- opcodeforread = buildopcode
- commandtosend = command + opcodeforread + pagespecification
- MSComm1.Output = commandtosend + Chr$(13)
- StringSent.Text = commandtosend
- ResponseCodeNumber.Text = ""
- StringRec.Text = ""
- ResponseCodeDescription.Text = ""
- 'waitforresponse
- satisfied = False
- allhide
- Do
- Buffer = ""
- Do
- DoEvents
- Buffer = Buffer + MSComm1.Input
-
- Loop Until InStr(Buffer, Chr$(13)) Or Cancelpressed
- If Not Cancelpressed Then StringRec.Text = Left(Buffer, Len(Buffer) - 1)
- 'parse out end code
- If Not Cancelpressed Then endcode = Left(Buffer, 2)
- If Not Cancelpressed Then ResponseCodeNumber.Text = endcode
- If Not Cancelpressed Then ResponseCodeDescription.Text = EndCodetext(endcode)
- If (Not Cancelpressed) And (endcode = "00") Then DataRead.Text = Right$(Left$(Buffer, Len(Buffer) - 1), Len(Buffer) - 3)
- If (Not Cancelpressed) And FormatASCII And DataRead.Text = "" Then DataRead.Text = "Please Enter Valid ASCII data on the RFID Tag"
- If TriggerType = "Single Auto" Or TriggerType = "Single Trigger" Then satisfied = True
- If TriggerType = "FIFO Trigger" Then satisfied = True
- If TriggerType = "FIFO Continue" And Cancelpressed Then satisfied = True
- If TriggerType = "FIFO Repeat" And Cancelpressed Then satisfied = True
- If TriggerType = "FIFO Auto" Then satisfied = True
- 'Acknowledge a repeat
- If TriggerType = "FIFO Continue" And (Not Cancelpressed) And endcode = "00" Then Beep
- If TriggerType = "FIFO Continue" And (Not Cancelpressed) Then
-
- Do
- DoEvents
- ReadAcknowledge.Visible = True
- Loop Until acknowledged Or Cancelpressed
- End If
- If acknowledged Then
- MSComm1.Output = "11" + Chr$(13)
- ResponseCodeNumber.Text = ""
- StringRec.Text = ""
- ResponseCodeDescription.Text = ""
- End If
- acknowledged = False
- ReadAcknowledge.Visible = False
- If (Not Cancelpressed) And ResponseCodeNumber.Text = "00" Then Beep
- Loop Until satisfied
- allshow
- Cancelpressed = False
- Readtag.Enabled = True
- CancelRead.Enabled = False
- MSComm1.PortOpen = False
- End Sub
- Private Sub VScroll1_Change()
- StartPage.Text = VScroll1.Value
- VScroll2.Min = pagemax - Val(StartPage) + 1
- If Val(StartPage.Text) > pagemax Then StartPage.Text = pagemax
- End Sub
- Private Sub VScroll2_Change()
- If VScroll2.Value > 16 Then VScroll2.Value = 16
- NumberofPages.Text = VScroll2.Value
- End Sub
- Private Sub VScroll3_Change()
- StartingByte.Text = VScroll3.Value
- End Sub
- Private Sub WriteAcknowledge_Click()
- acknowledged = True
- End Sub
- Private Sub WriteCancel_Click()
- Dim inbuffer As String
- Cancelpressed = True
- MSComm1.Output = "13" + Chr(13)
- Do
- DoEvents
- inbuffer = inbuffer & MSComm1.Input
- Loop Until InStr(inbuffer, Chr$(13))
-
- End Sub
- Private Sub COM1_Click()
- 'Sets the COMM port to 1
- MSComm1.CommPort = 1
- End Sub
- Private Sub Com2_Click()
- 'Sets the COMM port to 2
- MSComm1.CommPort = 2
- End Sub
- Private Sub Command2_Click()
- 'Exits program
- End
- End Sub
- Private Sub Form_Load()
- 'Initializes variables to defaults
- pagemax = 14 'Number of pages on 128 Byte tag
- VScroll1.Min = 14 'property for page selection
- StartPage.Text = VScroll1.Value
- NumberofPages.Text = VScroll2.Value
- VScroll2.Min = pagemax - Val(StartPage) + 1
- If Val(StartPage.Text) > pagemax Then StartPage.Text = pagemax
- ByteAcknowledge.Visible = False
- ReadAcknowledge.Visible = False
- WriteAcknowledge.Visible = False
- 'Set Version Number
- Version = "Version 1.00"
- versiondisplay.Text = Version
- 'Set default for Port and Tag Size
- Bytes128 = True
- COM1 = True
- FormatHEX = True
- 'Hide all action frames
- WriteDataFrame.Visible = False
- ReadDataFrame.Visible = False
- ByteWriteFrame.Visible = False
- Triggertypeframe.Visible = False
- DataFormat.Visible = False
- PageSelection.Visible = False
- ByteSelectionFrame.Visible = False
- 'Configure Default Port Settings
- MSComm1.CommPort = 1
- MSComm1.Settings = "9600,E,8,1"
-
- 'Add Items to Write Action List
- TriggerType.AddItem "Single Trigger"
- TriggerType.AddItem "Single Auto"
- TriggerType.AddItem "FIFO Trigger"
- TriggerType.AddItem "FIFO Auto"
- TriggerType.AddItem "FIFO Continue"
- TriggerType.AddItem "FIFO Repeat"
- End Sub
-
- Private Sub Other_Click()
- 'Enable Other Actions Frame
- ByteWriteFrame.Visible = False
- WriteDataFrame.Visible = False
- ReadDataFrame.Visible = False
- PageSelection.Visible = False
- DataFormat.Visible = False
- Triggertypeframe.Visible = False
- ByteSelectionFrame.Visible = False
- StringSent.Text = ""
- StringRec.Text = ""
- ResponseCodeNumber.Text = ""
- ResponseCodeDescription.Text = ""
- End Sub
- Private Sub Read_Click()
- 'Enable Read Frame
- Readtag.Enabled = True
- CancelRead.Enabled = False
- ByteSelectionFrame.Visible = False
- Triggertypeframe.Visible = True
- DataFormat.Visible = True
- PageSelection.Visible = True
- ByteWriteFrame.Visible = False
- WriteDataFrame.Visible = False
- ReadDataFrame.Visible = True
- StringSent.Text = ""
- StringRec.Text = ""
- ResponseCodeNumber.Text = ""
- ResponseCodeDescription.Text = ""
- End Sub
- Private Sub SendWrite_Click()
- 'Performs the sending of the data on a Page Send command
- Dim Hold As Integer, Temp As String, Buffer As String
- Dim count As Integer
- Dim pagespecification, endcode As String
- Dim test As Integer
- Dim satisfied As Boolean
-
- Dim opcodeforwrite As String '2 digit option code
- initarray 'sets array of page markers to 0
- If Not MSComm1.PortOpen Then MSComm1.PortOpen = True
- Cancelpressed = False
- SendWrite.Enabled = False
- WriteCancel.Enabled = True
- acknowledged = False
- For count = Val(StartPage) To (Val(StartPage) + Val(NumberofPages) - 1)
- PageNumbers(count) = 1
- Next
-
- If FormatASCII Then
- appropriatelength = 8 * NumberofPages
- If Len(WriteData) > appropriatelength Then WriteData = Left(WriteData, appropriatelength)
- For count = 1 To (appropriatelength - Len(WriteData))
- WriteData = WriteData + "0"
- Next
- End If
- If FormatHEX Then
- appropriatelength = 16 * NumberofPages
- If Len(WriteData) > appropriatelength Then WriteData = Left(WriteData, appropriatelength)
- For count = 1 To (appropriatelength - Len(WriteData))
- WriteData = WriteData + "0"
- Next
- End If
-
- pagespecification = pageformat()
- opcodeforwrite = buildopcode
- commandtosend = "02" + opcodeforwrite + pagespecification + WriteData
- MSComm1.Output = commandtosend + Chr$(13)
- StringSent.Text = commandtosend
- ResponseCodeNumber.Text = ""
- StringRec.Text = ""
- ResponseCodeDescription.Text = ""
- 'waitforresponse
- satisfied = False
- allhide
- Do
- Buffer = ""
- Do
- DoEvents
- Buffer = Buffer & MSComm1.Input
- Loop Until InStr(Buffer, Chr$(13)) Or Cancelpressed
- ResponseCodeNumber.Text = ""
- StringRec.Text = ""
- ResponseCodeDescription.Text = ""
- If Not Cancelpressed Then StringRec.Text = Left(Buffer, Len(Buffer) - 1)
- If Not Cancelpressed Then endcode = Left(Buffer, 2)
- If Not Cancelpressed Then ResponseCodeNumber.Text = endcode
- If Not Cancelpressed Then ResponseCodeDescription.Text = EndCodetext(endcode)
- If TriggerType = "Single Auto" Or TriggerType = "Single Trigger" Then satisfied = True
- If TriggerType = "FIFO Trigger" Then satisfied = True
- If TriggerType = "FIFO Continue" And Cancelpressed Then satisfied = True
- If TriggerType = "FIFO Repeat" And Cancelpressed Then satisfied = True
- If TriggerType = "FIFO Auto" Then satisfied = True
- 'Acknowledge a repeat
- If TriggerType = "FIFO Continue" And (Not Cancelpressed) And endcode = "00" Then Beep
- If TriggerType = "FIFO Continue" And (Not Cancelpressed) Then
- Do
-
- DoEvents
-
- WriteAcknowledge.Visible = True
- Loop Until acknowledged Or Cancelpressed
- End If
- If acknowledged Then
- MSComm1.Output = "11" + Chr$(13)
- ResponseCodeNumber.Text = ""
- StringRec.Text = ""
- ResponseCodeDescription.Text = ""
- End If
- acknowledged = False
- WriteAcknowledge.Visible = False
- If (Not Cancelpressed) And ResponseCodeNumber.Text = "00" Then Beep
- Loop Until satisfied
- allshow
- satisfied = False
- Cancelpressed = False
- SendWrite.Enabled = True
- WriteCancel.Enabled = False
- MSComm1.PortOpen = False
- End Sub
- Private Sub Write_Click()
- 'Enable Write Frame
- DataFormat.Visible = True
- PageSelection.Visible = True
- ByteSelectionFrame.Visible = False
- Triggertypeframe.Visible = True
- SendWrite.Enabled = True
- WriteCancel.Enabled = False
- ByteWriteFrame.Visible = False
- WriteDataFrame.Visible = True
- ReadDataFrame.Visible = False
- StringSent.Text = ""
- StringRec.Text = ""
- ResponseCodeNumber.Text = ""
- ResponseCodeDescription.Text = ""
- End Sub
-
複製代碼 ... |