ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Mscomm1 buffer problem (https://www.excelbanter.com/excel-programming/384514-mscomm1-buffer-problem.html)

gtslabs

Mscomm1 buffer problem
 
I have the following code that reads a Data Acquisition system. It is
suppose to put the data from CALL 1 into textbox1 and CALL 2 into
textbox2. However they are comming back reversed. I checked my
userform and I have the textboxs labeled correctly (not reversed)

When I comment out either channel it put the data in the correct
textbox.
I eventually need 5 channels. My system will not read all the
channels simultaneously so I have to loop thru each channel to get its
value.
I have tried varying a delay to see if the buffer is getting updated
too fast but I have not had luck with that approach.

I was looking for a feedback to know the buffer is complete before
outputing to the form. I have my bufferlength set to 0 so it brings it
in all at once instead of each bite.

What can I do here to correct this problem?
Thanks in advance.

BTW: Netcomm1.ocx is the free version of MSCOMM1.ocx. The only
difference is the "input" needs the "data" added.


Private Sub CommandButton21_Click() ' Stream Data into Channels

CommandButton21.Enabled = False
CommandButton23.Enabled = True

C1 = True

Do While C1 = True

Buffer1$ = ""
NETComm1.Output = "CALL 1" & Chr(13) ' retrieve reading
from Serial Device
Buffer1$ = Buffer1$ & NETComm1.InputData
TextBox1 = Application.Clean(Buffer1$)
TimedDelay (0.5)

Buffer2$ = ""
NETComm1.Output = "CALL 2" & Chr(13) ' retrieve reading
from Serial Device
Buffer2$ = Buffer2$ & NETComm1.InputData
TextBox2 = Application.Clean(Buffer2$)
TimedDelay (0.5)
Loop
End Sub


joel

Mscomm1 buffer problem
 
In the userform there is a caption and a name. the name needs be changed to
match the code. The name is the first line in the userform properties
windows and is what the code actually uses to identify the userrform. the
caption is just a text string for display puposes only. The name and the
caption can be different.

"gtslabs" wrote:

I have the following code that reads a Data Acquisition system. It is
suppose to put the data from CALL 1 into textbox1 and CALL 2 into
textbox2. However they are comming back reversed. I checked my
userform and I have the textboxs labeled correctly (not reversed)

When I comment out either channel it put the data in the correct
textbox.
I eventually need 5 channels. My system will not read all the
channels simultaneously so I have to loop thru each channel to get its
value.
I have tried varying a delay to see if the buffer is getting updated
too fast but I have not had luck with that approach.

I was looking for a feedback to know the buffer is complete before
outputing to the form. I have my bufferlength set to 0 so it brings it
in all at once instead of each bite.

What can I do here to correct this problem?
Thanks in advance.

BTW: Netcomm1.ocx is the free version of MSCOMM1.ocx. The only
difference is the "input" needs the "data" added.


Private Sub CommandButton21_Click() ' Stream Data into Channels

CommandButton21.Enabled = False
CommandButton23.Enabled = True

C1 = True

Do While C1 = True

Buffer1$ = ""
NETComm1.Output = "CALL 1" & Chr(13) ' retrieve reading
from Serial Device
Buffer1$ = Buffer1$ & NETComm1.InputData
TextBox1 = Application.Clean(Buffer1$)
TimedDelay (0.5)

Buffer2$ = ""
NETComm1.Output = "CALL 2" & Chr(13) ' retrieve reading
from Serial Device
Buffer2$ = Buffer2$ & NETComm1.InputData
TextBox2 = Application.Clean(Buffer2$)
TimedDelay (0.5)
Loop
End Sub



gtslabs

Mscomm1 buffer problem
 
I changed the 2 lines to send to the textbox to read:

UserForm1.TextBox1 = Application.Clean(Buffer1$)
UserForm1.TextBox2 = Application.Clean(Buffer2$)

And I still go the same error.

I am calling the code from a commmandbutton on the userform1


joel

Mscomm1 buffer problem
 
You should have two routines. One to handle each button.

Private Sub CommandButton21_Click() and
Private Sub CommandButton23_Click()

the while should be changed
from
Do While C1 = True
to
Do While C1

there also isn't any condition to exit the while loop. Don't know why you
need to loop. The sub will only get called when the button is clicked unless
you need to read the serial device multiple times.
"gtslabs" wrote:

I changed the 2 lines to send to the textbox to read:

UserForm1.TextBox1 = Application.Clean(Buffer1$)
UserForm1.TextBox2 = Application.Clean(Buffer2$)

And I still go the same error.

I am calling the code from a commmandbutton on the userform1



Tom Ogilvy

Mscomm1 buffer problem
 
Joel,
Those two statements appear functionally equivalent to me
Do While C1 = True

to
Do While C1

what was the significance of this suggestion?

as to looping, It looks like he is starting a loop to query the comm
controls continuously. given that information I don't see where two buttons
would be needed.

to the original poster. Have you tried putting your Timedelay between
issuing the call statement and when you get the input data?

--
Regards,
Tom Ogilvy




"Joel" wrote:

You should have two routines. One to handle each button.

Private Sub CommandButton21_Click() and
Private Sub CommandButton23_Click()

the while should be changed
from
Do While C1 = True
to
Do While C1

there also isn't any condition to exit the while loop. Don't know why you
need to loop. The sub will only get called when the button is clicked unless
you need to read the serial device multiple times.
"gtslabs" wrote:

I changed the 2 lines to send to the textbox to read:

UserForm1.TextBox1 = Application.Clean(Buffer1$)
UserForm1.TextBox2 = Application.Clean(Buffer2$)

And I still go the same error.

I am calling the code from a commmandbutton on the userform1



gtslabs

Mscomm1 buffer problem
 
Yes, that worked Tom, thanks

The C1 was used as a public boolean variable so I can turn off the
continious loop monitor.



All times are GMT +1. The time now is 10:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com