Hi All,
I am writing an creating an extensive set of tools, to replace and extend upon those I did using VB6 years ago, and work with a specific group of hardware with RS232 interfaces.
The required port parameters for the hardware are: 8 data bits, 1 stop bit, no parity, no flow control. The RTS and DTR lines (or at least one of them) need to be held high to power the device. My code to open the port is:
Most of the communication with the device consists of strings between 1 to 60 characters long. I know what length the returned string will be so here is the code I use to communicate with the device:
The problem with this is that I am getting a 30 millisecond delay or overhead with every send/receive transaction. k& only ever reaches 1 or 2. Some operations require over 10 transactions so the user will be left wondering what is happening. The device itself responds within a couple of ms so I suspect the delay is happening during either the sending or querying the size of the buffer.
My VB code, with either the now useless MSCOMM control or the excellent Marshallsoft serial library, does these transactions almost instantaneously. I would use the Marshallsoft DLL except that I am hoping to
distribute only one DLL for this device.
Can anyone see where I am going wrong?
Thanks and regards,
Rob
I am writing an creating an extensive set of tools, to replace and extend upon those I did using VB6 years ago, and work with a specific group of hardware with RS232 interfaces.
The required port parameters for the hardware are: 8 data bits, 1 stop bit, no parity, no flow control. The RTS and DTR lines (or at least one of them) need to be held high to power the device. My code to open the port is:
Code:
FUNCTION StartComms (PortNo AS LONG) AS LONG LOCAL cPort AS STRING EndComms 'flushes the buffer and calls COMM CLOSE #nComm SLEEP 30 cPort = "COM" & LTRIM$(STR$(PortNo)) COMM OPEN cPort AS #nComm IF ERRCLEAR THEN EXIT FUNCTION ' Exit if port cannot be opened COMM SET #nComm, BAUD = 9600 ' 9600 baud COMM SET #nComm, BYTE = 8 ' 8 bits COMM SET #nComm, PARITY = %False ' No parity COMM SET #nComm, STOP = 0 ' 1 stop bit COMM SET #nComm, TXBUFFER = 1024 ' 4k transmit buffer COMM SET #nComm, RXBUFFER = 1024 ' 4k receive buffer COMM SET #nComm, XINPFLOW = 0 ' Disable Xon Xoff flow control COMM SET #nComm, XOUTFLOW = 0 ' Disable Xon Xoff flow control COMM SET #nComm, RTSFLOW = 1 ' Raise RTS line COMM SET #nComm, CTSFLOW = 0 ' Disable CTS flow control COMM SET #nComm, DTRFLOW = 0 ' Disable DTR flow control COMM SET #nComm, DSRFLOW = 0 ' Disable DSR flow control COMM SET #nComm, DTRLINE = %True ' Raise DTR line SLEEP 50 'allow the device to power up GetLinkType 'query the device type and version IF LCASE$(LEFT$(LinkType,4)) = "link" THEN FUNCTION = %TRUE END FUNCTION
Code:
IF COMM(#nComm, RXQUE) THEN 'flush the buffer COMM RECV #nComm, COMM(#nComm, RXQUE), rStr END IF COMM SEND #nComm, SndString DO UNTIL i& >= numbytes OR k& = 20 'time out after 100 ms k& = k& + 1 SLEEP 5 i& = COMM(#nComm, RXQUE) LOOP COMM RECV #nComm, i&, RcvString
My VB code, with either the now useless MSCOMM control or the excellent Marshallsoft serial library, does these transactions almost instantaneously. I would use the Marshallsoft DLL except that I am hoping to
distribute only one DLL for this device.
Can anyone see where I am going wrong?
Thanks and regards,
Rob
Comment