Chinaunix首页 | 论坛 | 博客
  • 博客访问: 885370
  • 博文数量: 286
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1841
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-09 16:26
文章分类

全部博文(286)

文章存档

2016年(38)

2015年(248)

我的朋友

分类: C#/.net

2015-05-14 13:25:43


点击(此处)折叠或打开

  1. Public Class Form1

  2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3.         Form2.Show()
  4.     End Sub

  5.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  6.         If Form2 Is Nothing Then
  7.             MessageBox.Show("请先打开发送数据模块,进行数据发送")
  8.             Return
  9.         Else
  10.             Form3.Show()
  11.         End If



  12.     End Sub

  13.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  14.     End Sub
  15. End Class

点击(此处)折叠或打开

  1. Public Class Form2

  2.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3.         'TODO: 这行代码将数据加载到表“SDDataSet.sd”中。您可以根据需要移动或移除它。
  4.         Me.SdTableAdapter.Fill(Me.SDDataSet.sd)
  5.         Dim hshu As String = Str(SdDataGridView.RowCount)
  6.         '显示设备名称
  7.         'Dim sb As String
  8.         ''Dim sbstr As String
  9.         '设备号TextBox.Refresh()
  10.         'sb = 设备号TextBox.Text
  11.         'TextBox2.Text = sb


  12.     End Sub

  13.     Private Sub 更新_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 更新.Click
  14.         '--------------------------------------- 输入封装,判断输入是否正确----------------------------------------------
  15.         Dim n As Integer
  16.         Dim m As Integer
  17.         Dim hshu As String = Str(SdDataGridView.RowCount)

  18.         For n = 0 To hshu - 2

  19.             '判断label是否为八进制()
  20.             Dim label As String = Trim(SdDataGridView.Rows(n).Cells(2).Value.ToString)
  21.             For m = 1 To Len(label)

  22.                 If Mid(label, m, 1) < "0" Or Mid(label, m, 1) > "7" Or Len(label) <> 3 Then
  23.                     MessageBox.Show("请在LABEL单元格内为3位的八进制数")
  24.                     Return
  25.                 End If
  26.             Next

  27.             '判断data是否为十六进制
  28.             Dim data As String = Trim(SdDataGridView.Rows(n).Cells(3).Value.ToString)
  29.             For m = 1 To Len(data)
  30.                 ' Label5.Text = Mid(data, m, 1)
  31.                 If Not ((Mid(data, m, 1) >= "0" And Mid(data, m, 1) <= "9") Or (Mid(data, m, 1) >= "A" And Mid(data, m, 1) <= "F") Or (Mid(label, m, 1) >= "a" And Mid(data, m, 1) <= "f")) Then
  32.                     MessageBox.Show("请在DATA单元格内输入十六进制数")
  33.                     Return
  34.                 End If
  35.             Next

  36.             '判断ssm是否为二进制
  37.             Dim ssm As String = Trim(SdDataGridView.Rows(n).Cells(4).Value.ToString)
  38.             For m = 1 To Len(ssm)
  39.                 If Mid(ssm, m, 1) < "0" Or Mid(ssm, m, 1) > "1" Or Len(ssm) <> 2 Then
  40.                     MessageBox.Show("请在SSM单元格内为2位的二进制数")
  41.                     Return
  42.                 End If
  43.             Next

  44.             '判断sdi是否为二进制
  45.             Dim sdi As String = Trim(SdDataGridView.Rows(n).Cells(5).Value.ToString)
  46.             For m = 1 To Len(sdi)
  47.                 If Mid(sdi, m, 1) < "0" Or Mid(sdi, m, 1) > "1" Or Len(sdi) <> 2 Then
  48.                     MessageBox.Show("请在SDI单元格内为2位的二进制数")
  49.                     Return
  50.                 End If
  51.             Next
  52.             '--------------------------------------- 更新数据到数据库----------------------------------------------
  53.         Next
  54.         If MessageBox.Show("确认更新吗?", "更新记录", MessageBoxButtons.OKCancel) = DialogResult.OK Then
  55.             Me.Validate()
  56.             SdBindingSource.EndEdit()
  57.             TableAdapterManager.UpdateAll(SDDataSet)
  58.         Else
  59.             SdBindingSource.CancelEdit()
  60.         End If
  61.         'SdBindingSource.AddNew()
  62.     End Sub

  63.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  64.         '--------------------------------------- 删除一行数据----------------------------------------------
  65.         SdDataGridView.Rows.RemoveAt(SdDataGridView.CurrentRow.Index)
  66.     End Sub

  67.     Private Sub 奇校_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 奇校.Click
  68.         '--------------------------------------- ----------------------------------------------
  69.         Dim eid As String = "bao"
  70.         Dim label As String = "bao"
  71.         Dim data As String = "bao"
  72.         Dim ssm As String = "bao"
  73.         Dim sdi As String = "bao"
  74.         Dim labelhanshu As String = "bao"
  75.         Dim hshu As Integer = (SdDataGridView.RowCount)
  76.         Dim n As Integer
  77.         'Dim m As Integer

  78.         For n = 0 To hshu - 2
  79.             '-------------------提取发送模块每行的数据---------------
  80.             eid = Trim(Str(SdDataGridView.Rows(n).Cells(1).Value))

  81.             label = Trim(Str(SdDataGridView.Rows(n).Cells(2).Value))

  82.             data = Trim(Str(SdDataGridView.Rows(n).Cells(3).Value))

  83.             ssm = Trim(Str(SdDataGridView.Rows(n).Cells(4).Value))

  84.             sdi = Trim(Str(SdDataGridView.Rows(n).Cells(5).Value))

  85.             SdDataGridView.Rows(n).Cells(6).Value = jijiaoyan(label, sdi, data, ssm) '奇校验
  86.         Next

  87.     End Sub

  88.     Public Function jijiaoyan(ByVal label As String, ByVal sdi As String, ByVal data As String, ByVal ssm As String) As String '
  89.         '--------------------------------------- 奇校验函数----------------------------------------------
  90.         Dim shujuzi As String
  91.         Dim label_b As String = (OCT_to_BIN(label))
  92.         Dim sdi_b As String = sdi
  93.         Dim data_b As String = HEX_to_BIN(data)
  94.         Dim ssm_b As String = ssm
  95.         Dim i As Long
  96.         Dim b1 As String
  97.         Dim b2 As String
  98.         Dim p As String

  99.         shujuzi = Trim(label_b & sdi_b & data_b & ssm_b)

  100.         For i = 1 To (Len(shujuzi) - 1)
  101.             b1 = Mid(shujuzi, i, 1)
  102.             b2 = Mid(shujuzi, i + 1, 1)
  103.             p = b1 And b2

  104.         Next

  105.         If p = "1" Then
  106.             Return "0"
  107.         Else
  108.             Return "1"
  109.         End If

  110.     End Function

  111.     Public Function OCT_to_BIN(ByVal Oct As String) As String
  112.         Dim i As Long
  113.         Dim B As String

  114.         For i = 1 To Len(Oct)
  115.             Select Case Mid(Oct, i, 1)
  116.                 Case "0" : B = B & "000"
  117.                 Case "1" : B = B & "001"
  118.                 Case "2" : B = B & "010"
  119.                 Case "3" : B = B & "011"
  120.                 Case "4" : B = B & "100"
  121.                 Case "5" : B = B & "101"
  122.                 Case "6" : B = B & "110"
  123.                 Case "7" : B = B & "111"
  124.             End Select
  125.         Next i
  126.         While Strings.Left(B, 1) = "0"
  127.             B = Strings.Right(B, Len(B) - 1)
  128.         End While
  129.         OCT_to_BIN = B
  130.     End Function

  131.     Public Function HEX_to_BIN(ByVal Hex As String) As String
  132.         Dim i As Long
  133.         Dim B As String
  134.         Hex = UCase(Hex)
  135.         For i = 1 To Len(Hex)
  136.             Select Case Mid(Hex, i, 1)
  137.                 Case "0" : B = B & "0000"
  138.                 Case "1" : B = B & "0001"
  139.                 Case "2" : B = B & "0010"
  140.                 Case "3" : B = B & "0011"
  141.                 Case "4" : B = B & "0100"
  142.                 Case "5" : B = B & "0101"
  143.                 Case "6" : B = B & "0110"
  144.                 Case "7" : B = B & "0111"
  145.                 Case "8" : B = B & "1000"
  146.                 Case "9" : B = B & "1001"
  147.                 Case "A" : B = B & "1010"
  148.                 Case "B" : B = B & "1011"
  149.                 Case "C" : B = B & "1100"
  150.                 Case "D" : B = B & "1101"
  151.                 Case "E" : B = B & "1110"
  152.                 Case "F" : B = B & "1111"
  153.             End Select
  154.         Next i
  155.         While Strings.Left(B, 1) = "0"
  156.             B = Strings.Right(B, Len(B) - 1)
  157.         End While
  158.         B = B.PadLeft(19, "0")
  159.         HEX_to_BIN = B
  160.     End Function

  161.     
  162.     
  163.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  164.         MessageBox.Show("ARINC429 分析软件发送数据模块说明" & vbCr + vbLf & "1. ID单元格是自动编号请不要填写" & vbCr + vbLf & "2. 设备号单元格请填写十六进制数据" & vbCr + vbLf & "3. LABEL单元格请填写八进制数据" & vbCr + vbLf & "4. DATA单元格请填写十六进制数据" & vbCr + vbLf & "5. SSM和SDI单元格请填写二进制数据" & vbCr + vbLf & "6. P单元格为奇校验位,可手动输入,也可以点击奇校验按钮进行校验" & vbCr + vbLf & "7. 更新按钮将数据更新到数据库并自动发送数据" & vbCr + vbLf & "8. 删除数据按钮将会删除选中的一行数据" & vbCr + vbLf & "9. 要显示设备名称,请先单击界面上方设备名称的文字")
  165.     End Sub

  166.     Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
  167.         '---------------------------------------显示设备名称----------------------------------------------
  168.         Dim dqhang As String = SdDataGridView.CurrentRow.Index
  169.         Dim sbstr As String = SdDataGridView.Rows(dqhang).Cells(1).Value '获取第rows行的索引为num列的值
  170.         '判断设备号
  171.         Select Case sbstr
  172.             Case "000"
  173.                 TextBox2.Text = "宝"
  174.         End Select
  175.     End Sub
  176. End Class


点击(此处)折叠或打开

  1. Public Class Form3

  2.     Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3.         'TODO: 这行代码将数据加载到表“RDDataSet.redata”中。您可以根据需要移动或移除它。
  4.         Me.RedataTableAdapter.Fill(Me.RDDataSet.redata)
  5.         Dim hshu As Integer = (Form2.SdDataGridView.RowCount)

  6.     End Sub

  7.     Private Sub 解析_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 解析.Click
  8.         'Dim id As String
  9.         Dim eid As String = "bao"
  10.         Dim label As String = "bao"
  11.         Dim data As String = "bao"
  12.         Dim ssm As String = "bao"
  13.         Dim sdi As String = "bao"
  14.         Dim labelhanshu As String = "bao"
  15.         Dim hshu As Integer = (Form2.SdDataGridView.RowCount)
  16.         Dim n As Integer
  17.         'Dim m As Integer

  18.         For n = 0 To hshu - 2
  19.             RedataBindingSource.AddNew()
  20.             '-------------------提取发送模块的数据---------------
  21.             eid = Str(Form2.SdDataGridView.Rows(n).Cells(1).Value)
  22.             RedataDataGridView.Rows(n).Cells(1).Value = eid

  23.             label = Str(Form2.SdDataGridView.Rows(n).Cells(2).Value)
  24.             RedataDataGridView.Rows(n).Cells(2).Value = label
  25.             labelhanshu = Trim(label)

  26.             data = Str(Form2.SdDataGridView.Rows(n).Cells(3).Value)

  27.             ssm = Str(Form2.SdDataGridView.Rows(n).Cells(4).Value)

  28.             sdi = Str(Form2.SdDataGridView.Rows(n).Cells(5).Value)

  29.             '-------------------判断label号----------------------
  30.             Select Case labelhanshu
  31.                 Case "162"
  32.                     RedataDataGridView.Rows(n).Cells(4).Value = label162(data)
  33.                     RedataDataGridView.Rows(n).Cells(3).Value = "BNR"
  34.                 Case "35"
  35.                     RedataDataGridView.Rows(n).Cells(4).Value = label035(data)
  36.                     RedataDataGridView.Rows(n).Cells(3).Value = "BCD"
  37.                 Case "201"
  38.                     RedataDataGridView.Rows(n).Cells(4).Value = label201(data)
  39.                     RedataDataGridView.Rows(n).Cells(3).Value = "BCD"
  40.                 Case "32"
  41.                     RedataDataGridView.Rows(n).Cells(4).Value = label032(data)
  42.                     RedataDataGridView.Rows(n).Cells(3).Value = "BCD"
  43.                 Case "33"
  44.                     RedataDataGridView.Rows(n).Cells(4).Value = label033(data)
  45.                     RedataDataGridView.Rows(n).Cells(3).Value = "BCD"
  46.                 Case "34"
  47.                     RedataDataGridView.Rows(n).Cells(4).Value = label034(data)
  48.                     RedataDataGridView.Rows(n).Cells(3).Value = "BCD"
  49.                 Case "222"
  50.                     RedataDataGridView.Rows(n).Cells(4).Value = label222(data)
  51.                     RedataDataGridView.Rows(n).Cells(3).Value = "BNR"
  52.                 Case "202"
  53.                     RedataDataGridView.Rows(n).Cells(4).Value = label202(data)
  54.                     RedataDataGridView.Rows(n).Cells(3).Value = "BNR"
  55.                 Case "173"
  56.                     RedataDataGridView.Rows(n).Cells(4).Value = label173(data)
  57.                     RedataDataGridView.Rows(n).Cells(3).Value = "BNR"
  58.                 Case "174"
  59.                     RedataDataGridView.Rows(n).Cells(4).Value = label174(data)
  60.                     RedataDataGridView.Rows(n).Cells(3).Value = "BNR"

  61.             End Select


  62.         Next

  63.         
  64.     End Sub
  65.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  66.         Me.Validate()
  67.         RedataBindingSource.EndEdit()
  68.         TableAdapterManager.UpdateAll(RDDataSet)

  69.     End Sub

  70.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  71.         RedataDataGridView.Rows.RemoveAt(RedataDataGridView.CurrentRow.Index)
  72.     End Sub

  73.     Public Function label162(ByVal data As String) As String 'ok ADF方位角
  74.         Dim datab = HEX_to_BIN(data) 'data转为二进制

  75.         Dim gn As String

  76.         Dim hanyi As String = Mid(datab, 2, 12)
  77.         Dim fuhao As String = Mid(datab, 1, 1)
  78.         Dim hanyizi As Single = Val(hanyi)
  79.         Dim fwj As Single
  80.         Dim strfwj As String
  81.         If fuhao = "0" Then
  82.             hanyizi = BIN_to_DEC(hanyizi)
  83.             fwj = (hanyizi / 4096) * 180
  84.             strfwj = Str(fwj)
  85.             gn = "VOR方位角为正" & strfwj & "度"
  86.         Else
  87.             hanyizi = qiuyuanma(hanyizi)
  88.             hanyizi = BIN_to_DEC(hanyizi)
  89.             fwj = (hanyizi / 4096) * 180
  90.             strfwj = Str(fwj)
  91.             gn = "VOR方位角为负" & strfwj & "度"
  92.         End If

  93.         Return gn
  94.     End Function
  95.     Public Function label032(ByVal data As String) As String 'ok ADF频率
  96.         Dim datab = HEX_to_BIN(data) 'data转为二进制
  97.         Dim BFO As String = Mid(datab, 19, 1)
  98.         Dim mode As String = Mid(datab, 18, 1)
  99.         Dim fr As String

  100.         Dim _1000m As String = 1000 * (BIN_to_DEC(Mid(datab, 1, 3)))
  101.         Dim _100m As String = 100 * (BIN_to_DEC(Mid(datab, 4, 4)))
  102.         Dim _10m As String = 10 * (BIN_to_DEC(Mid(datab, 8, 4)))
  103.         Dim _1m As String = BIN_to_DEC(Mid(datab, 12, 4))
  104.         Dim _01m As String = Mid(datab, 16, 1)

  105.         If _01m = "1" Then
  106.             _01m = "0.05"
  107.         Else
  108.             _01m = "0.00"
  109.         End If

  110.         If BFO = "0" Then
  111.             BFO = "BFO off"
  112.         Else
  113.             BFO = "BFO on"
  114.         End If

  115.         If mode = "0" Then
  116.             mode = "ADF mode"
  117.         Else
  118.             mode = "ANT mode"
  119.         End If
  120.         fr = Val(_1000m) + Val(_100m) + Val(_10m) + Val(_1m) + Val(_01m)
  121.         Return BFO & "," & mode & ",ADF频率为" & fr & "KHz"
  122.     End Function
  123.     Public Function label035(ByVal data As String) As String 'ok DME频率
  124.         Dim datab = HEX_to_BIN(data) 'data转为二进制
  125.         Dim flx As String = Mid(datab, 15, 2) '取14、15位用来判断频率的类型
  126.         Dim fr As String
  127.         Dim fm As String
  128.         Dim _10m As String = 10 * (BIN_to_DEC(Mid(datab, 1, 3)))
  129.         Dim _1m As String = (BIN_to_DEC(Mid(datab, 4, 4)))
  130.         Dim _01m As String = 0.1 * (BIN_to_DEC(Mid(datab, 8, 4)))
  131.         Dim _001m As String = Mid(datab, 12, 1)

  132.         If _001m = "1" Then
  133.             _001m = "0.05"
  134.         Else
  135.             _001m = "0.00"
  136.         End If

  137.         If flx = "00" Then
  138.             fm = "VOR频率为"
  139.         ElseIf flx = "01" Then
  140.             fm = "ILS频率为"
  141.         Else
  142.             fm = "MLS频率为"
  143.         End If
  144.         fr = 100 + Val(_10m) + Val(_1m) + Val(_01m) + Val(_001m)
  145.         Return "DME波道对应的" & fm & fr & "MHz"
  146.     End Function
  147.     Public Function label201(ByVal data As String) As String 'ok DME测距
  148.         Dim datab = HEX_to_BIN(data) 'data转为二进制
  149.         Dim juli As String
  150.         Dim _100m As String = 100 * BIN_to_DEC(Mid(datab, 1, 3))
  151.         Dim _10m As String = 10 * BIN_to_DEC(Mid(datab, 4, 4))
  152.         Dim _1m As String = BIN_to_DEC(Mid(datab, 8, 4))
  153.         Dim _01m As String = 0.1 * BIN_to_DEC(Mid(datab, 12, 4))
  154.         Dim _001m As String = 0.01 * BIN_to_DEC(Mid(datab, 16, 4))
  155.         juli = Val(_100m) + Val(_10m) + Val(_1m) + Val(_01m + _001m)
  156.         Return "DME测得距离为" & juli & "N.M"
  157.     End Function
  158.     Public Function label033(ByVal data As String) As String ' ok ILS频率

  159.         Dim datab = HEX_to_BIN(data) 'data转为二进制
  160.         Dim ils_lx As String = Mid(datab, 18, 2)
  161.         Dim fr As String = "bao"
  162.         Dim strils As String = "bao"
  163.         Dim _10m As String = 10 * BIN_to_DEC(Mid(datab, 1, 3))
  164.         Dim _1m As String = BIN_to_DEC(Mid(datab, 4, 4))
  165.         Dim _01m As String = 0.1 * BIN_to_DEC(Mid(datab, 8, 4))
  166.         Dim _001m As String = 0.01 * BIN_to_DEC(Mid(datab, 12, 4))
  167.         fr = 100 + Val(_10m) + Val(_1m) + Val(_01m) + Val(_001m)
  168.         Select Case ils_lx
  169.             Case "00"
  170.                 strils = "CATEGORY NOT"
  171.             Case "01"
  172.                 strils = "ILS Ⅰ型"
  173.             Case "10"
  174.                 strils = "ILS Ⅱ型"
  175.             Case "11"
  176.                 strils = "ILS Ⅲ型"
  177.         End Select
  178.         Return strils & fr & "MHz"
  179.     End Function
  180.     Public Function label034(ByVal data As String) As String ' ok VOR or ILS 频率
  181.         Dim datab = HEX_to_BIN(data) 'data转为二进制
  182.         Dim f As String = Mid(datab, 16, 1) '从string字符串的start字符开始取得length长度的字符串,如果省略第三个参数表示从start字符开始到字符串结尾的字符串
  183.         Dim fr As Double
  184.         Dim fm As String
  185.         Dim _10m As Double = 10 * Val(BIN_to_DEC(Mid(datab, 1, 3)))
  186.         Dim _1m As Double = Val(BIN_to_DEC(Mid(datab, 4, 4)))
  187.         Dim _01m As Double = 0.1 * Val(BIN_to_DEC(Mid(datab, 8, 4)))
  188.         Dim _001m As Double = 0.01 * Val(BIN_to_DEC(Mid(datab, 12, 4)))
  189.         If f = "0" Then
  190.             fm = "VOR频率"
  191.         Else
  192.             fm = "ILS频率"
  193.         End If
  194.         fr = 100 + Val(_10m) + Val(_1m) + Val(_01m) + Val(_001m)
  195.         Return fm & fr & "MHz"
  196.     End Function
  197.     Public Function label222(ByVal data As String) As String 'ok VOR方位角
  198.         Dim datab = HEX_to_BIN(data) 'data转为二进制
  199.         Dim mb As String = Mid(datab, 17, 3)
  200.         Dim strmb As String = "bao"
  201.         Dim gn As String
  202.         Select Case mb
  203.             Case "001"
  204.                 strmb = "外指点信标400HZ,"
  205.             Case "010"
  206.                 strmb = "中指点信标1300HZ,"
  207.             Case "100"
  208.                 strmb = "内指点信标3000HZ,"
  209.         End Select
  210.         Dim hanyi As String = Mid(datab, 2, 12)
  211.         Dim fuhao As String = Mid(datab, 1, 1)
  212.         Dim hanyizi As Single = Val(hanyi)
  213.         Dim fwj As Single
  214.         Dim strfwj As String
  215.         If fuhao = "0" Then
  216.             hanyizi = BIN_to_DEC(hanyizi)
  217.             fwj = (hanyizi / 4096) * 180
  218.             strfwj = Str(fwj)
  219.             gn = strmb & "VOR方位角为" & strfwj & "度"
  220.         Else
  221.             hanyizi = qiuyuanma(hanyizi)
  222.             hanyizi = BIN_to_DEC(hanyizi)
  223.             fwj = (hanyizi / 4096) * 180
  224.             strfwj = Str(fwj)
  225.             gn = strmb & "VOR方位角为负" & strfwj & "度"
  226.         End If

  227.         Return gn
  228.     End Function
  229.     Public Function label202(ByVal data As String) As String ' DME测距-BNR
  230.         Dim datab = HEX_to_BIN(data) 'data转为二进制
  231.         Dim jl As String
  232.         Dim gn As String

  233.         Dim hanyi As String = Mid(datab, 2, 16)
  234.         Dim fuhao As String = Mid(datab, 1, 1)
  235.         'Dim hanyizi As Single = Val(hanyi)
  236.         Dim strjl As Single

  237.         If fuhao = "0" Then
  238.             hanyi = BIN_to_DEC(hanyi)
  239.             jl = (hanyi / 65536) * 512
  240.             strjl = Str(jl)
  241.             gn = "DME测得的距离为" & strjl & "N.M"
  242.         Else
  243.             hanyi = qiuyuanma(hanyi)
  244.             hanyi = BIN_to_DEC(hanyi)
  245.             jl = (hanyi / 65536) * 512
  246.             strjl = Str(jl)
  247.             gn = "DME测得的距离为" & strjl & "N.M"
  248.         End If

  249.         Return gn
  250.     End Function
  251.     Public Function label173(ByVal data As String) As String 'LOC 偏差
  252.         Dim datab = HEX_to_BIN(data) 'data转为二进制
  253.         Dim gn As String
  254.         Dim hanyi As String = Mid(datab, 2, 12)
  255.         Dim fuhao As String = Mid(datab, 1, 1)
  256.         'Dim hanyizi As Single = Val(hanyi)
  257.         Dim pc As Single
  258.         Dim strpc As String

  259.         If fuhao = "0" Then
  260.             hanyi = BIN_to_DEC(hanyi)
  261.             pc = (hanyi / 4096) * 0.4
  262.             strpc = Str(pc)
  263.             gn = "方位角右偏0" & strpc & "DDM"
  264.         Else
  265.             hanyi = qiuyuanma(hanyi)
  266.             hanyi = BIN_to_DEC(hanyi)
  267.             pc = (hanyi / 4096) * 0.4
  268.             strpc = Str(pc)
  269.             gn = "方位角左偏0" & strpc & "DDM"
  270.         End If
  271.         Label2.Text = pc
  272.         Return gn
  273.     End Function
  274.  
  275.     Public Function label174(ByVal data As String) As String 'GS 偏差
  276.         Dim datab = HEX_to_BIN(data) 'data转为二进制
  277.         Dim gn As String
  278.         Dim hanyi As String = Mid(datab, 2, 12)
  279.         Dim fuhao As String = Mid(datab, 1, 1)
  280.         'Dim hanyizi As Single = Val(hanyi)
  281.         Dim pc As Single
  282.         Dim strpc As String

  283.         If fuhao = "0" Then
  284.             hanyi = BIN_to_DEC(hanyi)
  285.             pc = (hanyi / 4096) * 0.4
  286.             strpc = Str(pc)
  287.             gn = "下滑角角上偏0" & strpc & "DDM"
  288.         Else
  289.             hanyi = qiuyuanma(hanyi)
  290.             hanyi = BIN_to_DEC(hanyi)
  291.             pc = (hanyi / 4096) * 0.4
  292.             strpc = Str(pc)
  293.             gn = "下滑角下偏0" & strpc & "DDM"
  294.         End If

  295.         Return gn
  296.     End Function

  297.     

  298.     Public Function HEX_to_BIN(ByVal Hex As String) As String
  299.         Dim i As Long
  300.         Dim B As String
  301.         Hex = UCase(Hex)
  302.         For i = 1 To Len(Hex)
  303.             Select Case Mid(Hex, i, 1)
  304.                 Case "0" : B = B & "0000"
  305.                 Case "1" : B = B & "0001"
  306.                 Case "2" : B = B & "0010"
  307.                 Case "3" : B = B & "0011"
  308.                 Case "4" : B = B & "0100"
  309.                 Case "5" : B = B & "0101"
  310.                 Case "6" : B = B & "0110"
  311.                 Case "7" : B = B & "0111"
  312.                 Case "8" : B = B & "1000"
  313.                 Case "9" : B = B & "1001"
  314.                 Case "A" : B = B & "1010"
  315.                 Case "B" : B = B & "1011"
  316.                 Case "C" : B = B & "1100"
  317.                 Case "D" : B = B & "1101"
  318.                 Case "E" : B = B & "1110"
  319.                 Case "F" : B = B & "1111"
  320.             End Select
  321.         Next i
  322.         While Strings.Left(B, 1) = "0"
  323.             B = Strings.Right(B, Len(B) - 1)
  324.         End While
  325.         B = B.PadLeft(19, "0")
  326.         HEX_to_BIN = B
  327.     End Function

  328.     Public Function BIN_to_DEC(ByVal Bin As String) As Long
  329.         Dim i As Long
  330.         For i = 1 To Len(Bin)
  331.             BIN_to_DEC = BIN_to_DEC * 2 + Val(Mid(Bin, i, 1))
  332.         Next i
  333.     End Function
  334.     Public Function DEC_to_BIN(ByVal Dec As String) As String
  335.         DEC_to_BIN = ""
  336.         Do While Dec > 0
  337.             DEC_to_BIN = Dec Mod 2 & DEC_to_BIN
  338.             Dec = Dec \ 2
  339.         Loop
  340.     End Function

  341.     Public Function qiuyuanma(ByVal Bin As String) As Long '补码转原码
  342.         Dim i As Long
  343.         Dim B As String
  344.         Bin = UCase(Bin)
  345.         For i = 1 To Len(Bin)
  346.             Select Case Mid(Bin, i, 1)
  347.                 Case "0" : B = B & "1"
  348.                 Case "1" : B = B & "0"
  349.             End Select
  350.         Next
  351.         B = BIN_to_DEC(B)
  352.         B = B + 1
  353.         B = DEC_to_BIN(B)
  354.         B = B.PadLeft(19, "0")
  355.         qiuyuanma = B
  356.     End Function

  357.     
  358.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  359.         End
  360.     End Sub

  361.     
  362. End Class


阅读(1117) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~