PDA

Click to See Complete Forum and Search --> : MSComm1 wrting data multiple times in the file


hiharsh
Jan 15th, 2008, 01:17 PM
Hi,

I am trying to achieve following on VB 6 using MSComm1

1 ,open comm port set it to 115200,n,8
2,send "reboot" +chr$(13)
3,Now open a file and read data from board
4,once you get particular string (parse) on the serial port
send another command


Private Sub Form_Load() 'on form load set serial port


MSComm1.CommPort = 4
MSComm1.Settings = "115200,N,8,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = True

End Sub



Private Sub Command2_Click()
Dim myval As Variant

Dim nwmess As String

'Dim start As Integer
Dim i As Integer
i = 0

myval = Chr$(13) + "reboot" + Chr$(13) 'send reboot cmd to board
MSComm1.Output = myval
MSComm1.InputLen = 0


Do While (True)
'Do
DoEvents
mess = mess & MSComm1.Input

If InStr(1, mess, "Hit") Then 'search for string "Hit"
Exit Do

Else

Open "C:\TCU52.txt" For Append As #1

'if string is not found write everythg into textfile

Write #1, mess
Close #1
End If

Loop


What i am getting in the text file is unexpected , i get all the data(strings that board sends) multiple times

How should i fix this ?


"I get something like


reboot

Starting pid 85"
"
reboot

Starting pid 851, console /dev/console: '/bin/sh'"
"
reboot

Starting pid 851, console /dev/console: '/bin/sh'
"
"
reboot

Starting pid 851, console /dev/console: '/bin/sh'


B"




# reboot

Starting pid 858, console /dev/console: '/sbin/swapoff'

Starting pid 860, console /dev/console: '/bin/umount'
#
The system is going down NOW !!

The system is going down NOW !!

Sending SIGTERM to all processes.

Sending SIGTERM to all processes.
"
"
reboot

Starting pid 851, console /dev/console: '/bin/sh'


BusyBox v1.1.2 (2007.09.10-16:57+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

# reboot

Starting pid 858, console /dev/console: '/sbin/swapoff'

Starting pid 860, console /dev/console: '/bin/umount'
#
The system is going down NOW !!

The system is going down NOW !!

Sending SIGTERM to all processes.

Sending SIGTERM to all processes.
"
"
reboot

Starting pid 851, console /dev/console: '/bin/sh'



Please stand by while rebooting the system.
Restarting system.

.



U-Boot 1.1.4 (Dec 13 2007 - 14:10:59)

DRAM: 64 MB
Flash: 64 MB
In: serial
Out: serial
Err: serial
"
"
reboot

Starting pid 851, console /dev/console: '/bin/sh'


BusyBox v1.1.2 (2007.09.10-16:57+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

# reboot

Starting pid 858, console /dev/console: '/sbin/swapoff'

Starting pid 860, console /dev/console: '/bin/umount'
#
The system is going down NOW !!

The system is going down NOW !!

Sending SIGTERM to all processes.

Sending SIGTERM to all processes.

Sending SIGKILL to all processe
Please stand by while rebooting the system.

Please stand by while rebooting the system.
Restarting system.

.



U-Boot 1.1.4 (Dec 13 2007 - 14:10:59)

DRAM: 64 MB
Flash: 64 MB
In: serial
Out: serial
Err: serial
"