Search the Community

Showing results for tags 'double'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Found 5 results

  1. Dear reader, I am writing a C# program using the library  ‘EasyModbus’ that needs to communicate with Siemens WinCC via the connection type ‘Modicon modbus’ I have written a version using the ‘float’ data type in WinCC and that works perfectly. Here my code fragment: Method to convert ‘double’ to bytes in C#: public static byte[] DoubleToModbusFloat(double value) {     byte[] bytes = new byte[4];     float floatValue = (float)value;     int intValue = BitConverter.ToInt32(BitConverter.GetBytes(floatValue), 0);     bytes[0] = (byte)(intValue >> 24);     bytes[1] = (byte)(intValue >> 16);     bytes[2] = (byte)(intValue >> 8);     bytes[3] = (byte)intValue;     return bytes; } Call of the method and loading of the modbus registers in EasyModbus: Bytes = PublicCode.DoubleToModbusFloat(TmpDbl); int n = (int)ModbusStartAddress + ((i - 1) * 2); mb.ModServer.holdingRegisters[n + 1] = (short)((Bytes[0] << 8) + Bytes[1]); mb.ModServer.holdingRegisters[n + 2] = (short)((Bytes[2] << 8) + Bytes[3]); So far so good – this works fine. But I also want to be able to use the ‘Double’ data type in WinCC because I sometimes need more precision than the 7 figures of the ‘float’. I thought it would simply be a case of doubling up the code so I wrote: Method to convert ‘double’ to bytes in C#: public static byte[] DoubleToModbusDouble(double value) {     byte[] bytes = new byte[8];     long intValue = BitConverter.ToInt64(BitConverter.GetBytes(value), 0);     bytes[0] = (byte)((intValue >> 56) & 0xff);     bytes[1] = (byte)((intValue >> 48) & 0xff);     bytes[2] = (byte)((intValue >> 40) & 0xff);     bytes[3] = (byte)((intValue >> 32) & 0xff);     bytes[4] = (byte)((intValue >> 24) & 0xff);     bytes[5] = (byte)((intValue >> 16) & 0xff);     bytes[6] = (byte)((intValue >> 8) & 0xff);     bytes[7] = (byte)(intValue & 0xff);     return bytes; } Call of method and loading of the modbus registers in EasyModbus: Bytes = PublicCode.DoubleToModbusDouble(TmpDbl); int n = (int)ModbusStartAddress + ((i - 1) * 4); mb.ModServer.holdingRegisters[n + 1] = (short)((Bytes[0] << 8) + Bytes[1]); mb.ModServer.holdingRegisters[n + 2] = (short)((Bytes[2] << 8) + Bytes[3]); mb.ModServer.holdingRegisters[n + 3] = (short)((Bytes[4] << 8) + Bytes[5]); mb.ModServer.holdingRegisters[n + 4] = (short)((Bytes[6] << 8) + Bytes[7]); However, this code does not work correctly. I have tried all combinations of byte and word reversal, and whatever I do WinCC either displays nonsensical values or ‘####’ showing that it cannot display the value. I have tried reading as much documentation as I can but it still looks to me as if I am doing the right thing. Also, I have downloaded a number of ‘modbus master’ code examples, and they seem to be able to read the ‘Double’ from my program without any issues. In WinCC I also see that there are two types of double – ‘Double’ and ‘+/- Double’ – I am also unsure as to why this is – there is no ‘+/- Float’ data type, which seems inconsistent to me. I am obviously missing something, but cannot seem to discover what exactly. I hope that someone can point me in the right direction as to what I am doing wrong. Please see attached word file for a picture of the configuration of the connection in WinCC.   Thanks in advance for any help !, Dave Long Double trouble.docx
  2. I am working on something different. I have a Signal Speaker that uses binary inputs to play a certain song based on source configuration. I have to send 24v to the inputs of the speaker. I have 5 of them with 30 different configurations. I am currently trying to do this in ladder logic, RSLogix 5000. Steps done. 1. Assigned the 6 outputs tag names. This is so that I can shift the program to other machines if I have to and I just need to change the slot location, or if I have an output go bad I can move it with ease. This works. 2. I  created the 30 lines of  5 columns to match the binary method. This works.    a. I can manually toggle the output to cycle thru the binary table. 3. Currently working on the logic that when a particular alarm is activated... I turn on the outputs needed to match the binary table. The problem is destructive bit reference on the coils.  I was researching some but don't know what direction to go. How can I call the same output on different rungs? I have attached the .L5X to show what I have programmed. 4. I know the first rungs are wrong. That is what I am trying to fix. 5. Would there be a better way to address this, if so how? Any help would be greatly appreciated.     Speaker_Alarm.L5X Speaker_Alarm.L5X
  3. Hello, I am trying to have single press and double press etc. functionality in my PLC program where for example, single press will turn on the motor whereas double press will turn on the motor for 5 seconds. Is it possible to achieve using ladder logic in sysmac studio, if yes, how? Thank you in advance.
  4. Dword to Float on FX3GE

    Hello! I have a float number (HEX: 3CA01D0F) in Big Endian. It's 0.0195451062. I get it from the sensor and store it in a double word variable. Could you help me? How can I convert DWord to Float? If i use DFLT instruction, It treats DWord as an integer (1017126159) and just gives me 1.017126 e+009 Thanks in advance.
  5. Hey everyone first post on here, does anyone know if it is possible to convert a string into a double integer. i am working with a dimensioner and it is sending me its box dimensions in a 12 char string (see attached picture). however i need this data as a double integer (it seems to just take the string length not the string value i have tried both dim_lengh and dim_length.data[0]). i have gotten it down to the point where i have the string split up into the dimensions i need but i dont know how to do the conversion. (box dims for reference are 21 X 15 X 14.8) Thanks in advance, Dr. Brule