Link to home
Start Free TrialLog in
Avatar of jfarmer20
jfarmer20

asked on

MSComm Control causing an external software program to crash while communicating with it.

I am using VB 6.0 programming a MSCOMM control running under WINNT OS.  I am Using this program to interface with a external program that develops and sends a file to a solder flow machine.  This machine has three main programs that we run.  I am using a touchscreen computer and writing the code to download the program to the solder machine and also upload the program from the external software program.  When running the following code I get this error msg and the external program shuts down, if i step through the program, it works fine.

Private mnuReceive_Click()
Dim A as integer
If TypePart = 1 then
MSComm3.output = NAME?
loop while MSComm3.InBufferCount = 0
temp = MSComm3.input
temp = Left(temp,4) ' gets the name of the program from the external software
A = 0
Data_DCND(A,0) = temp ' stores the data in an array
do while a< 100
call stepTXT(A)
MSComm3.output = Step
temp = ""
do
doevents
temp = temp & MSComm3.input
Loop until InStr(temp, vbcrlf)
Data_DCND(A + 1,0) = temp
A = A + 1
if temp = "0019000000000000000000000000000000000000" & VbCrLf then
ProgramReceived = 1
msgbox ("Program Received")
exit sub
end if

loop
end if
end sub

Private Sub StepTXT(A as integer)
if A <= 9 then
Step = "Step000" & A
elseif A > 9 and A < 100 then
Step = "Step00" & A
else
Step = "Step0" & A
end if
end sub

What could be causing my problem?
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

The program at the other end is faulty if it crashes with unexpected data.
Your program is full of syntax errors. I'm surprised you can get it to run at all.

Private mnuReceive_Click()
should be
Private Sub mnuReceive_Click()

MSComm3.output = NAME?
quotes missing round string literal

loop while MSComm3.InBufferCount = 0
Missing Do
etc, etc
Avatar of jfarmer20
jfarmer20

ASKER

Sorry about the typing errors.   I did not cut and paste the program, I retyped into the question.  There are not any syntax errors on the program.  What I have noticed is when the program is running, the external software receives multiple commands and does not see the VbCrLf.  (Example:  NAME?NAME?NAME?)
Ar you sending the vbCrLf?  I can't sse it in what you typed.
I did not type in the VbCrLf on the original question, I am sending the VbCrLf along with the data.  I added a sleep function in the program between the writes and reads which helped.  The program will now run but sometimes it will not communicate with the external program.  Still maybe something about the protocol from the external software (Software is called SPA 250-400 which creates and downloads programs to a solder wave machine).  Thanks for the help you have been giving me.

ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't hink I was much help here. Please refund the questioner's points.