I have scales equipped with RS232 serial port and a Bluetooth transmitter. I made a program in VBA to receive data from the scales. However, lets say out of 10 incoming strings I get 3 distorted. My regular strings look like: "+001500./3 G S". This means 1500.3 grams above zero and the output is stable. But sometimes I get strings separated like "+" or "001500./3" or "G S". When I plug serial cable I have no distortions. Could you please help me out to fix it?
You can't "make a program" using VBA since it is an embedded macro language. Most applications embedding VBA do not come with a licensed COMn: ("serial") port control or library either.
So what application is it that you are automating? Excel? What serial port library are you using?
Your problem stems from the "Packet Fallacy" where you assume that stream-oriented communication paths are message oriented. Correcting for this fallacy is basically the same process no matter what library you use, though the details will vary widely.
Essentially your problem is that depending on how quickly data arrives relative to how quickly your program polls the inbound buffer for data you will grab larger or smaller pieces at a time, sometimes as little as one character at a time. You need to deblock the inbound stream into messages, either by looking for some message delimiter or by message length if messages have a known fixed length.
I have an event: incoming serial data from com port.
Every time my scales send something the event is executed.
The frequency of that messages is about one in every 100 ms.
The problems is when I connect scales via cable I receive correct strings. But when Im using the bluetooth I get strange strings sometimes.
I tried to put incoming data into a text "log" file. And I was surprised because the data was displayed in a right way. Notepad's magic haha.
I dont get why on Incoming data event bluetooth sends me wierd strings and why they are fine in notepad. Every new received string should be stored in a new line in notepad but its not..
My current solution is to exit sub when wierd string arrives and move to the next one. I think that communication is fast enough not to delay sent data.. But I am not shure..