Results 1 to 13 of 13

Thread: Expert please HELP

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Expert please HELP

    Greetings to all who read this,

    1. I need to load 1 Mb binary file
    2. In binary file are all settings for programming device like this sample
    which will I try to explain...

    0012DB3A000300470016000000160600000FFE3D(second block)436B041A80017FF60000000022F085F0BDEF68D2724EFFBEFBECC9309249F6409072245730324CC648C304C6B0B72EFB008AC540648490834ADCA82D9490 01B5EDD9357ADC46352842646036011DE712000849306A5DD85576C7C96FA5B4445B6F68ED6EF4DEAD696A55C911B5145FBF 7FBFFEFBEC99820A56BBBDB7B777BDDDDEF77BDDDDEEEEFC8EEF

    this is like U see hex format
    when i load file, I need to make this

    "0012" first line of binary file ( here is hex ) are = 18 decimal and this is size of block need's to be sent at first

    "DB3A" are checksum of that lenght

    "0003" are device type

    "0047" are number of block's in this binary file ( decimal = 71 block )

    "00160000" are device ID1
    "00160600" are device ID2
    "00FFE3D" are size of binary file ( decimal = 1048125 bytes )

    This all info is from first line of binary code ( I have put here hex for better understanding )

    "0012DB3A000300470016000000160600000FFE3D"


    Another block, size lenght and CRC

    "436B" = 17259 ( binary lenght of second block )
    "041A" = checksum
    "8001" = not important
    "7FF6" = decimal value 32758
    "00000000" start address

    Now using mscoom I need to send first ( 0012 hex = 18 decimal line of code )

    send "DB3A000300470016000000160600000FFE3D" = 1 block size
    wait for device to accept and store data
    return from device = 06 ( this means that data are stored correctly )

    send 2 block "436B041A80017FF60000000022F085F0BDEF68D2724EFFBEFBECC9309249F6409072245730324CC648C304C6B0B72EFB008 AC540648490834ADCA82D949001B5EDD9357A..........." lenght 17259 binary

    Also here, afther sending 2 block data, I need to wait for ( 06 ) which is
    response from device that data are stored correctly.

    Afther lenght of 17259 binary, there is also line of code which gives info of another block like described beffore.

    I'm sorry for bad explanation if U dont understand...

    Please help...
    B.R
    VB Client/Server

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Expert please HELP

    What is is that you need help with? What code have you already written?
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Expert please HELP

    I havent write till now any code, coz I dont how !
    I dont know how to load file and read from it what I have described in previous post ( read first bytes which will give me adresses, lenght of blocks, and lenght of entire blocks in file ).

    I can send 1 mb file using mscomm control, that is not problem, but it will be not writed OK!

    Here is small sample what info I need from that file when I load it to be able
    send it correctly.


    Lenght of block : 0x0012 (18)
    Block CRC: 0xDB3A
    Model Typ: 0x0003
    Entire blocks in file: 0x0047 (71)
    SistemID1: 0016.0000
    SistemID2: 0016.0600
    Entire File Lenght: 0x000FFE3D (1048125)

    ** BLOCK 1 **

    Lenght of block: 0x436B (17259)
    Block CRC: 0x041A
    Block 1: 0x80
    Block 2: 0x01
    Decimal lenght: 0x7FF6 (32758)
    Start Address: 0x00000000

    ** BLOCK 2 **

    Lenght of block: 0x402E (16430)
    Blok CRC: 0x800E
    Block 1: 0x80
    Block 2: 0x01
    Decimal lenght: 0x7FF6 (32758)
    Start address: 0x00007FF6

    etc, etc until I'l have all 71 bloks and their lenght

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Expert please HELP

    This sample code will help me.

    1.Load any binary file (example 10 kb)
    2.Read first 15 bytes from file and put him in text box
    3.Then skip (example) 40 bytes and select 10 bytes afther that then show them in text 2
    4.create ini file with (text1 and text2) from this file I will use settings for programing device

    From this sample I will be able to complete my project.

    Greetings

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Expert please HELP

    Quote Originally Posted by VB Client/Server
    This sample code will help me.

    1.Load any binary file (example 10 kb)
    VB Code:
    1. Dim strBuff As String
    2.  
    3.   Open strFileName For Binary As #1
    4.   strBuff = Space(Lof(1))
    5.   Get #1, , strBuff
    6.   Close #1
    2.Read first 15 bytes from file and put him in text box
    VB Code:
    1. Text1.Text = Left$(strBuff, 15)
    3.Then skip (example) 40 bytes and select 10 bytes afther that then show them in text 2
    VB Code:
    1. Text2.Text = Mid$(strBuff,56,10)
    4.create ini file with (text1 and text2) from this file I will use settings for programing device
    Search the site for Ini file handling. There are many threads showing various methods to use.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Expert please HELP

    Great
    This is what I need, thanx Al42.
    Let's make code now...

    Greetings,

    VB Client/Server

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Expert please HELP

    OK, code working BUT!
    When I load my binary file I can't see Info that I need.
    I need convert it to hex but only to be able read info from that file.
    When I see info, I need to send it as binary.

    Private Sub Command1_Click()
    cdlg.DialogTitle = "Select new ( BIN )..."
    cdlg.Filter = "TST_UPD (*.bin)|*.bin|All Files (*.*)|*.*"
    cdlg.InitDir = App.Path
    cdlg.FileName = ""
    cdlg.ShowOpen

    If cdlg.FileName <> "" Then Count (cdlg.FileName)
    End Sub

    Function Count(strFilename)
    Dim strBuff As String
    Open strFilename For Binary As #1

    strBuff = Space(LOF(1))
    Get #1, , strBuff
    Close #1

    Text1.Text = Left$(strBuff, 30)
    Text2.Text = Mid$(strBuff, 1024, 20)
    End Function

    This is OK, but when I load file i dont get in 1 txt box nothing and second is
    ?&/()=!"}§<>><§}{@´´˙`˛°˘^¨¸˝´˙`˛°

    How to get HEX value in text boxes?

    Here is small bin file...
    Rename txt to bin
    When U open file with HEX Editor U will see info what I need in my txt boxes.

    0012E83B000300....

    Best Regards,
    VB Client/Server
    Attached Files Attached Files

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Expert please HELP

    Here is another code, show me HEX but only 1 character, WHY?

    Private Sub Command1_Click()
    cdlg.DialogTitle = "Select new ( UPD.bin)..."
    cdlg.Filter = "UPD_BIN (*.bin)|*.bin|Svi Podaci (*.*)|*.*"
    cdlg.InitDir = App.Path
    cdlg.FileName = ""
    cdlg.ShowOpen

    If cdlg.FileName <> "" Then Count (cdlg.FileName)
    End Sub

    Function Count(strFilename)
    Dim strMyByte As String
    Dim ascMyByte As Integer
    Dim strHEXMyByte As String

    Dim strBuff As String
    Open strFilename For Binary As #1

    strBuff = Space(LOF(1))
    Get #1, , strBuff
    Close #1

    'Text1.Text = Left$(strBuff, 200)
    'Text2.Text = Mid$(strBuff, 1024, 20)


    'Get the byte you want to convert
    strMyByte = Mid$(strBuff, 1, 18)
    'then
    ascMyByte = Asc(strMyByte) 'recover the ascii value
    'and
    strHEXMyByte = Hex$(ascMyByte) 'create the hex value

    'if hex is a single byte (value 0 to 15), add a preceding "0"
    If Len(strHEXMyByte) = 1 Then strHEXMyByte = "0" & strHEXMyByte

    'display the results
    Text1.Text = Str$(ascMyByte)
    Text2.Text = strHEXMyByte
    End Function


    ?

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Expert please HELP

    You have to convert ech btye in the buffer into 2 hex characters (using the code you posted in post #8), add it to the tex box, then go back and convert the next byte, etc., until the end of the buffer. Use a For ... Next loop, going from 1 to Len(strBuff), using Mid$(strBuff, <loop counter>, 1) to get each byte.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Expert please HELP

    Thanx for help Al42,

    but I have already make my soft work in another way.
    I have split all blocks in separate files, rename it like this:
    suk_HOT-BLOCK-1-17259-041A-1-000000.bin
    suk_HOT-BLOCK-2-16430-800E-1-007FF6.bin
    suk_HOT-BLOCK-3-17143-1873-1-00FFEC.bin etc.

    So now I know number of block, filesize in bytes, checksum of block
    and start address.

    Now mscomm problems comes
    Programming device...

    B.R
    VB Client/Server
    Last edited by VB Client/Server; Jun 26th, 2006 at 04:50 PM.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Expert please HELP

    There are many examples of using MSCOMM here, and the help in the help file has a usable example.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    282

    Re: Expert please HELP

    Now i cant get code to know when device is ready for programming
    I need to receive some data from device to know that is connected
    When I switch ON device I get "5A" as a response

    Here is code:



    Private Sub Command1_Click()
    Timer1.Enabled = True

    End Sub

    Private Sub Form_Load()
    With MSComm1
    .CommPort = 1
    .Handshaking = comNone
    .RThreshold = 1
    .RTSEnable = True
    .DTREnable = True
    .Settings = "9600,n,8,1"
    .SThreshold = 1
    .InputMode = comInputModeBinary
    .InputLen = 1
    .PortOpen = True
    End With
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    Timer1.Enabled = False

    If MSComm1.PortOpen = True Then
    MSComm1.PortOpen = False
    End If



    End Sub

    Private Sub Timer1_Timer()


    On Error GoTo OpenError
    Timer1.Interval = 50

    '*************************************************
    '*Do While MSComm1.......
    '*DoEvents
    '*Do Until MSComm1.Index = Chr$(&H5A)
    '*If MSComm1.Input=chr$(&H5A) Then GoTo OK
    '*Loop
    ' here I need code to determine when device is connected and ready
    ' when I power on device, I get "5A" character
    ' so "5A" means that device is powered ON and ready, programming can start
    ' and i need to remove any other char that might come when port is open
    '*************************************************


    OK:
    Timer1.Enabled = False
    MSComm1.PortOpen = False
    MsgBox "OK"
    Exit Sub

    OpenError:
    MsgBox "Error " & Format$(Err.Number) & _
    ": " & vbCrLf & _
    Err.Description
    Exit Sub
    End Sub

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Expert please HELP

    Try something like this:
    VB Code:
    1. Private Sub MSCom_OnComm()
    2. Dim s As String
    3.  
    4. If MSCom.InBufferCount > 0 Then
    5.   s = MSCom.Input
    6.   If InStr(s, "5A") Then
    7.     'do whatever you need to tell the program that the device is on
    8.   End If
    9. End If
    10.  
    11. End Sub
    MSCom _OnComm fires when the control receives anything, so you don't need the timer.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width