0

I'm creating an iOS app that needs to talk to devices via Modbus. I'm using https://github.com/iUtvikler/ObjectiveLibModbus that has worked well until I needed to handle floats. This CocoaPod is a wrapper for libmodbus (http://libmodbus.org/).

It seems likely that writing and reading floats would be important to do. Has anyone solved this problem? Can anyone point me to the right direction to figure this out?

I have not programmed in C before.

Or does anyone have another library of code to use that can handle reading and writing floats?

Thank you!

Keith Smiley
  • 61,481
  • 12
  • 97
  • 110
ryanmmanalo
  • 101
  • 6
  • One issue is that the floating point formats may be be different between the device and iOS. – zaph Feb 24 '14 at 22:59
  • variable types items like floating point numbers, and integer, are supported in the processor level so all languages support them. – Paulo Feb 24 '14 at 23:08
  • I know that objective c supports floats. I believe this is a modbus communication issue when trying to read and write floats. how is this communication implemented? I have tried tracing the method calls from the cocoapod to libmodbus as well as looking through the libmodbus forums. I am hoping for a working code example that will be able to read/write a floating number to a modbus device – ryanmmanalo Feb 24 '14 at 23:14
  • I am not sure what the bytes are. When using the cocoapod library I was able to read/write bits with not problem. I am also able to read/write integer values. I realized I was reading/writing values wrong when a colleague mentioned it should be floats. When I was writing "148" and reading back "148" I thought it was working fine. I was told however the value being written was actually "10.0000004" I've been trying to look for a code example in libmodbus.org on how the modbus_get_float() method works but I have had no luck. http://libmodbus.org/site_media/html/modbus_get_float.html – ryanmmanalo Feb 25 '14 at 00:52

2 Answers2

0

Objective C supports float :

@property (nonatomic) float x;
@property (nonatomic) float y;

or you can create it in your m file:

 float minValue = [slider minimumValue];
 float maxValue = [slider maximumValue];
 float value = 0.5f;
Paulo
  • 1,245
  • 10
  • 8
  • We know Objective-C handles floats, it is a super-set of "C". The issue is the floats are coming from a device. There are different formats for floats not to mention byte order (big-endian or little-endian). – zaph Feb 25 '14 at 00:10
  • I understand now and from what I understand iPhone is little Endian while the device maybe either, Have you tried to run it without conversion - it will work if the device is also little Endian , if not there are a few codes that will do the conversion see this -> http://stackoverflow.com/questions/19275955/convert-little-endian-to-big-endian?rq=1 – Paulo Feb 25 '14 at 00:32
0

This is implementation specific for modbus as the slave side will have to send the data formatted for a float value. On the master/client side this is achieved by reading/writing two simultaneous registers.

JL272
  • 13
  • 1
  • 3