Пример #1
0
        public static void FlowCoefList_Read(UInt16 type, UInt16 len)
        {
            Byte   devaddr = 0x01;                     // 设备地址
            UInt16 regAddr = REG_sysFlowInPressLow;    // 寄存器地址, 2字节
            UInt16 readlen = len;                      // 读N个(数值1-125)寄存器,2字节

            switch (type)
            {
            case 0:
                regAddr = REG_sysFlowInPressLow;                        // 寄存器地址, 2字节
                Modbus.Modbus_Read03Command(devaddr, regAddr, readlen); //
                break;

            case 1:
                regAddr = REG_sysFlowInPressMid;                        // 寄存器地址, 2字节
                Modbus.Modbus_Read03Command(devaddr, regAddr, readlen); //
                break;

            case 2:
                regAddr = REG_sysFlowInPressHigh;                       // 寄存器地址, 2字节
                Modbus.Modbus_Read03Command(devaddr, regAddr, readlen); //
                break;

            default:
                break;
            }
            Modbus.Modbus_Read03Command(devaddr, regAddr, readlen);
        }
Пример #2
0
        public static void FlowCoefOutPress(UInt16 type, UInt32 Val)
        {
            Byte   devaddr  = 0x01;                    // 设备地址
            UInt16 regAddr  = REG_sysFlowOutPressLow;  // 寄存器地址, 2字节
            UInt16 writelen = 1;                       // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[16];
            dat[0] = (UInt16)Val;       // 写一个数据到寄存器,2字节
            switch (type)
            {
            case 0:
                regAddr = REG_sysFlowOutPressLow;                              // 寄存器地址, 2字节
                Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat); //
                break;

            case 1:
                regAddr = REG_sysFlowOutPressMid;                              // 寄存器地址, 2字节
                Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat); //
                break;

            case 2:
                regAddr = REG_sysFlowOutPressHigh;                             // 寄存器地址, 2字节
                Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat); //
                break;

            default:
                break;
            }
        }
Пример #3
0
        public static void FlowCoefSet(UInt16 type, UInt16 point, UInt32 Val)
        {
            Byte   devaddr  = 0x01;                    // 设备地址
            UInt16 regAddr  = REG_sysCoef0_Low;        // 寄存器地址, 2字节
            UInt16 writelen = 1;                       // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[16];
            dat[0] = (UInt16)Val;       // 写一个数据到寄存器,2字节
            if (point >= 13)
            {
                return;    //点无效
            }
            switch (type)
            {
            case 0:
                regAddr = (UInt16)(REG_sysCoef0_Low + point);                      // 寄存器地址, 2字节
                Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat);     //
                break;

            case 1:
                regAddr = (UInt16)(REG_sysCoef0_Mid + point);                      // 寄存器地址, 2字节
                Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat);     //
                break;

            case 2:
                regAddr = (UInt16)(REG_sysCoef0_High + point);                     // 寄存器地址, 2字节
                Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat);     //
                break;

            default:
                break;
            }
        }
Пример #4
0
        public static void FlowSet_FlowValveDefault(UInt32 Val)
        {
            Byte   devaddr = 0x01;                     // 设备地址
            UInt16 regAddr = REG_sysPercentClear_Low;  // 寄存器地址, 2字节

            switch (Val)
            {
            case 0:
                regAddr = REG_sysPercentClear_Low;
                break;

            case 1:
                regAddr = REG_sysPercentClear_Mid;
                break;

            case 2:
                regAddr = REG_sysPercentClear_High;
                break;

            default:
                return;

                break;
            }
            UInt16 writelen = 1;                       // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[16];
            dat[0] = 0;                                                    // 写一个数据到寄存器,2字节
            Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat); //
        }
Пример #5
0
        public static void SyncPressDeviceDateTime()
        {
            Byte   devaddr  = 0x01;                    // 设备地址
            UInt16 regAddr  = REG_sysSyncYear;         // 寄存器地址, 2字节
            UInt16 writelen = 4;                       // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[16];
            UInt16   year = 0, md = 0, wh = 0, ms = 0;
            DateTime dt = DateTime.Now;

            year = (UInt16)dt.Year;
            md   = (UInt16)dt.Month;
            md   = (UInt16)(md << 8);
            md   = (UInt16)(md + dt.Day);

            wh = (UInt16)dt.DayOfWeek;
            wh = (UInt16)(wh << 8);
            wh = (UInt16)(wh + dt.Hour);

            ms = (UInt16)dt.Minute;
            ms = (UInt16)(ms << 8);
            ms = (UInt16)(ms + dt.Second);

            dat[0] = year;   // 写一个数据到寄存器,2字节
            dat[1] = md;     // 写一个数据到寄存器,2字节
            dat[2] = wh;     // 写一个数据到寄存器,2字节
            dat[3] = ms;     // 写一个数据到寄存器,2字节
            Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat);
        }
Пример #6
0
        public static void Flow24HourTable_Read(UInt16 len)
        {
            Byte   devaddr = 0x01;                     // 设备地址
            UInt16 regAddr = REG_sysFlowValid;         // 寄存器地址, 2字节
            UInt16 readlen = len;                      // 读N个(数值1-125)寄存器,2字节

            Modbus.Modbus_Read03Command(devaddr, regAddr, readlen);
        }
Пример #7
0
        public static void ReadPressDeviceID()
        {
            Byte   devaddr = 0x01;                     // 设备地址
            UInt16 regAddr = REG_sysDeviceID_L;        // 寄存器地址, 2字节
            UInt16 readlen = 12;                       // 读N个(数值1-125)寄存器,2字节

            Modbus.Modbus_Read03Command(devaddr, regAddr, readlen);
        }
Пример #8
0
        public static void ReadPressFlowRefreshSumValue()
        {
            Byte   devaddr = 0x01;                    // 设备地址
            UInt16 regAddr = REG_FlowResvSumL;        // 寄存器地址, 2字节
            UInt16 readlen = 4;                       // 读N个(数值1-125)寄存器,2字节

            Modbus.Modbus_Read03Command(devaddr, regAddr, readlen);
        }
Пример #9
0
        public static void FlowInfoConfig_Read(UInt16 len)
        {
            Byte   devaddr = 0x01;                     // 设备地址
            UInt16 regAddr = REG_sysFlowValveMax;      // 寄存器地址, 2字节
            UInt16 readlen = len;                      // 读N个(数值1-125)寄存器,2字节

            Modbus.Modbus_Read03Command(devaddr, regAddr, readlen);
        }
Пример #10
0
        public static void ReadPressPIDParam()
        {
            Byte   devaddr = 0x01;                     // 设备地址
            UInt16 regAddr = REG_sysPID_FenMu;         // 寄存器地址, 2字节
            UInt16 readlen = 13;                       // 读N个(数值1-125)寄存器,2字节

            Modbus.Modbus_Read03Command(devaddr, regAddr, readlen);
        }
Пример #11
0
        public static void ReadPressErrorList(UInt16 len)
        {
            Byte   devaddr = 0x01;                     // 设备地址
            UInt16 regAddr = REG_ErrorPtrSt;           // 寄存器地址, 2字节
            UInt16 readlen = 30;                       // 读N个(数值1-125)寄存器,2字节

            Modbus.Modbus_Read03Command(devaddr, regAddr, readlen);
        }
Пример #12
0
        public static void ReadPressDateTime()
        {
            Byte   devaddr = 0x01;                    // 设备地址
            UInt16 regAddr = REG_sysSyncYear;         // 寄存器地址, 2字节
            UInt16 readlen = 4;                       // 读N个(数值1-125)寄存器,2字节

            Modbus.Modbus_Read03Command(devaddr, regAddr, readlen);
        }
Пример #13
0
        public static void ReadPressUserConfig()
        {
            Byte   devaddr = 0x01;                    // 设备地址
            UInt16 regAddr = REG_sysPressOutObj;      // 寄存器地址, 2字节
            UInt16 readlen = 7;                       // 读N个(数值1-125)寄存器,2字节

            Modbus.Modbus_Read03Command(devaddr, regAddr, readlen);
        }
Пример #14
0
        public static void SetPressErrorListClear(UInt16 Val)
        {
            Byte   devaddr  = 0x01;                    // 设备地址
            UInt16 regAddr  = REG_ErrorClear;          // 寄存器地址, 2字节
            UInt16 writelen = 1;                       // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[16];
            dat[0] = 0;; // (UInt16)Val;       // 写一个数据到寄存器,2字节
            Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat);
        }
Пример #15
0
        public static void SetPresRegisterValue(UInt16 Reg, UInt16 Val)
        {
            Byte   devaddr  = 0x01;                 // 设备地址
            UInt16 regAddr  = Reg;                  // 寄存器地址, 2字节
            UInt16 writelen = 1;                    // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[16];
            dat[0] = (UInt16)Val;       // 写一个数据到寄存器,2字节
            Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat);
        }
Пример #16
0
        public static void FlowSet_sysFlowValveStep(UInt16 Val)
        {
            Byte   devaddr  = 0x01;                    // 设备地址
            UInt16 regAddr  = REG_sysFlowValveStep;    // 寄存器地址, 2字节
            UInt16 writelen = 1;                       // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[16];
            dat[0] = (UInt16)Val;                                          // 写一个数据到寄存器,2字节
            Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat); //
        }
Пример #17
0
        public static void FlowSet24HourTable(UInt16 hour, UInt16 flowVal)
        {
            Byte   devaddr = 0x01;                     // 设备地址
            UInt16 regAddr = REG_sysFlowTable0;        // 寄存器地址, 2字节

            regAddr = (UInt16)(regAddr + hour);
            UInt16 writelen = 1;                       // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[16];
            dat[0] = (UInt16)flowVal;                                      // 写一个数据到寄存器,2字节
            Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat); //
        }
Пример #18
0
        public static void FlowSet_sysFlowRangeMin(UInt32 Val)
        {
            Byte   devaddr  = 0x01;                    // 设备地址
            UInt16 regAddr  = REG_sysFlowRangeMin;     // 寄存器地址, 2字节
            UInt16 writelen = 1;                       // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[16];

            dat[0] = (UInt16)DataTrans.translate_uint32_to_uint16(Val);    // 写一个数据到寄存器,2字节

            Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat); //
        }
Пример #19
0
        public static void FlowSet_sysFlowLimitSum(UInt32 Val)
        {
            Byte   devaddr  = 0x01;                    // 设备地址
            UInt16 regAddr  = REG_sysFlowSumRemainL;   // 寄存器地址, 2字节
            UInt16 writelen = 2;                       // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[16];

            dat[0] = (UInt16)Val;                                          // 写一个数据到寄存器,2字节
            dat[1] = (UInt16)(Val >> 16);                                  // 写一个数据到寄存器,2字节
            Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat); //
        }
Пример #20
0
        public static void FlowSet24HourTableEnable(UInt16 Val)
        {
            Byte   devaddr  = 0x01;                    // 设备地址
            UInt16 regAddr  = REG_sysFlowValid;        // 寄存器地址, 2字节
            UInt16 writelen = 1;                       // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[16];
            dat[0] = (UInt16)Val;       // 写一个数据到寄存器,2字节
            if (dat[0] != 0)            // 0或1
            {
                dat[0] = 1;
            }
            Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat); //
        }
Пример #21
0
        public static void SetPresRegisterBuffer(UInt16 Reg, UInt16 [] Val, UInt16 len)
        {
            if (len > 255)
            {
                return;
            }
            Byte   devaddr  = 0x01;                 // 设备地址
            UInt16 regAddr  = Reg;                  // 寄存器地址, 2字节
            UInt16 writelen = len;                  // 写入N个(数值1-123)寄存器,2字节

            UInt16[] dat = new UInt16[256];
            for (int i = 0; i < writelen; i++)
            {
                dat[i] = Val[i];      // 写一个数据到寄存器,2字节
            }
            Modbus.Modbus_Write10Command(devaddr, regAddr, writelen, dat);
        }
Пример #22
0
 public static UInt16 Modbus_Read03Command(Byte devAddr, UInt16 regAddr, UInt16 regLen)
 {
     Byte[] tmpbuf = new Byte[16];
     tmpbuf[0] = devAddr;                      // 设备地址
     tmpbuf[1] = 0x03;                         // 0x03
                                               // 寄存器起始地址 0000-FFFF
     tmpbuf[2] = (byte)(regAddr >> 8);         // 高地址
     tmpbuf[3] = (byte)(regAddr & 0xFF);       // 低地址
                                               // 读取N(1-125)个寄存器
     tmpbuf[4] = (byte)(regLen >> 8);          // 长度高
     tmpbuf[5] = (byte)(regLen & 0xFF);        // 长度低
     if (regLen > 125)
     {
         return(0);
     }
     Modbus.ModbusSend_WriteCommand(6, tmpbuf);
     return(1);
     // 应答:      01(1字节地址) 03(1字节功能), 02(1字节数据长度字节), 00 00(2字节数据)
     // 错误应答:  01(1字节地址) 83(1字节功能), 01(01/02/03/04 1个字节,错误类型)
     // 必须记录发送命令的地址,否则没有办法区分
 }
Пример #23
0
        public static UInt16 Modbus_Write10Command(Byte devAddr, UInt16 regAddr, UInt16 regLen, UInt16[] dat)
        {
            Byte[] tmpbuf = new Byte[255];
            UInt16 tmpdat;

            tmpbuf[0] = devAddr;                       // 设备地址 地址码, 1字节
            tmpbuf[1] = 0x10;                          // 功能0x10, 1字节
                                                       // 寄存器地址, 2字节
            tmpbuf[2] = (byte)(regAddr >> 8);          // 高地址
            tmpbuf[3] = (byte)(regAddr & 0xFF);        // 低地址

            UInt16 writelen = regLen;                  // 写入N个(数值1-123)寄存器,2字节

            tmpbuf[4] = (byte)(writelen >> 8);         // 长度高
            tmpbuf[5] = (byte)(writelen & 0xFF);       // 长度低

            writelen  = (UInt16)(writelen * 2);        // 写入2*N(数值2-246)个字节, 1字节
            tmpbuf[6] = (byte)(writelen);              // 字节

            UInt16 ptr = 7;

            // 写一个数据到寄存器,2字节
            for (int i = 0; i < regLen; i++)
            {
                tmpdat      = dat[i];
                tmpbuf[ptr] = (byte)(tmpdat >> 8);              // 数据高
                ptr         = (UInt16)(ptr + 1);
                tmpbuf[ptr] = (byte)(tmpdat & 0xFF);            // 数据低
                ptr         = (UInt16)(ptr + 1);
            }

            Modbus.ModbusSend_WriteCommand(ptr, tmpbuf);
            return(1);
            // 应答:      01(1字节地址) 10(1字节功能), XXXX(2字节,寄存器始地址), 00 00(2字节,寄存器长度)
            // 错误应答:  01(1字节地址) 90(1字节功能), 01(01/02/03/04 1个字节,错误类型)
            // 必须记录发送命令的地址,否则没有办法区分
        }