Problem with Readline - I broke it !
-
Hi - I have a small development app that (used to) talk to a servo on a com port, and get a status reply. I have somehow really fixed it (I tried to simplify the code) - but the symptoms are maddening, and I do not see what I did other than move a readline from a subroutine to be inline with the code. Here is what I have Public ServoCommName As String = "COM4" Public ServoCommSpeed As Integer = 9600 Public ServoCommdataOut As String Public ServoCommDataIn As String Public ServoCommParity As System.IO.Ports.Parity Public ServoCommDataBits As Integer Public ServoCommStopBits As System.IO.Ports.StopBits Public Com2 As SerialPort = My.Computer.Ports.OpenSerialPort(ServoCommName, ServoCommSpeed, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One) Then the subroutine . . . Public Sub GetServoStatus() ' Sends a status request and then gets Status from the Servo serial port. ServoCommdataOut = cstCameraServoAddress & "&R" Call SendSerialData() 'This will return the Firmware Version 'just in case wait 500 ms ' I have tried all sorts of delays . . . it worked before with 500 Call DelayTimer(DelayTime) ServoCommDataIn = Com2.ReadLine() MsgBox("End Read" & DelayTime & ServoCommDataIn) outLabel = "Read Servo" outMessage = ServoCommDataIn Call WriteToLog(outLabel, outMessage) ServoStatusBoxOut = "Ready" ServoStatusBox = ServoStatusBoxOut End Sub Here is the portmonitor recording for this part of the code . . . The response comes in on line 52 and portmon says it is fine ! 32 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_BAUD_RATE slabser1 SUCCESS Rate: 9600 33 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_RTS slabser1 SUCCESS 34 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_DTR slabser1 SUCCESS 35 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_LINE_CONTROL slabser1 SUCCESS StopBits: 1 Parity: NONE WordLength: 8 36 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_CHAR slabser1 SUCCESS EOF:1a ERR:0 BRK:0 EVT:1a XON:11 XOFF:13 37 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_HANDFLOW slabser1 SUCCESS Shake:0 Replace:0 XonLimit:128 XoffLimit:128 38 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_RTS slabser1 SUCCESS 39 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_TIMEOUTS slabser1 SUCCESS RI:-1 RM:-1 RC:-2 WM:0 WC
-
Hi - I have a small development app that (used to) talk to a servo on a com port, and get a status reply. I have somehow really fixed it (I tried to simplify the code) - but the symptoms are maddening, and I do not see what I did other than move a readline from a subroutine to be inline with the code. Here is what I have Public ServoCommName As String = "COM4" Public ServoCommSpeed As Integer = 9600 Public ServoCommdataOut As String Public ServoCommDataIn As String Public ServoCommParity As System.IO.Ports.Parity Public ServoCommDataBits As Integer Public ServoCommStopBits As System.IO.Ports.StopBits Public Com2 As SerialPort = My.Computer.Ports.OpenSerialPort(ServoCommName, ServoCommSpeed, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One) Then the subroutine . . . Public Sub GetServoStatus() ' Sends a status request and then gets Status from the Servo serial port. ServoCommdataOut = cstCameraServoAddress & "&R" Call SendSerialData() 'This will return the Firmware Version 'just in case wait 500 ms ' I have tried all sorts of delays . . . it worked before with 500 Call DelayTimer(DelayTime) ServoCommDataIn = Com2.ReadLine() MsgBox("End Read" & DelayTime & ServoCommDataIn) outLabel = "Read Servo" outMessage = ServoCommDataIn Call WriteToLog(outLabel, outMessage) ServoStatusBoxOut = "Ready" ServoStatusBox = ServoStatusBoxOut End Sub Here is the portmonitor recording for this part of the code . . . The response comes in on line 52 and portmon says it is fine ! 32 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_BAUD_RATE slabser1 SUCCESS Rate: 9600 33 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_RTS slabser1 SUCCESS 34 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_DTR slabser1 SUCCESS 35 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_LINE_CONTROL slabser1 SUCCESS StopBits: 1 Parity: NONE WordLength: 8 36 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_CHAR slabser1 SUCCESS EOF:1a ERR:0 BRK:0 EVT:1a XON:11 XOFF:13 37 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_HANDFLOW slabser1 SUCCESS Shake:0 Replace:0 XonLimit:128 XoffLimit:128 38 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_RTS slabser1 SUCCESS 39 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_TIMEOUTS slabser1 SUCCESS RI:-1 RM:-1 RC:-2 WM:0 WC
-
I'm no expert but you moved a line of code maybe with a cut and paste maybe you got an extra line return in there somewhere. Might be completely silly but the simple things first
Bird with no beak was born to succeed.
Thanks for the response - I have looked pretty carefully but nothing is obvious - the problem seems to be that PortMon sees the string comming in - but the readline(ServoDataIn) statement in the vb code either gets an incomplete transfer or garbage - I am not certain which . . . this is all very slow stuff and not much data is moving . . .