Declare Function Can_data(byval Std_mode As Integer , Byval Data_length As Integer , _
Byval Func_code As String , Byval Node_id As String , _
Byval Str_data As String) As String
Declare Sub Set_enable(byval Node_id As String , Byval Ctrl_mode As Integer , Byval Value As Integer)
'按值發(fā)送
Sub Send(byval Str_code As String )
Local I1 As Integer , Mystr As String * 4 , Mybyte As Byte , Length As Integer
Length = Len(str_code)
For I1 = 1 To Length Step 2
Mystr = Mid(str_code , I1 , 2)
Mybyte = Hexval(mystr)
Printbin Mybyte
Next
End Sub
'Can幀數(shù)據(jù)Std_mode=1為標(biāo)準(zhǔn)幀=0為擴(kuò)展幀,
'Data_length為數(shù)據(jù)區(qū)長(zhǎng)度最大8字節(jié),
'Func_code為功能碼一個(gè)字節(jié),
'Node_id為節(jié)點(diǎn)ID一個(gè)字節(jié),
'Str_data數(shù)據(jù)區(qū)十六進(jìn)制字符串,最大8個(gè)字節(jié)
Function Can_data(byval Std_mode As Integer , Byval Data_length As Integer , _
Byval Func_code As String , Byval Node_id As String , _
Byval Str_data As String) As String
Local Count As Integer , Str_code As String * 26 , I As Integer
Select Case Std_mode
Case Is = Std_frame
Str_code = "0" + Str(data_length) '標(biāo)準(zhǔn)幀的第一個(gè)字符為0第二個(gè)字符為數(shù)據(jù)區(qū)的字節(jié)數(shù)(最大8字節(jié))
Case Is = Ext_frame
Str_code = "8" + Str(data_length) '擴(kuò)展幀的第一個(gè)字符為8第二個(gè)字符為數(shù)據(jù)區(qū)的字節(jié)數(shù)(最大8字節(jié))
End Select
Str_code = Str_code + "0000"
If Len(func_code) = 1 Then
Str_code = Str_code + "0"
End If
Str_code = Str_code + Func_code
If Len(node_id) = 1 Then Str_code = Str_code + "0"
Str_code = Str_code + Node_id
Count = Len(str_data)
Count = 16 - Count
Str_code = Str_code + Str_data
For I = 1 To Count
Str_code = Str_code + "0"
Next I
Can_data = Str_code
End Function