Hello I'm having an issue with a serial connection program. It connects a motor controller to a computer via RS232.
Here is the code:
VB Code:
Public Class Form1 Dim COM1 As IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort("COM1", 38400, IO.Ports.Parity.Odd, 7, IO.Ports.StopBits.One) Dim Ring_Vel As Integer = 1 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'First run setup COM1.WriteLine("1PW" & vbCr & vbCr) COM1.WriteLine("1RSF" & vbCr) COM1.WriteLine("1AC=100000" & vbCr) COM1.WriteLine("1VL=" & Ring_Vel & vbCr) VScrollBar1.Value = Ring_Vel Label3.Text = Ring_Vel End Sub Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll 'Speed Controller Ring_Vel = VScrollBar1.Value * 1000 COM1.WriteLine("1VL=" & Ring_Vel & vbCr) If Button1.Enabled = False Then COM1.WriteLine("1RFN" & vbCr) Label3.Text = VScrollBar1.Value End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Start Button Button1.Enabled = False Button2.Enabled = True COM1.WriteLine("1RFN" & vbCr) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Stop Button Button1.Enabled = True Button2.Enabled = False COM1.WriteLine("1ST" & vbCr) End Sub End Class
If I change the VScroll1 quickly and often I get this error:
The I/O operation has been aborted because of either a thread exit or an application request.
Why is it doing this? I tried to put the COM1.WriteLine on a timer (.5 sec) so it doesnt overload the buffers or something. And it will still do it.
I dont understand bc I have another program that has a loop, and every cycle of the loop it sends something to the unit. It was able to reach nearly 30 sends per second.




Reply With Quote