File transfer via serial port - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

File transfer via serial port

rickratrickrat Posts: 55Member
Hey,

I am trying to send files via the comm port. I am able to do so w/ text files, however, i am not able to send executable files. When i tell my program to send an exe file from one computer to another it will copy the file from the first computer to the second but if i open it w/ a hex editor, it will not look anything like the orig. file.

Do you know of a way to copy an exe file via the comm port?

thanks!

Comments

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : Hey,
    :
    : I am trying to send files via the comm port. I am able to do so w/ text files, however, i am not able to send executable files. When i tell my program to send an exe file from one computer to another it will copy the file from the first computer to the second but if i open it w/ a hex editor, it will not look anything like the orig. file.
    :
    : Do you know of a way to copy an exe file via the comm port?
    :
    : thanks!
    :

    What control (Maybe even API) are you using??? Maybe you send it as text, while you should actually send the file as a piece of binary data!

    Greets...
    Richard

  • rickratrickrat Posts: 55Member
    [b][red]This message was edited by rickrat at 2003-8-14 7:52:21[/red][/b][hr]
    [b][red]This message was edited by rickrat at 2003-8-14 7:51:24[/red][/b][hr]
    : : Hey,
    : :
    : : I am trying to send files via the comm port. I am able to do so w/ text files, however, i am not able to send executable files. When i tell my program to send an exe file from one computer to another it will copy the file from the first computer to the second but if i open it w/ a hex editor, it will not look anything like the orig. file.
    : :
    : : Do you know of a way to copy an exe file via the comm port?
    : :
    : : thanks!
    : :
    :
    : What control (Maybe even API) are you using??? Maybe you send it as text, while you should actually send the file as a piece of binary data!
    :
    : Greets...
    : Richard
    :
    :
    I'm using the MSComm control, i know i have to open the exe file in binary, at least i think i have to, but i am not quite sure as to how to do that. I think one of the problems that i am getting is that when i open the code on the first computer before it is sent over, it is not opening correctly.
    Right now i am using this code just to open the program:


    Dim intCounter As Integer, intFile As Integer, Char$
    intFile = FreeFile()
    Open "C:hi.exe" For Binary As intFile
    For intCounter = 1 To LOF(intFile)
    Char$ = Input$(1, #intFile)
    txtInput.Text = txtInput.Text & Char$
    Next
    Close intFile

    Any idea's?

    Also, one thing that you could do as a good example:
    1. Make an executable file that just simply display's a message box to the user and then ends.
    2. Take that file and change it from *.exe to *.txt and open it w/ notepad
    3. copy the contents of the file to another *.txt file and rename the new *.txt file as a *.exe file
    4. you will notice that the program will not run, but will be in the form as a dos prompt, or command prompt

    if i can find a way to copy the contents from one exe file to another i think that will be the answer that i am looking for.



  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : [b][red]This message was edited by rickrat at 2003-8-14 7:52:21[/red][/b][hr]
    : [b][red]This message was edited by rickrat at 2003-8-14 7:51:24[/red][/b][hr]
    : : : Hey,
    : : :
    : : : I am trying to send files via the comm port. I am able to do so w/ text files, however, i am not able to send executable files. When i tell my program to send an exe file from one computer to another it will copy the file from the first computer to the second but if i open it w/ a hex editor, it will not look anything like the orig. file.
    : : :
    : : : Do you know of a way to copy an exe file via the comm port?
    : : :
    : : : thanks!
    : : :
    : :
    : : What control (Maybe even API) are you using??? Maybe you send it as text, while you should actually send the file as a piece of binary data!
    : :
    : : Greets...
    : : Richard
    : :
    : :
    : I'm using the MSComm control, i know i have to open the exe file in binary, at least i think i have to, but i am not quite sure as to how to do that. I think one of the problems that i am getting is that when i open the code on the first computer before it is sent over, it is not opening correctly.
    : Right now i am using this code just to open the program:
    :
    :
    : Dim intCounter As Integer, intFile As Integer, Char$
    : intFile = FreeFile()
    : Open "C:hi.exe" For Binary As intFile
    : For intCounter = 1 To LOF(intFile)
    : Char$ = Input$(1, #intFile)
    : txtInput.Text = txtInput.Text & Char$
    : Next
    : Close intFile
    :
    : Any idea's?
    :
    : Also, one thing that you could do as a good example:
    : 1. Make an executable file that just simply display's a message box to the user and then ends.
    : 2. Take that file and change it from *.exe to *.txt and open it w/ notepad
    : 3. copy the contents of the file to another *.txt file and rename the new *.txt file as a *.exe file
    : 4. you will notice that the program will not run, but will be in the form as a dos prompt, or command prompt
    :
    : if i can find a way to copy the contents from one exe file to another i think that will be the answer that i am looking for.
    :
    :
    :
    :

    That's because EXE files have alot of character 0's in them. A character 0 in a string indicates the end of that string! That can cause confusing situations. You have to open the file in a different way.

    Use:
    [code]
    Dim intCounter As Integer, intFile As Integer
    Dim bytData() As Byte

    intFile = FreeFile()
    Open "C:hi.exe" For Binary As intFile
    ReDim bytData(0 To Len("c:hi.exe") - 1)
    Get intFile, , bytData
    Close intFile
    [/code]

    Now bytData() contains the entire file. Now I don't know the Comm Control, so I don't know how you have to send it over, but now you can just loop trough the array and send each byte individually!

    Let me know what you think...

    Greets...
    Richard

  • johny780johny780 Posts: 1Member
    hi... BitByBit_Thor
    can i have your source code??
    I am trying to send a text file using mscommm control... But i do not know how to do it.... For example: I have a file called ID.txt in c: , how do i send ID.txt through the serial port using mscomm control? Can ya show me a sample code? I need to complete a school project urgently, the submission is in 2 days time. Can u teach me or tell me how to do it???
    Can ya email me with the source code to [email protected] ?
    Thank you very much, hope u will reply me soon....
  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : hi... BitByBit_Thor
    : can i have your source code??
    : I am trying to send a text file using mscommm control... But i do not know how to do it.... For example: I have a file called ID.txt in c: , how do i send ID.txt through the serial port using mscomm control? Can ya show me a sample code? I need to complete a school project urgently, the submission is in 2 days time. Can u teach me or tell me how to do it???
    : Can ya email me with the source code to [email protected] ?
    : Thank you very much, hope u will reply me soon....
    :

    I send you an e-mail. I forgot to add this question: Do you know how to read the file and place the data into a string?

    Greets...
    Richard

  • mrjustmrjust Posts: 1Member
    Hi... BitByBit_Thor
    im working on data tranfer using comm port, and im not able to send file or receive it using comm port to another computer. its a little project in my university, i want u please send to me by e-mail the source of ur work, i need it quickly within these two days, and im very thankful.

    my email is: [email protected]

    Regards


  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : That's because EXE files have alot of character 0's in them. A character 0 in a string indicates the end of that string! That can cause confusing situations. You have to open the file in a different way.
    :

    And because Input generally destroys the data in a file. In text files, you don't notice because it fixes the data by the time you get it. Chr$(0) and either vbCr or vbLf (I forget which of the two) are all reinterpreted as vbCrLf.

    You can also use:

    : [code]
    : Dim intCounter As Integer, intFile As Integer
    : Dim bytData [b]As String[/b]
    :
    : intFile = FreeFile()
    : Open "C:hi.exe" For Binary As intFile
    : bytData [b]= Space(LOF(intFile))[/b]
    : Get intFile, , bytData
    : Close intFile
    : [/code]
    :

    And the [b]Len("C:hi.exe")[/b] should have been [b]LOF(intFile)[/b] or [b]FileLen("C:hi.exe")[/b].

    : Now bytData() contains the entire file. Now I don't know the Comm Control, so I don't know how you have to send it over, but now you can just loop trough the array and send each byte individually!
    :

    I think MSComm will accept either a string or a byte array, because VB will often allow you to substitute one for the other. If it does allow the byte array, I would suggest using it instead of a string as it should be read faster (VB does an internal conversion on strings to unicode).
Sign In or Register to comment.