Forum Discussion
Serial COM Ports in Excel VBA
Hello and thanks for your interest in SerialComms VBA.
You may have a timing problem between VBA and your instrument.
Modern PC is simply far too fast for relatively slow serial ports and attached devices.
Try adding a delay between starting the COM port and sending the Start Sampling command.
Add a second delay between sending the command and waiting for a response.
There's an example function at the end of the listing below which shows how to do that.
Regards,
SerialComms
Regards Andrew Mellon
- Andrew_M395Jan 06, 2024Copper ContributorI have solved this: I needed to add a delay between the open port and transmit in my own subroutine. This despite the fact that the transmit reported sending the data sucessfully. I then went back to the example and invcreased the delay before If Port_Started(Port_Number) Then to 2000 and it worked.
Thanks again for the code.
Regards Andrew M- serialcommsJan 07, 2024Copper Contributor
Hello,
At least one Arduino model (Uno R3) will intentionally reboot when a serial connection is made to it. This may explain the need for a delay after opening the port as you have discovered.
The following Github repository contains a modified version which allows an Arduino serial connection to be made without rebooting it.
Serialcomms/Serial-Ports-in-VBA-Arduino-2023: Arduino R3 serial version (github.com)
There is also a separate function to reboot the Arduino if you need it, and a sample Arduino sketch to send analogue channel values to the serial port.
Note also that the Uno is relatively slow compared to a modern PC which further increases the need for timing delays.
Regards,
Serialcomms.
- Andrew_M395Jan 08, 2024Copper Contributor
serialcomms Thankyou for the help it was useful. I should have realised by Arduino was rebooting on connection. It explains some other things I did not understand happening. First use of Arduino. I will certainly look at the Arduino version.
Thanks Andrew M