Пример #1
0
        public static bool communicateModbus(int comType, int slaveID, int addr, string value)
        {
            // 1 - Read coil | 2 - Write coil | 3 - Write Register
            switch (comType)
            {
            case 1:
            {
                byte[] dest = new byte[1] {
                    0
                };
                WrapperModbus.lib_modbus_read_bits(slaveID, addr, 1, dest);
                if (dest[0] == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            case 2:
            {
                byte[] dest = new byte[1] {
                    0
                };
                if (value == "true")
                {
                    dest[0] = 1;
                }
                else
                {
                    dest[0] = 0;
                }

                WrapperModbus.lib_modbus_write_bits(slaveID, addr, 1, dest);
                return(true);
            }

            case 3:
            {
                ushort[] dest = new ushort[1] {
                    0
                };
                dest[0] = ushort.Parse(value);

                WrapperModbus.lib_modbus_write_registers(slaveID, addr, 1, dest);
                return(true);
            }

            default:
                MessageBox.Show("Error : Modbus fonction miss-used");
                return(false);
            }
        }
Пример #2
0
        public static bool disconnectModbus(string IP, string Port)
        {
            int result;

            result = WrapperModbus.lib_modbus_deconnect();
            if (result == 0)
            {
                Global.modbusConnection_status = false;
                MessageBox.Show("Modbus communication disconnected");
                return(true);
            }
            else
            {
                MessageBox.Show("Failed to disconnect");
                return(false);
            }
        }
Пример #3
0
        // Modbus communication
        public static bool connectModbus(string IP, string Port)
        {
            int result;

            result = WrapperModbus.lib_modbus_connect(IP, Int16.Parse(Port));
            if (result == 0)
            {
                Global.modbusConnection_status = true;
                MessageBox.Show("Modbus communication with the runtime OK");
                return(true);
            }
            else
            {
                MessageBox.Show("Modbus communication failed to connect");
                return(false);
            }
        }