@@ -358,43 +358,13 @@ public void Dispose()
358
358
_grps . Clear ( ) ;
359
359
}
360
360
361
- internal string GetErrorString ( byte exception )
362
- {
363
- switch ( exception )
364
- {
365
- case Modbus . excIllegalFunction :
366
- return "Constant for ModbusModbus.exception illegal function." ;
367
- case Modbus . excIllegalDataAdr :
368
- return "Constant for ModbusModbus.exception illegal data address." ;
369
- case Modbus . excIllegalDataVal :
370
- return "Constant for ModbusModbus.exception illegal data value." ;
371
- case Modbus . excSlaveDeviceFailure :
372
- return "Constant for ModbusModbus.exception slave device failure." ;
373
- case Modbus . excAck :
374
- return "Constant for ModbusModbus.exception acknowledge." ;
375
- case Modbus . excSlaveIsBusy :
376
- return "Constant for ModbusModbus.exception slave is busy/booting up." ;
377
- case Modbus . excGatePathUnavailable :
378
- return "Constant for ModbusModbus.exception gate path unavailable." ;
379
- case Modbus . excExceptionNotConnected :
380
- return "Constant for ModbusModbus.exception not connected." ;
381
- case Modbus . excExceptionConnectionLost :
382
- return "Constant for ModbusModbus.exception connection lost." ;
383
- case Modbus . excExceptionTimeout :
384
- return "Constant for ModbusModbus.exception response timeout." ;
385
- case Modbus . excExceptionOffset :
386
- return "Constant for ModbusModbus.exception wrong offset." ;
387
- case Modbus . excSendFailt :
388
- return "Constant for ModbusModbus.exception send failt." ;
389
- }
390
- return string . Empty ;
391
- }
361
+
392
362
393
363
internal void CallException ( int id , byte function , byte exception )
394
364
{
395
365
if ( tcpSynCl == null ) return ;
396
366
if ( OnError != null )
397
- OnError ( this , new IOErrorEventArgs ( GetErrorString ( exception ) ) ) ;
367
+ OnError ( this , new IOErrorEventArgs ( Modbus . GetErrorString ( exception ) ) ) ;
398
368
}
399
369
400
370
public byte [ ] ReadBytes ( DeviceAddress address , ushort size )
@@ -511,42 +481,49 @@ public int WriteBit(DeviceAddress address, bool bit)
511
481
512
482
public int WriteBits ( DeviceAddress address , byte bits )
513
483
{
484
+ if ( address . DBNumber != 3 ) return - 1 ;
514
485
var data = WriteSingleRegister ( address . Area , address . Start , new byte [ ] { bits } ) ;
515
486
return data == null ? - 1 : 0 ;
516
487
}
517
488
518
489
public int WriteInt16 ( DeviceAddress address , short value )
519
490
{
491
+ if ( address . DBNumber != 3 ) return - 1 ;
520
492
var data = WriteSingleRegister ( address . Area , address . Start , BitConverter . GetBytes ( IPAddress . HostToNetworkOrder ( value ) ) ) ;
521
493
return data == null ? - 1 : 0 ;
522
494
}
523
495
524
496
public int WriteUInt16 ( DeviceAddress address , ushort value )
525
497
{
498
+ if ( address . DBNumber != 3 ) return - 1 ;
526
499
var data = WriteSingleRegister ( address . Area , address . Start , BitConverter . GetBytes ( ( ushort ) IPAddress . HostToNetworkOrder ( ( short ) value ) ) ) ;
527
500
return data == null ? - 1 : 0 ;
528
501
}
529
502
530
503
public int WriteUInt32 ( DeviceAddress address , uint value )
531
504
{
505
+ if ( address . DBNumber != 3 ) return - 1 ;
532
506
var data = WriteMultipleRegister ( address . Area , address . Start , BitConverter . GetBytes ( ( uint ) IPAddress . HostToNetworkOrder ( ( int ) value ) ) ) ;
533
507
return data == null ? - 1 : 0 ;
534
508
}
535
509
536
510
public int WriteInt32 ( DeviceAddress address , int value )
537
511
{
512
+ if ( address . DBNumber != 3 ) return - 1 ;
538
513
var data = WriteMultipleRegister ( address . Area , address . Start , BitConverter . GetBytes ( IPAddress . HostToNetworkOrder ( value ) ) ) ;
539
514
return data == null ? - 1 : 0 ;
540
515
}
541
516
542
517
public int WriteFloat ( DeviceAddress address , float value )
543
518
{
519
+ if ( address . DBNumber != 3 ) return - 1 ;
544
520
var data = WriteMultipleRegister ( address . Area , address . Start , BitConverter . GetBytes ( ( int ) value ) ) ;
545
521
return data == null ? - 1 : 0 ;
546
522
}
547
523
548
524
public int WriteString ( DeviceAddress address , string str )
549
525
{
526
+ if ( address . DBNumber != 3 ) return - 1 ;
550
527
var data = WriteMultipleRegister ( address . Area , address . Start , Encoding . ASCII . GetBytes ( str ) ) ;
551
528
return data == null ? - 1 : 0 ;
552
529
}
0 commit comments