![]() |
Forum Index : Microcontroller and PC projects : Reading Modbus Energy Meter.
Author | Message | ||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Thought I'd start a new thread, not really appropriate to tag it on the end of Modbus CRC. Ok, So I now have this mess of workings and it is returning a result. Just using a hard coded string to request a voltage reading from the meter on address 002. Just not sure if I'm going around in circles converting data from one form to another un-necessarily. Any feedback would be greatly appreciated. Bit I have trouble getting my head around is that the "String" that comes in the com port is really a series of bytes & how I should treat them. Phil. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
A 'string' is only a collection of bytes. In MMBasic, strings can contain any byte value from zero to 255. Internally MMBasic doesn't care. The only difficulty is PRINTing the string that contains non-printable characters. You have solved that by converting to HEX for viewing but that's only for your benefit, not the program. Internally you can stick to strings for storage without any concern. Jim VK7JH MMedit |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Rather Excited that I can now read Volts! Next step is to read the whole damn meter. (And the other two). Phil. |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
Small point and would only go wrong rarely, but after you suck in the chars you could have more than BufLen. Best to set BufLen = len(DataStr) to be sure. --- On a style point, using globals for Response$ and so on will hurt you sooner or later. Instead, pass as a param (to IEEE754 in this case). Also, you may as well get the byte direct from DataStr rather then re-convert from hex. It looks odd to use a $ with Response$ but Str instead with DataStr. I'll leave off anything about explicit typing of variables... John |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
All totally correct John. What I posted above is at this stage raw workings with trial & error bits commented out. Once I've got all the working parts doing their job I'll tidy them up into correctly written functions with better variable usage. Phil. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |