Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub Btclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btclose.Click
- comm.Close()
- Application.Exit()
- End Sub
- Public Function getChecksum(ByVal bytcommandframe As Byte()) As Byte() '
- ' Check some which
- Dim Total As Byte = &H0
- For i = 0 To bytcommandframe.Length - 1
- Total = Total Xor bytcommandframe(i)
- Next
- ReDim Preserve bytcommandframe(bytcommandframe.Length)
- bytcommandframe(bytcommandframe.Length - 1) = Total
- Return bytcommandframe
- End Function
- Private Sub readserialnumber()
- Dim getSRN As Byte() = {&H4, &HFF, &H11}
- Dim Serialno As String = ""
- getSRN = getChecksum(getSRN)
- System.Threading.Thread.Sleep(200)
- comm.Write(getSRN, 0, getSRN.Length)
- ReadResponse()
- End Sub
- Private Sub WriteTag(ByVal pageno As Byte, ByVal datain As Byte())
- System.Threading.Thread.Sleep(150)
- Dim datatowrite() As Byte = {&H9, &HFF, &H14, pageno, datain(0), datain(1), datain(2), datain(3)}
- datatowrite = getChecksum(datatowrite) ' passing it in and checking against
- comm.Write(datatowrite, 0, datatowrite.Length) 'datatowrite is a 4 array
- End Sub
- Private Function ReadResponse() As Byte()
- System.Threading.Thread.Sleep(100)
- Dim arrayin(comm.BytesToRead - 1) As Byte
- comm.Read(arrayin, 0, comm.BytesToRead)
- Select Case arrayin(2)
- Case &H11 'serial number
- Select Case arrayin(3)
- Case 0
- Dim array1(4) As Byte
- System.Array.Copy(arrayin, 5, array1, 0, 4)
- tbInput.Text = BitConverter.ToString(array1)
- Case 1
- MsgBox("no transponder")
- Case Else
- MsgBox("another Error")
- End Select
- Case &H14 'For write data
- Select Case arrayin(3)
- Case 0
- MessageBox.Show("Data Written Successfully")
- Case 1
- MsgBox("no transponder")
- Case 3
- MsgBox("Write Error")
- Case Else
- MsgBox(" Error")
- End Select
- Case &H15 'For read data
- Select Case arrayin(0) 'Select the first element within the array
- Case &H9 'for a 1 block request
- Select Case arrayin(3) 'check the third element within the array i.e status bit
- Case 0 'Status = OK
- Dim block1(3) As Byte ' 4
- Array.Copy(arrayin, 4, block1, 0, 4) '
- Return block1
- Case 1 'Status = no transponder etc.
- MsgBox("no transponder")
- Case 3
- MsgBox("Write Error")
- Case Else
- MsgBox(" Error")
- End Select
- Case &HD 'For a 2 block request
- Select Case arrayin(3) 'check the third element within the array i.e status bit
- Case 0 'Status = OK
- Dim block2(7) As Byte
- Array.Copy(arrayin, 4, block2, 0, 8)
- Return block2
- Case 1 'Status = no transponder etc.
- MsgBox("no transponder")
- Case 3
- MsgBox("Write Error")
- Case Else
- MsgBox(" Error")
- End Select
- Case &H11
- Select Case arrayin(3) 'check the third element within the array i.e status bit
- Case 0 'Status = OK
- Dim block3(11) As Byte
- Array.Copy(arrayin, 4, block3, 0, 12)
- Return block3
- Case 1 'Status = no transponder etc.
- MsgBox("no transponder")
- Case 3
- MsgBox("Write Error")
- Case Else
- MsgBox(" Error")
- End Select
- Case &H15
- Select Case arrayin(3) 'check the third element within the array i.e status bit
- Case 0 'Status = OK
- Dim block4(15) As Byte
- Array.Copy(arrayin, 4, block4, 0, 16) 'starting from zero
- Return block4
- Case 1 'Status = no transponder etc.
- MsgBox("no transponder")
- Case 3
- MsgBox("Write Error")
- Case Else
- MsgBox(" Error")
- End Select
- End Select
- End Select
- End Function
- Private Function warningsadult() As Boolean
- If tbtemp.Text < "36.6" Then
- Healthwarnings.Items.Add(tbtemp.Text & " | High Temperature")
- ElseIf tbtemp.Text > "37.6" Then
- Healthwarnings.Items.Add(tbtemp.Text & " | High Temperature")
- ElseIf tbresth.Text > "76" Then
- Healthwarnings.Items.Add(tbresth.Text & " | High Heart Rate")
- ElseIf tbbloodp.Text > "120" Then
- Healthwarnings.Items.Add(tbbloodp.Text & " | High Blood Pressure")
- ElseIf tbrespiratory.Text > "60" Then
- Healthwarnings.Items.Add(tbrespiratory.Text & " | High Respiratory")
- Return False
- Return True
- End If
- End Function
- Private Sub performancepadding()
- 'If tbtemp.Text < 10.0 Then
- ' tbtemp.Text = tbtemp.Text.PadLeft(2, "0")
- ' tbbloodp.Text = tbbloodp.Text.PadLeft(3, "0") ' every needs to be a multiple of 4
- ' tbcreatinine.Text = tbcreatinine.Text.PadLeft(3, "0")
- ' tbchloride.Text = tbchloride.Text.PadLeft(3, "0")
- ' tbresth.Text = tbresth.Text.PadLeft(3, "0")
- ' tbtotalB.Text = tbtotalB.Text.PadLeft(2, "0")
- ' tbalanine.Text = tbalanine.Text.PadLeft(2, "0")
- ' tbalkaline.Text = tbalkaline.Text.PadLeft(3, "0")
- ' tbgamma.Text = tbgamma.Text.PadLeft(2, "0")
- ' tbaspartarte.Text = tbaspartarte.Text.PadLeft(2, "0")
- ' tbtrigly.Text = tbtrigly.Text.PadLeft(2, "0")
- ' tbresth.Text = tbresth.Text.PadLeft(1, "0")
- ' tbrespiratory.Text = tbrespiratory.Text.PadLeft(1, "0")
- 'End If
- End Sub
- Private Sub readsponseback(ByVal startblock As Integer, ByVal numofblock As Integer)
- Dim bytereadblock() As Byte = {&H6, &HFF, &H15, startblock, numofblock}
- bytereadblock = getChecksum(bytereadblock)
- comm.Write(bytereadblock, 0, bytereadblock.Length)
- System.Threading.Thread.Sleep(150)
- 'Were you wanna read from '"index" page number
- 'number of blocks
- ' LOOK at lab 8 my documents
- End Sub
- Private Sub readdateback(ByVal intstartpage As Integer, ByVal intnumberofblocks As Integer)
- Dim bytReadBlock() As Byte = {&H6, &HFF, &H15, CByte(intstartpage), CByte(intnumberofblocks)}
- bytReadBlock = getChecksum(bytReadBlock)
- comm.Write(bytReadBlock, 0, bytReadBlock.Length)
- End Sub
- Public Function warningadult() As Boolean
- If tbresth.Text > "76" Then
- Healthwarnings.Items.Add(tbresth.Text & " | High Heart Rate")
- ElseIf tbresth.Text < "70" Then
- Healthwarnings.Items.Add(tbresth.Text & " | High Heart Rate")
- End If
- End Function
- Public Function warningchild() As Boolean
- If tbresth.Text > "150" Then
- Healthwarnings.Items.Add(tbresth.Text & " | High Heart Rate")
- ElseIf tbresth.Text < "130" Then
- Healthwarnings.Items.Add(tbresth.Text & " | High Heart Rate")
- End If
- End Function
- Public Sub Btwriteall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btwriteall.Click
- readserialnumber()
- If adult2.Checked = True Then
- warningsadult()
- ElseIf Child1.Checked = True Then
- warningchild()
- End If
- warningchild()
- Dim radiobuttonint As Integer
- If Rbmale.Checked = True Then
- radiobuttonint = 1
- ElseIf Rbfemale.Checked = True Then
- radiobuttonint = 0
- End If
- warningsadult()
- performancepadding()
- Dim tbdateoflast As String = Now.ToString("ddMMyy")
- Dim tbtimeoflast As String = Now.ToString("HHmmss")
- '08/04/11
- Dim dataconcat As String = String.Concat(tbdateofbirth.Text, tbdateoflast, tbtimeoflast, tbtemp.Text, tbresth.Text, tbbloodp.Text, tbrespiratory.Text, tbsodium.Text, tbpotassium.Text, tbchloride.Text, tburea.Text, tbcreatinine.Text, tbph.Text, tbbase.Text, tbh.Text, tboxygen.Text, tbalbumin.Text, tbtotalB.Text, tbalanine.Text, tbalkaline.Text, tbgamma.Text, tbaspartarte.Text, tbtrigly.Text, tbtotalc.Text, tbredb.Text, tbhaemoglobin.Text, tbwhiteb.Text, radiobuttonint)
- ' joins multiple objects together
- 'replacing the decimals with nothing when writing the tag
- Dim allstrings As String = dataconcat.Replace(".", "")
- Dim test As String = "0000" '4
- Dim finalstring As String = allstrings & test
- Dim colofstr() As Byte = Encoding.ASCII.GetBytes(finalstring) ' passing the byte array the string
- ' Extract 4 bytes to store in a byte array
- ' send to write tag function all with page number
- Dim DatatoWrite(3) As Byte
- Dim x As Integer = 0
- Dim PageNo As Integer = 0
- For i = 0 To colofstr.Length - 1 Step 4
- Array.Copy(colofstr, x, DatatoWrite, 0, 4) ' copy to colofstr starting from 0 to 4
- WriteTag(PageNo, DatatoWrite)
- x += 4 ' next page
- PageNo += 1
- Next
- ReadResponse()
- ' limit the loop to 4 pages
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement