pyromatt
asked on
High speed Serial Port output
Hi,
I am writing an application in which i need to output 3 bytes of data to the serial port 20 times a second. I tried to use the MSComm control but it seems to delay the output of the data (presumably because of buffering or something) and can not cope with the speed I require, so i get 'Out of stack space' errors. I am running my port and serial device at 9600baud so I would have thought this would have been fast enough as i should only require 480 baud (3 bytes * 8 bits per byte * 20 times a second = 480.) Is there any way to output the data faster without the delay/buffering using the MSComm control or any other alternative ways of serial port output? Sample code would be great too :)
Thanks,
Matt.
I am writing an application in which i need to output 3 bytes of data to the serial port 20 times a second. I tried to use the MSComm control but it seems to delay the output of the data (presumably because of buffering or something) and can not cope with the speed I require, so i get 'Out of stack space' errors. I am running my port and serial device at 9600baud so I would have thought this would have been fast enough as i should only require 480 baud (3 bytes * 8 bits per byte * 20 times a second = 480.) Is there any way to output the data faster without the delay/buffering using the MSComm control or any other alternative ways of serial port output? Sample code would be great too :)
Thanks,
Matt.
ASKER
Public Function SerOut(PortData As String)
Do
DoEvents 'Prevent 'Port already open' errors
Loop Until frmMain.SerPort.PortOpen = False
frmMain.SerPort.PortOpen = True
frmMain.SerPort.Output = PortData
frmMain.SerPort.PortOpen = False
End Function
PortData always contains 3 characters, and this fuction is used 20 times a second. The serial port however, only manages to output around 2 a second and so after a few seconds i get a stack space error.
Do
DoEvents 'Prevent 'Port already open' errors
Loop Until frmMain.SerPort.PortOpen = False
frmMain.SerPort.PortOpen = True
frmMain.SerPort.Output = PortData
frmMain.SerPort.PortOpen = False
End Function
PortData always contains 3 characters, and this fuction is used 20 times a second. The serial port however, only manages to output around 2 a second and so after a few seconds i get a stack space error.
Why don't you just leave the port open?
ASKER
I thought you had to close the port to send the data? I always thought 'output' just buffers it and it isnt sent until you close it.
ASKER
Doh! Ive found the problem. I forgot to disable DTR and hence having to close the port everytime i need to send data (and hence the slowness)!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
'Out of stack space' is usually caused by a recursive call gone out of control. I can't understand the connection with slow output.
Perhaps you should post your code