Advertisement
Guest User

Untitled

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