Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 11.39 KB | None | 0 0
  1.   Private Sub Btclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btclose.Click
  2.         comm.Close()
  3.         Application.Exit()
  4.     End Sub
  5.  
  6. #so this bit is gonna generate the checksum
  7.     Public Function getChecksum(ByVal bytcommandframe As Byte()) As Byte()  '
  8.         ' Check some which
  9. #this value is basically 0 to start us off
  10.         Dim Total As Byte = &H0
  11. #this loop with run through the byte array, Xor'ing each byte with the next one. it will then come up with a value (total)
  12.         For i = 0 To bytcommandframe.Length - 1
  13.             Total = Total Xor bytcommandframe(i)
  14.         Next
  15. this bit expands the bytearray by one and appends the checksum onto the end
  16.         ReDim Preserve bytcommandframe(bytcommandframe.Length)
  17.         bytcommandframe(bytcommandframe.Length - 1) = Total
  18.         Return bytcommandframe
  19.  
  20.     End Function
  21. getting the serial number
  22.     Private Sub readserialnumber()
  23. the packet needed to send to the tag
  24.         Dim getSRN As Byte() = {&H4, &HFF, &H11}
  25.         Dim Serialno As String = ""
  26. here the packet is getting a checksum put on the end
  27.         getSRN = getChecksum(getSRN)
  28. you dont need the sleep here because you havnt done anything to the reader yet
  29.         System.Threading.Thread.Sleep(200)
  30. this writes to the tag
  31.         comm.Write(getSRN, 0, getSRN.Length)
  32. here is where you need your delay
  33. i guess this gets the response back
  34.         ReadResponse()
  35.     End Sub
  36.  
  37.     Private Sub WriteTag(ByVal pageno As Byte, ByVal datain As Byte())
  38.  again i dunno why the delay is here
  39.  System.Threading.Thread.Sleep(150)
  40. creating a packet with the relevant data passed in from the function
  41.         Dim datatowrite() As Byte = {&H9, &HFF, &H14, pageno, datain(0), datain(1), datain(2), datain(3)}
  42.         datatowrite = getChecksum(datatowrite) ' passing it in and checking against
  43.         comm.Write(datatowrite, 0, datatowrite.Length) 'datatowrite is a 4 array
  44.     End Sub
  45.  
  46.     Private Function ReadResponse() As Byte()
  47.         System.Threading.Thread.Sleep(100)
  48. creating a new array the right size
  49.         Dim arrayin(comm.BytesToRead - 1) As Byte
  50. reading it in
  51.         comm.Read(arrayin, 0, comm.BytesToRead)
  52. your case statements for errors etc
  53.         Select Case arrayin(2)
  54.  
  55.             Case &H11 'serial number
  56.                 Select Case arrayin(3)
  57.                     Case 0
  58.                         Dim array1(4) As Byte
  59.                         System.Array.Copy(arrayin, 5, array1, 0, 4)
  60.                         tbInput.Text = BitConverter.ToString(array1)
  61.                     Case 1
  62.                         MsgBox("no transponder")
  63.  
  64.                     Case Else
  65.                         MsgBox("another Error")
  66.                 End Select
  67.  
  68.             Case &H14 'For write data
  69.                 Select Case arrayin(3)
  70.  
  71.                     Case 0
  72.                         MessageBox.Show("Data Written Successfully")
  73.                     Case 1
  74.                         MsgBox("no transponder")
  75.                     Case 3
  76.                         MsgBox("Write Error")
  77.  
  78.                     Case Else
  79.                         MsgBox(" Error")
  80.  
  81.                 End Select
  82.  
  83.             Case &H15 'For read data
  84.  
  85.                 Select Case arrayin(0) 'Select the first element within the array
  86.  
  87.                     Case &H9 'for a 1 block request
  88.  
  89.                         Select Case arrayin(3) 'check the third element within the array i.e status bit
  90.                             Case 0 'Status = OK
  91.  
  92.                                 Dim block1(3) As Byte ' 4
  93.  
  94.                                 Array.Copy(arrayin, 4, block1, 0, 4) '
  95.  
  96.                                 Return block1
  97.  
  98.  
  99.                             Case 1 'Status = no transponder etc.
  100.                                 MsgBox("no transponder")
  101.                             Case 3
  102.                                 MsgBox("Write Error")
  103.  
  104.                             Case Else
  105.                                 MsgBox(" Error")
  106.  
  107.  
  108.                         End Select
  109.  
  110.                     Case &HD 'For a 2 block request
  111.  
  112.                         Select Case arrayin(3) 'check the third element within the array i.e status bit
  113.                             Case 0 'Status = OK
  114.  
  115.                                 Dim block2(7) As Byte
  116.  
  117.                                 Array.Copy(arrayin, 4, block2, 0, 8)
  118.  
  119.                                 Return block2
  120.  
  121.  
  122.                             Case 1 'Status = no transponder etc.
  123.                                 MsgBox("no transponder")
  124.                             Case 3
  125.                                 MsgBox("Write Error")
  126.                             Case Else
  127.                                 MsgBox(" Error")
  128.                         End Select
  129.  
  130.  
  131.                     Case &H11
  132.                         Select Case arrayin(3) 'check the third element within the array i.e status bit
  133.                             Case 0 'Status = OK
  134.  
  135.                                 Dim block3(11) As Byte
  136.  
  137.                                 Array.Copy(arrayin, 4, block3, 0, 12)
  138.  
  139.                                 Return block3
  140.  
  141.  
  142.                             Case 1 'Status = no transponder etc.
  143.                                 MsgBox("no transponder")
  144.                             Case 3
  145.                                 MsgBox("Write Error")
  146.  
  147.                             Case Else
  148.                                 MsgBox(" Error")
  149.  
  150.                         End Select
  151.  
  152.  
  153.                     Case &H15
  154.                         Select Case arrayin(3) 'check the third element within the array i.e status bit
  155.                             Case 0 'Status = OK
  156.  
  157.                                 Dim block4(15) As Byte
  158.  
  159.                                 Array.Copy(arrayin, 4, block4, 0, 16) 'starting from zero
  160.  
  161.                                 Return block4
  162.  
  163.  
  164.                             Case 1 'Status = no transponder etc.
  165.                                 MsgBox("no transponder")
  166.                             Case 3
  167.                                 MsgBox("Write Error")
  168.                             Case Else
  169.                                 MsgBox(" Error")
  170.  
  171.                         End Select
  172.  
  173.                 End Select
  174.         End Select
  175.     End Function
  176.  
  177. here are your value warnings
  178.     Private Function warningsadult() As Boolean
  179.         If tbtemp.Text < "36.6" Then
  180.             Healthwarnings.Items.Add(tbtemp.Text & "      | High Temperature")
  181.  
  182.         ElseIf tbtemp.Text > "37.6" Then
  183.             Healthwarnings.Items.Add(tbtemp.Text & "      | High Temperature")
  184.  
  185.         ElseIf tbresth.Text > "76" Then
  186.             Healthwarnings.Items.Add(tbresth.Text & "   | High Heart Rate")
  187.  
  188.  
  189.         ElseIf tbbloodp.Text > "120" Then
  190.             Healthwarnings.Items.Add(tbbloodp.Text & "  | High Blood Pressure")
  191.  
  192.         ElseIf tbrespiratory.Text > "60" Then
  193.             Healthwarnings.Items.Add(tbrespiratory.Text & " | High Respiratory")
  194.  
  195.             Return False
  196.  
  197.             Return True
  198.         End If
  199.     End Function
  200.     Private Sub performancepadding()
  201.         'If tbtemp.Text < 10.0 Then
  202.         '    tbtemp.Text = tbtemp.Text.PadLeft(2, "0")
  203.  
  204.  
  205.         '    tbbloodp.Text = tbbloodp.Text.PadLeft(3, "0") ' every needs to be a multiple of 4
  206.         '    tbcreatinine.Text = tbcreatinine.Text.PadLeft(3, "0")
  207.         '    tbchloride.Text = tbchloride.Text.PadLeft(3, "0")
  208.         '    tbresth.Text = tbresth.Text.PadLeft(3, "0")
  209.         '    tbtotalB.Text = tbtotalB.Text.PadLeft(2, "0")
  210.         '    tbalanine.Text = tbalanine.Text.PadLeft(2, "0")
  211.         '    tbalkaline.Text = tbalkaline.Text.PadLeft(3, "0")
  212.         '    tbgamma.Text = tbgamma.Text.PadLeft(2, "0")
  213.         '    tbaspartarte.Text = tbaspartarte.Text.PadLeft(2, "0")
  214.         '    tbtrigly.Text = tbtrigly.Text.PadLeft(2, "0")
  215.         '    tbresth.Text = tbresth.Text.PadLeft(1, "0")
  216.         '    tbrespiratory.Text = tbrespiratory.Text.PadLeft(1, "0")
  217.         'End If
  218.     End Sub
  219.  
  220.     Private Sub readsponseback(ByVal startblock As Integer, ByVal numofblock As Integer)
  221.         Dim bytereadblock() As Byte = {&H6, &HFF, &H15, startblock, numofblock}
  222.         bytereadblock = getChecksum(bytereadblock)
  223.         comm.Write(bytereadblock, 0, bytereadblock.Length)
  224.         System.Threading.Thread.Sleep(150)
  225.  
  226.  
  227.         'Were you wanna read from '"index" page number
  228.         'number of blocks
  229.         ' LOOK at lab 8 my documents
  230.     End Sub
  231.     Private Sub readdateback(ByVal intstartpage As Integer, ByVal intnumberofblocks As Integer)
  232.  
  233.         Dim bytReadBlock() As Byte = {&H6, &HFF, &H15, CByte(intstartpage), CByte(intnumberofblocks)}
  234.         bytReadBlock = getChecksum(bytReadBlock)
  235.         comm.Write(bytReadBlock, 0, bytReadBlock.Length)
  236.     End Sub
  237.     Public Function warningadult() As Boolean
  238.  
  239.         If tbresth.Text > "76" Then
  240.             Healthwarnings.Items.Add(tbresth.Text & "   | High Heart Rate")
  241.         ElseIf tbresth.Text < "70" Then
  242.             Healthwarnings.Items.Add(tbresth.Text & "   | High Heart Rate")
  243.         End If
  244.     End Function
  245.     Public Function warningchild() As Boolean
  246.         If tbresth.Text > "150" Then
  247.             Healthwarnings.Items.Add(tbresth.Text & "   | High Heart Rate")
  248.         ElseIf tbresth.Text < "130" Then
  249.             Healthwarnings.Items.Add(tbresth.Text & "   | High Heart Rate")
  250.         End If
  251.     End Function
  252.  
  253.  
  254.     Public Sub Btwriteall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btwriteall.Click
  255.  
  256.         readserialnumber()
  257.  
  258.  
  259.         If adult2.Checked = True Then
  260.             warningsadult()
  261.         ElseIf Child1.Checked = True Then
  262.             warningchild()
  263.  
  264.         End If
  265.         warningchild()
  266.  
  267.         Dim radiobuttonint As Integer
  268.         If Rbmale.Checked = True Then
  269.             radiobuttonint = 1
  270.         ElseIf Rbfemale.Checked = True Then
  271.             radiobuttonint = 0
  272.         End If
  273.  
  274.         warningsadult()
  275.  
  276.  
  277.         performancepadding()
  278.  
  279.         Dim tbdateoflast As String = Now.ToString("ddMMyy")
  280.         Dim tbtimeoflast As String = Now.ToString("HHmmss")
  281.  
  282.         '08/04/11
  283.  
  284.         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)
  285.         ' joins multiple objects together
  286.         'replacing the decimals with nothing when writing the tag
  287.         Dim allstrings As String = dataconcat.Replace(".", "")
  288.  
  289.         Dim test As String = "0000" '4
  290.         Dim finalstring As String = allstrings & test
  291.  
  292.         Dim colofstr() As Byte = Encoding.ASCII.GetBytes(finalstring) ' passing the byte array the string
  293.  
  294.  
  295.         ' Extract 4 bytes to store in a byte array
  296.         ' send to write tag function all with page number
  297.  
  298.         Dim DatatoWrite(3) As Byte
  299.         Dim x As Integer = 0
  300.         Dim PageNo As Integer = 0
  301.  
  302.         For i = 0 To colofstr.Length - 1 Step 4
  303.             Array.Copy(colofstr, x, DatatoWrite, 0, 4) ' copy to colofstr starting from 0 to 4
  304.             WriteTag(PageNo, DatatoWrite)
  305.             x += 4 ' next page
  306.             PageNo += 1
  307.         Next
  308.         ReadResponse()
  309.  
  310.  
  311.         ' limit the loop to 4 pages
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement