cmdolcet69 said:
cmdolcet69 said:
Armin before i send the document can you help me out on this for
loop .when i do the following loop and code for the initial loop
it will
[...]
As I see in your other thread, there are already people helping
you.
Armin
2.1.11 Erase Table Request
0x07
Description:
The "Erase Table Request" provides a means for the master to clear
the calibration table in preparation for a new table upload. The
slave will respond with an ACK packet upon successful completion of
the erase operation.
Erase Packet Format
Byte Offset Byte
0 1 2 3 4 5 6
0 BMS Len Cmd Pass CRC
BMS binary message start byte
Value: 0x2A ('*')
Len command length, number of bytes in message - excludes BMS Value
Range: 0x06
Cmd binary command - erase table
Value: 0x07
Pass factory pass code
Value: 11548
CRC Cyclic Redundancy Check - excludes BMS
Value Range: 0x0000 - 0xFFFF
Both the Pass and CRC take 2 bytes
Looks as if you don't need any hex conversions.....
Imports System.Runtime.InteropServices
Public Class Form1
<StructLayout(LayoutKind.Sequential, pack:=1)> _
Class EraseTable
Public BMS As Byte = &H2A
Public len As Byte = 6
Public cmd As Byte = 7
Public Pass As Short = 11548
Public CRC As Short = &H3082
Public Function ToByteArray() As Byte()
Dim result As Byte()
Dim gch As GCHandle
gch = GCHandle.Alloc(Me, GCHandleType.Pinned)
Try
ReDim result(Marshal.SizeOf(Me) - 1)
Marshal.Copy(gch.AddrOfPinnedObject, result, 0,
result.Length)
Finally
gch.Free()
End Try
Return result
End Function
End Class
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim out As New EraseTable
Dim bytes As Byte()
bytes = out.ToByteArray
'send byte-array here
End Sub
End Class
This solution puts the data into an object. It's better to handle. Then it's
written into a byte array as a whole, so you don't have to bother about each
single byte anymore. The usage is shown in Form1_Load.
I guess you will have to write different commands to the device, so you can
use this approach for each one.
Armin