diff --git a/.gitignore b/.gitignore
index 88fd331..bc96eec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ composer.lock
.idea/
*~
+/report
\ No newline at end of file
diff --git a/composer.json b/composer.json
index b44d7a1..d52d076 100644
--- a/composer.json
+++ b/composer.json
@@ -7,6 +7,12 @@
"php": "^5.3.2 || ^7.0",
"ext-sockets": "*"
},
+ "require-dev": {
+ "react/socket": "~0.4.0",
+ "react/child-process": "^0.4.1",
+ "react/datagram": "^1.1",
+ "phpunit/phpunit": "^5.6"
+ },
"authors": [
{
"name": "Honza Krakora",
@@ -21,5 +27,10 @@
"psr-4": {
"PHPModbus\\": "src/"
}
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "Tests\\": "tests/"
+ }
}
}
diff --git a/examples/README.md b/examples/README.md
index f3e0c3b..b4b8c0c 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -1,3 +1 @@
-Those examples have not been updated to use namespaces.
-
-They may not work. Just for reference.
+Do not expose this folder publicly as you read/write modbus data with query parameters
diff --git a/examples/example_750841_Mmemory.php b/examples/example_750841_Mmemory.php
index 452b801..6fa8f90 100644
--- a/examples/example_750841_Mmemory.php
+++ b/examples/example_750841_Mmemory.php
@@ -1,65 +1,74 @@
readMultipleRegisters($moduleId, $reference, $quantity);
+ // FC 3
+ $recData = $modbus->readMultipleRegisters($unitId, $reference, $quantity);
} catch (Exception $e) {
- echo $modbus;
- echo $e;
- exit;
+ echo $modbus;
+ echo $e;
+ exit;
}
?>
-
-
-
- WAGO 750-841 M-memory dump
-
-
- Dump of M-memory from WAGO 750-84x series coupler.
-
- - PLC: 750-84x series
- - IP:
- - Modbus module ID:
- - Modbus memory reference:
- - Modbus memory quantity:
-
-
- M-memory dump
+
+
+
+ WAGO 750-841 M-memory dump
+
+
+Dump of M-memory from WAGO 750-84x series coupler.
+
+ - PLC: 750-84x series
+ - IP:
+ - Modbus module ID:
+ - Modbus memory reference:
+ - Modbus memory quantity:
+
-
-
- Modbus address |
- MWx |
- value |
-
-
-
- |
- MW |
- |
-
-
-
+M-memory dump
- Modbus class status
+
+
+ WORD address |
+ Int16 |
+ UInt16 |
+ high byte |
+ low byte |
+ high bits |
+ low bits |
+
+
+
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+
+
+
- = $modbus ?>
+Modbus class status
-
+= $modbus ?>
+Data
+= print_r($recData); ?>
+
diff --git a/examples/example_datatype.php b/examples/example_datatype.php
index 86fa4dc..aeb0a7b 100644
--- a/examples/example_datatype.php
+++ b/examples/example_datatype.php
@@ -1,20 +1,23 @@
readMultipleRegisters(0, 12288, 10);
+ // FC 3
+ // read 10 words (20 bytes) from device ID=0, address=12288
+ $recData = $modbus->readMultipleRegisters($unitId, $reference, $quantity);
} catch (Exception $e) {
- // Print error information if any
- echo $modbus;
- echo $e;
- exit;
+ // Print error information if any
+ echo $modbus;
+ echo $e;
+ exit;
}
// Received data
@@ -29,17 +32,17 @@ $values = array_chunk($recData, 4);
// Get float from REAL interpretation
echo "REAL to Float
\n";
foreach ($values as $bytes)
- echo PhpType::bytes2float($bytes) . "";
+ echo PhpType::bytes2float($bytes) . "";
// Get integer from DINT interpretation
echo "DINT to integer
\n";
foreach ($values as $bytes)
- echo PhpType::bytes2signedInt($bytes) . "";
+ echo PhpType::bytes2signedInt($bytes) . "";
// Get integer of float from DINT interpretation
echo "DWORD to integer (or float)
\n";
foreach ($values as $bytes)
- echo PhpType::bytes2unsignedInt($bytes) . "";
+ echo PhpType::bytes2unsignedInt($bytes) . "";
echo "16 bit types
\n";
// Chunk the data array to set of 4 bytes
@@ -48,12 +51,12 @@ $values = array_chunk($recData, 2);
// Get signed integer from INT interpretation
echo "INT to integer
\n";
foreach ($values as $bytes)
- echo PhpType::bytes2signedInt($bytes) . "";
+ echo PhpType::bytes2signedInt($bytes) . "";
// Get unsigned integer from WORD interpretation
echo "WORD to integer
\n";
foreach ($values as $bytes)
- echo PhpType::bytes2unsignedInt($bytes) . "";
+ echo PhpType::bytes2unsignedInt($bytes) . "";
// Get string from STRING interpretation
echo "STRING to string
\n";
diff --git a/examples/example_fc1.php b/examples/example_fc1.php
index d6c7497..34d7e12 100644
--- a/examples/example_fc1.php
+++ b/examples/example_fc1.php
@@ -2,12 +2,16 @@
use PHPModbus\ModbusMaster;
-// Create Modbus object
-$modbus = new ModbusMaster("192.192.15.51", "UDP");
+$ip = filter_var($_GET['ip'], FILTER_VALIDATE_IP) ? $_GET['ip'] : '192.192.15.51';
+$unitId = ((int)$_GET['unitid']) ?: 0;
+$reference = ((int)$_GET['reference']) ?: 12288;
+$quantity = ((int)$_GET['quantity']) ?: 12;
+
+$modbus = new ModbusMaster($ip, 'UDP');
try {
// FC 1
- $recData = $modbus->readCoils(0, 12288, 12);
+ $recData = $modbus->readCoils($unitId, $reference, $quantity);
} catch (Exception $e) {
// Print error information if any
echo $modbus;
@@ -15,10 +19,9 @@ try {
exit;
}
-// Print status information
-echo "Status:" . $modbus;
-
-// Print read data
-echo "Data:";
-var_dump($recData);
-echo "";
+echo 'Status
';
+print_r($modbus);
+echo '
';
+echo 'Data
';
+print_r($recData);
+echo '
';
diff --git a/examples/example_fc15.php b/examples/example_fc15.php
index 23de38b..ced94a6 100644
--- a/examples/example_fc15.php
+++ b/examples/example_fc15.php
@@ -1,27 +1,33 @@
writeMultipleCoils(0, 12288, $data);
+ // FC15
+ $recData = $modbus->writeMultipleCoils($unitId, $reference, $data);
} catch (Exception $e) {
- // Print error information if any
- echo $modbus;
- echo $e;
- exit;
+ // Print error information if any
+ echo $modbus;
+ echo $e;
+ exit;
}
-// Print status information
-echo $modbus;
+echo 'Status
';
+print_r($modbus);
+echo '
';
+echo 'Data
';
+print_r($recData);
+echo '
';
\ No newline at end of file
diff --git a/examples/example_fc16.php b/examples/example_fc16.php
index 1bff6f2..1cd8e49 100644
--- a/examples/example_fc16.php
+++ b/examples/example_fc16.php
@@ -1,25 +1,29 @@
writeMultipleRegister(0, 12288, $data, $dataTypes);
+ // FC16
+ $recData = $modbus->writeMultipleRegister($unitId, $reference, $data, $dataTypes);
} catch (Exception $e) {
- // Print error information if any
- echo $modbus;
- echo $e;
- exit;
+ // Print error information if any
+ echo $modbus;
+ echo $e;
+ exit;
}
-// Print status information
-echo $modbus;
-
-?>
+echo 'Status
';
+print_r($modbus);
+echo '
';
+echo 'Data
';
+print_r($recData);
+echo '
';
\ No newline at end of file
diff --git a/examples/example_fc2.php b/examples/example_fc2.php
index 1563938..d91c550 100644
--- a/examples/example_fc2.php
+++ b/examples/example_fc2.php
@@ -2,24 +2,27 @@
use PHPModbus\ModbusMaster;
-// Create Modbus object
-$modbus = new ModbusMaster("192.192.15.51", "UDP");
+$ip = filter_var($_GET['ip'], FILTER_VALIDATE_IP) ? $_GET['ip'] : '192.192.15.51';
+$unitId = ((int)$_GET['unitid']) ?: 0;
+$reference = ((int)$_GET['reference']) ?: 0;
+$quantity = ((int)$_GET['quantity']) ?: 2;
+
+$modbus = new ModbusMaster($ip, 'UDP');
try {
- // FC 2
- // read 2 input bits from address 0x0 (Wago input image)
- $recData = $modbus->readInputDiscretes(0, 0, 2);
+ // FC 2
+ // read 2 input bits from address 0x0 (Wago input image)
+ $recData = $modbus->readInputDiscretes($unitId, $reference, $quantity);
} catch (Exception $e) {
- // Print error information if any
- echo $modbus;
- echo $e;
- exit;
+ // Print error information if any
+ echo $modbus;
+ echo $e;
+ exit;
}
-// Print status information
-echo "Status:" . $modbus;
-
-// Print read data
-echo "Data:";
-var_dump($recData);
-echo "";
+echo 'Status
';
+print_r($modbus);
+echo '
';
+echo 'Data
';
+print_r($recData);
+echo '
';
\ No newline at end of file
diff --git a/examples/example_fc22.php b/examples/example_fc22.php
index 34ccd2e..28ca792 100644
--- a/examples/example_fc22.php
+++ b/examples/example_fc22.php
@@ -1,9 +1,11 @@
maskWriteRegister(0, 12288, $andMask, $orMask);
+ $recData = $modbus->maskWriteRegister($unitId, $reference, $andMask, $orMask);
} catch (Exception $e) {
// Print error information if any
echo $modbus;
@@ -21,5 +23,9 @@ try {
exit;
}
-// Print status information
-echo $modbus;
+echo 'Status
';
+print_r($modbus);
+echo '
';
+echo 'Data
';
+print_r($recData);
+echo '
';
\ No newline at end of file
diff --git a/examples/example_fc23.php b/examples/example_fc23.php
index 0fa0ebe..a21aea4 100644
--- a/examples/example_fc23.php
+++ b/examples/example_fc23.php
@@ -1,28 +1,30 @@
readWriteRegisters(0, 12288, 6, 12288, $data, $dataTypes);
+ // FC23
+ $recData = $modbus->readWriteRegisters($unitId, $reference, $quantity, $reference, $data, $dataTypes);
} catch (Exception $e) {
- // Print error information if any
- echo $modbus;
- echo $e;
- exit;
+ // Print error information if any
+ echo $modbus;
+ echo $e;
+ exit;
}
-// Print status information
-echo "Status:" . $modbus;
-
-// Print read data
-echo "Data:";
+echo 'Status
';
+print_r($modbus);
+echo '
';
+echo 'Data
';
print_r($recData);
-echo "";
+echo '
';
\ No newline at end of file
diff --git a/examples/example_fc3.php b/examples/example_fc3.php
index 859e1c0..d3d12bd 100644
--- a/examples/example_fc3.php
+++ b/examples/example_fc3.php
@@ -2,23 +2,26 @@
use PHPModbus\ModbusMaster;
-// Create Modbus object
-$modbus = new ModbusMaster("192.192.15.51", "UDP");
+$ip = filter_var($_GET['ip'], FILTER_VALIDATE_IP) ? $_GET['ip'] : '192.192.15.51';
+$unitId = ((int)$_GET['unitid']) ?: 0;
+$reference = ((int)$_GET['reference']) ?: 12288;
+$quantity = ((int)$_GET['quantity']) ?: 6;
+
+$modbus = new ModbusMaster($ip, 'UDP');
try {
- // FC 3
- $recData = $modbus->readMultipleRegisters(0, 12288, 6);
+ // FC 3
+ $recData = $modbus->readMultipleRegisters($unitId, $reference, $quantity);
} catch (Exception $e) {
- // Print error information if any
- echo $modbus;
- echo $e;
- exit;
+ // Print error information if any
+ echo $modbus;
+ echo $e;
+ exit;
}
-// Print status information
-echo "Status:" . $modbus;
-
-// Print read data
-echo "Data:";
+echo 'Status
';
+print_r($modbus);
+echo '
';
+echo 'Data
';
print_r($recData);
-echo "";
+echo '
';
\ No newline at end of file
diff --git a/examples/example_fc4.php b/examples/example_fc4.php
index 94478c6..eefa528 100644
--- a/examples/example_fc4.php
+++ b/examples/example_fc4.php
@@ -1,13 +1,16 @@
readMultipleInputRegisters(0, 0, 2);
+ $recData = $modbus->readMultipleInputRegisters($unitId, $reference, $quantity);
} catch (Exception $e) {
// Print error information if any
echo $modbus;
@@ -15,4 +18,9 @@ try {
exit;
}
-var_dump($recData);
+echo 'Status
';
+print_r($modbus);
+echo '
';
+echo 'Data
';
+print_r($recData);
+echo '
';
\ No newline at end of file
diff --git a/examples/example_fc5.php b/examples/example_fc5.php
index 7f47680..151aa4e 100644
--- a/examples/example_fc5.php
+++ b/examples/example_fc5.php
@@ -1,23 +1,26 @@
writeSingleCoil(0, 12288, $data_true);
- $modbus->writeSingleCoil(0, 12289, $data_false);
- $modbus->writeSingleCoil(0, 12290, $data_true);
- $modbus->writeSingleCoil(0, 12291, $data_false);
+ // Write single coil - FC5
+ $recData = $modbus->writeSingleCoil($unitId, $reference, [$value]);
} catch (Exception $e) {
- // Print error information if any
- echo $modbus;
- echo $e;
- exit;
+ // Print error information if any
+ echo $modbus;
+ echo $e;
+ exit;
}
+
+echo 'Status
';
+print_r($modbus);
+echo '
';
+echo 'Data
';
+print_r($recData);
+echo '
';
diff --git a/examples/example_fc6.php b/examples/example_fc6.php
index 1d7c733..50e5985 100644
--- a/examples/example_fc6.php
+++ b/examples/example_fc6.php
@@ -1,22 +1,26 @@
writeSingleRegister(0, 12288, $data);
+ // FC6
+ $recData = $modbus->writeSingleRegister($unitId, $reference, [$value]);
} catch (Exception $e) {
- // Print error information if any
- echo $modbus;
- echo $e;
- exit;
+ // Print error information if any
+ echo $modbus;
+ echo $e;
+ exit;
}
-// Print status information
-echo $modbus;
+echo 'Status
';
+print_r($modbus);
+echo '
';
+echo 'Data
';
+print_r($recData);
+echo '
';
\ No newline at end of file
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..fb3d442
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,34 @@
+
+
+
+ ./tests/*
+
+
+
+
+
+
+
+
+
+ src
+
+
+
diff --git a/tests/Codesys/TEST.EXP b/tests/Codesys/TEST.EXP
deleted file mode 100644
index 3e6f226..0000000
--- a/tests/Codesys/TEST.EXP
+++ /dev/null
@@ -1,256 +0,0 @@
-
-
-(* @NESTEDCOMMENTS := 'Yes' *)
-(* @PATH := '' *)
-(* @OBJECTFLAGS := '0, 8' *)
-(* @SYMFILEFLAGS := '2048' *)
-PROGRAM PLC_PRG
-VAR
- (* BOOL, COIL *)
- COIL1 AT %MX0.0 : BOOL := 0;
- COIL2 AT %MX0.1 : BOOL := 0;
- COIL3 AT %MX0.2 : BOOL := 0;
- COIL4 AT %MX0.3 : BOOL := 0;
- COIL5 AT %MX0.4 : BOOL := 0;
- COIL6 AT %MX0.5 : BOOL := 0;
- COIL7 AT %MX0.6 : BOOL := 0;
- COIL8 AT %MX0.7 : BOOL := 0;
-
- (* BYTE *)
- BYTE1 AT %MB0 : BYTE := 0;
- BYTE2 AT %MB1 : BYTE := 0;
- BYTE3 AT %MB2 : BYTE := 0;
- BYTE4 AT %MB3 : BYTE := 0;
- BYTE5 AT %MB4 : BYTE := 0;
-
- (* INT *)
- INT1 AT %MW0 : INT := 0;
- INT2 AT %MW1 : INT := 0;
- INT3 AT %MW2 : INT := 0;
- INT4 AT %MW3 : INT := 0;
- INT5 AT %MW4 : INT := 0;
-
- (* WORD *)
- WORD1 AT %MW0 : WORD := 0;
- WORD2 AT %MW1 : WORD := 0;
- WORD3 AT %MW2 : WORD := 0;
- WORD4 AT %MW3 : WORD := 0;
- WORD5 AT %MW4 : WORD := 0;
-
- (* DINT *)
- DINT1 AT %MD0 : DINT := 0;
- DINT2 AT %MD1 : DINT := 0;
- DINT3 AT %MD2 : DINT := 0;
- DINT4 AT %MD3 : DINT := 0;
- DINT5 AT %MD4 : DINT := 0;
-
- (* DWORD *)
- DWORD1 AT %MD0 : DWORD := 0;
- DWORD2 AT %MD1 : DWORD := 0;
- DWORD3 AT %MD2 : DWORD := 0;
- DWORD4 AT %MD3 : DWORD := 0;
- DWORD5 AT %MD4 : DWORD := 0;
-
- (* REAL *)
- REAL1 AT %MD0 : REAL := 0;
- REAL2 AT %MD1 : REAL := 0;
- REAL3 AT %MD2 : REAL := 0;
- REAL4 AT %MD3 : REAL := 0;
- REAL5 AT %MD4 : REAL := 0;
-
- (* String *)
- STRING1 AT %MW0 : STRING := 'Hello word!!!';
-END_VAR
-
-(* @END_DECLARATION := '0' *)
-(* Something to do *)
-;
-END_PROGRAM
-
-(* @NESTEDCOMMENTS := 'Yes' *)
-(* @GLOBAL_VARIABLE_LIST := 'Global_Variables' *)
-(* @PATH := '' *)
-(* @OBJECTFLAGS := '0, 8' *)
-(* @SYMFILEFLAGS := '2048' *)
-VAR_GLOBAL
-END_VAR
-
-(* @OBJECT_END := 'Global_Variables' *)
-(* @CONNECTIONS := Global_Variables
-FILENAME : ''
-FILETIME : 0
-EXPORT : 0
-NUMOFCONNECTIONS : 0
-*)
-
-(* @NESTEDCOMMENTS := 'Yes' *)
-(* @GLOBAL_VARIABLE_LIST := 'Variable_Configuration' *)
-(* @PATH := '' *)
-(* @OBJECTFLAGS := '0, 8' *)
-(* @SYMFILEFLAGS := '2048' *)
-VAR_CONFIG
-END_VAR
-
-(* @OBJECT_END := 'Variable_Configuration' *)
-(* @CONNECTIONS := Variable_Configuration
-FILENAME : ''
-FILETIME : 0
-EXPORT : 0
-NUMOFCONNECTIONS : 0
-*)
-
-
-_ALARMCONFIG
-_ALARMCONFIGNEXTTEXTID : 10002
-_ALARMCONFIGFORMATS : 'HH$':$'mm$':$'ss','dd$'-$'MM$'-$'yyyy'
-_ALARMCLASSLIST : 1
-_ALARMCLASSID : 0
-_ALARMCLASSACKTYPE : 0
-_ALARMCLASSNAME : 'DEFAULT'
-_ALARMCLASSDESCRIPTION : ''
-_ALARMCLASSBGCOLORS : 16777215,16777215,16777215
-_ALARMCLASSTEXTCOLORS : 3394560,255,16711680
-_ALARMCLASSBITMAPS : '','',''
-_ALARMACTIONLIST : 0
-(* @ALARMCLASSRESETCOLORS := '_ALARMCLASSRESETCOLORS: 33023,16777215' *)
-(* @ALARMCLASSRESETBITMAP := '_ALARMCLASSRESETBITMAP: $'$'' *)
-_ALARMGROUPLISTNAME : 'System'
-_ALARMGROUPPATH : 'System'
-_ALARMGROUPLIST : 0
-_VISUALSETTINGSFLAGS : 0,0,0,0
-_VISUALSETTINGSFLAGS : '','',''
-_VISUALSETTINGSDYNTEXTFILECOUNT : 0
-
-(* @ALARMCONFIGFLAGS := '_ALARMCONFIGFLAGS: 0' *)
-(* @ALARMCONFIGGLOBALDB_STR := '_ALARMCONFIGGLOBALDB_STRINGS: $'$',$'$',$'$',$'$'' *)
-(* @ALARMCONFIGGLOBALDB_NUM := '_ALARMCONFIGGLOBALDB_NUMBERS: 0,0' *)
-_END_ALARMCONFIG
-
-
-LIBRARY
-Standard.lib 2.12.10 14:48:34
-(* @LIBRARYSYMFILEINFO := '0' *)
-NumOfPOUs: 26
-ASCIIBYTE_TO_STRING: 2048
-CONCAT: 0
-CTD: 0
-CTU: 0
-CTUD: 0
-DELETE: 0
-F_TRIG: 0
-FIND: 0
-INSERT: 0
-LEFT: 0
-LEN: 0
-MID: 0
-R_TRIG: 0
-REAL_STATE: 2048
-REPLACE: 0
-RIGHT: 0
-RS: 0
-RTC: 0
-SEMA: 0
-SR: 0
-STANDARD_VERSION: 2048
-STRING_COMPARE: 2048
-STRING_TO_ASCIIBYTE: 2048
-TOF: 0
-TON: 0
-TP: 0
-NumOfGVLs: 1
-'Global Variables 0': 0
-END_LIBRARY
-
-LIBRARY
-SYSLIBCALLBACK.LIB 2.12.10 14:48:32
-(* @LIBRARYSYMFILEINFO := '0' *)
-NumOfPOUs: 2
-SysCallbackRegister: 0
-SysCallbackUnregister: 0
-NumOfGVLs: 2
-Globale_Variablen: 0
-Version: 0
-END_LIBRARY
-
-PLC_CONFIGURATION
-_GLOBAL
-_VERSION: 3
-_AUTOADR: 0
-_CHECKADR: 0
-_SAVECONFIGFILESINPROJECT: 0
-_END_GLOBAL
-
-_MODULE: '3S'
-_SECTION_NAME: 'Root'
-_INDEX_IN_PARENT: '-1'
-_MODULE_NAME: 'Hardware configuration'
-_NODE_ID: -1
-_IECIN: %IB0
-_IECOUT: %QB0
-_IECDIAG: %MB0
-_DOWNLOAD: 1
-_EXCLUDEFROMAUTOADR: 0
-_COMMENT: ''
-
-_MODULE: '3S'
-_SECTION_NAME: 'K_Bus'
-_INDEX_IN_PARENT: '1'
-_MODULE_NAME: 'K-Bus'
-_NODE_ID: 0
-_IECIN: %IB0
-_IECOUT: %QB0
-_IECDIAG: %MB0
-_DOWNLOAD: 1
-_EXCLUDEFROMAUTOADR: 0
-_COMMENT: ''
-_END_MODULE
-
-_MODULE: '3S'
-_SECTION_NAME: 'FB_VARS'
-_INDEX_IN_PARENT: '2'
-_MODULE_NAME: 'Fieldbus variables'
-_NODE_ID: 1
-_IECIN: %IB0
-_IECOUT: %QB0
-_IECDIAG: %MB0
-_DOWNLOAD: 1
-_EXCLUDEFROMAUTOADR: 0
-_COMMENT: ''
-_END_MODULE
-_END_MODULE
-PLC_END
-
-
-RESOURCE
-{event_task : 'start','Called when program starts','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,1,11986}
-{event_task : 'stop','Called when program stops','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,2,11986}
-{event_task : 'before_reset','Called before reset takes place','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,3,11986}
-{event_task : 'after_reset','Called after reset took place','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,4,11986}
-{event_task : 'shutdown','Called before shutdown is performed (Firmware update over ethernet)','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,5,11986}
-{event_task : 'excpt_watchdog','Software watchdog of IEC-task expired','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,7,11986}
-{event_task : 'excpt_fieldbus','Fieldbus error','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,9,11986}
-{event_task : 'excpt_ioupdate','KBus error','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,10,11986}
-{event_task : 'excpt_dividebyzero','Division by zero. Only integer operations!','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,18,11986}
-{event_task : 'excpt_noncontinuable','Exception handler','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,20,11986}
-{event_task : 'after_reading_inputs','Called after reading of inputs','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,28,11986}
-{event_task : 'before_writing_outputs','Called before writing of outputs','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,29,11986}
-{event_task : 'debug_loop','Debug loop at breakpoint','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,31,11986}
-{event_task : 'online_change','Is called after CodeInit() at Online-Change','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,33,11986}
-{event_task : 'before_download','Is called before the Download starts','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,34,11986}
-{event_task : 'event_login','Is called before the login service is performed','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,501,11986}
-{event_task : 'eth_overload','Ethernet Overload','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,750,11986}
-{event_task : 'eth_network_ready','Is called directly after the Network and the PLC are initialised','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,751,11986}
-{event_task : 'blink_code','New blink code / Blink code cleared ( Call STATUS_GET_LAST_ERROR for details )','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,752,11986}
-{event_task : 'interrupt_0','Interrupt Real Time Clock (every second)','','FUNCTION systemevent: DWORD VAR_INPUT dwEvent: DWORD; dwFilter: DWORD; dwOwner: DWORD; END_VAR '}{event_task_info : 0,1000,11986}
-
-END_RESOURCE
-
-
-_WORKSPACE
-_GLOBALVISUALSETTINGS
-_VISUALSETTINGSFLAGS : 0,0,0,0
-_VISUALSETTINGSFLAGS : '','',''
-_VISUALSETTINGSDYNTEXTFILECOUNT : 0
-_VISUALBITMAPLISTCOUNT : 0
-_END_GLOBALVISUALSETTINGS
-_END_WORKSPACE
diff --git a/tests/Codesys/_make_exp.cmd b/tests/Codesys/_make_exp.cmd
deleted file mode 100644
index 415af58..0000000
--- a/tests/Codesys/_make_exp.cmd
+++ /dev/null
@@ -1,15 +0,0 @@
-rem Create Codesys EXP file
-
-rem Build cmd file
-set CODESYS="c:\Program Files (x86)\WAGO Software\CoDeSys V2.3\codesys.exe"
-set PROJECT=test
-del %PROJECT%.EXP
-echo file open %PROJECT%.pro >> codesys_cmd_file.cmd
-echo project export %PROJECT%.EXP >> codesys_cmd_file.cmd
-rem echo file saveas %PROJECT%.lib internallib >> codesys_cmd_file.cmd
-echo file close >> codesys_cmd_file.cmd
-echo file quit >> codesys_cmd_file.cmd
-%CODESYS% /noinfo /cmd codesys_cmd_file.cmd
-
-rem Clean all when finished
-del codesys_cmd_file.cmd
\ No newline at end of file
diff --git a/tests/Codesys/test.pro b/tests/Codesys/test.pro
deleted file mode 100644
index 6904c0c..0000000
Binary files a/tests/Codesys/test.pro and /dev/null differ
diff --git a/tests/IecType/IecByteTest.php b/tests/IecType/IecByteTest.php
new file mode 100644
index 0000000..c280ad4
--- /dev/null
+++ b/tests/IecType/IecByteTest.php
@@ -0,0 +1,18 @@
+assertEquals(125, ord(IecType::iecBYTE(125)));
+ $this->assertEquals(98, ord(IecType::iecBYTE(98)));
+ $this->assertEquals(0, ord(IecType::iecBYTE(0)));
+ $this->assertEquals(255, ord(IecType::iecBYTE(255)));
+ $this->assertEquals(88, ord(IecType::iecBYTE(88)));
+ }
+}
\ No newline at end of file
diff --git a/tests/IecType/IecDIntTest.php b/tests/IecType/IecDIntTest.php
new file mode 100644
index 0000000..b1eaaef
--- /dev/null
+++ b/tests/IecType/IecDIntTest.php
@@ -0,0 +1,31 @@
+assertEquals('00000000', self::unPackDInt2HexString(0));
+ $this->assertEquals('00010000', self::unPackDInt2HexString(1));
+ $this->assertEquals('ffffffff', self::unPackDInt2HexString(-1));
+ $this->assertEquals('ffff7fff', self::unPackDInt2HexString(pow(2, 31) - 1));
+ $this->assertEquals('00008000', self::unPackDInt2HexString(-pow(2, 31)));
+ }
+
+ public function testIecDintEndianingOn()
+ {
+ $this->assertEquals('00000000', self::unPackDInt2HexString(0, 1));
+ $this->assertEquals('00000001', self::unPackDInt2HexString(1, 1));
+ $this->assertEquals('ffffffff', self::unPackDInt2HexString(-1, 1));
+ $this->assertEquals('7fffffff', self::unPackDInt2HexString(pow(2, 31) - 1, 1));
+ $this->assertEquals('80000000', self::unPackDInt2HexString(-pow(2, 31), 1));
+ }
+}
diff --git a/tests/IecType/IecIntTest.php b/tests/IecType/IecIntTest.php
new file mode 100644
index 0000000..3abc828
--- /dev/null
+++ b/tests/IecType/IecIntTest.php
@@ -0,0 +1,22 @@
+assertEquals('0000', self::unPackInt2HexString(0));
+ $this->assertEquals('0001', self::unPackInt2HexString(1));
+ $this->assertEquals('ffff', self::unPackInt2HexString(-1));
+ $this->assertEquals('7fff', self::unPackInt2HexString(pow(2, 15) - 1));
+ $this->assertEquals('8000', self::unPackInt2HexString(-pow(2, 15)));
+ }
+}
\ No newline at end of file
diff --git a/tests/IecType/IecRealTest.php b/tests/IecType/IecRealTest.php
new file mode 100644
index 0000000..070568d
--- /dev/null
+++ b/tests/IecType/IecRealTest.php
@@ -0,0 +1,31 @@
+assertEquals('00000000', self::unPackReal2HexString(0));
+ $this->assertEquals('00003f80', self::unPackReal2HexString(1));
+ $this->assertEquals('0000c000', self::unPackReal2HexString(-2));
+ $this->assertEquals('aaab3eaa', self::unPackReal2HexString(0.333333333333));
+ $this->assertEquals('000041c8', self::unPackReal2HexString(25));
+ }
+
+ public function testIecRealEndianingOn()
+ {
+ $this->assertEquals('00000000', self::unPackReal2HexString(0, 1));
+ $this->assertEquals('3f800000', self::unPackReal2HexString(1, 1));
+ $this->assertEquals('c0000000', self::unPackReal2HexString(-2, 1));
+ $this->assertEquals('3eaaaaab', self::unPackReal2HexString(0.333333333333, 1));
+ $this->assertEquals('41c80000', self::unPackReal2HexString(25, 1));
+ }
+}
diff --git a/tests/IecType/_test.bat b/tests/IecType/_test.bat
deleted file mode 100644
index 8122004..0000000
--- a/tests/IecType/_test.bat
+++ /dev/null
@@ -1,11 +0,0 @@
-@echo off
-call ../config.bat
-
-for %%f in (test.*.php) do %php% -q "%%f" > "output/%%f.html"
-
-cd output
-for %%f in (*.html) do %diff% "%%f" ../ref/"%%f"
-cd ..
-pause
-
-@echo on
\ No newline at end of file
diff --git a/tests/IecType/ref/test.iecByte.php.html b/tests/IecType/ref/test.iecByte.php.html
deleted file mode 100644
index dc6e8a7..0000000
--- a/tests/IecType/ref/test.iecByte.php.html
+++ /dev/null
@@ -1 +0,0 @@
-125
98
0
0
0
0
0
0
0
0
0
0
255
255
255
255
158
88
97
168
\ No newline at end of file
diff --git a/tests/IecType/ref/test.iecDInt.php.html b/tests/IecType/ref/test.iecDInt.php.html
deleted file mode 100644
index 1abf31b..0000000
--- a/tests/IecType/ref/test.iecDInt.php.html
+++ /dev/null
@@ -1 +0,0 @@
-Endianing off
0 --> Packet: 0000_0000_1 --> Packet: 0001_0000_-1 --> Packet: ffff_ffff_2147483647 --> Packet: ffff_7fff_-2147483648 --> Packet: 0000_8000_Endianing on
0 --> Packet: 0000_0000_1 --> Packet: 0000_0001_-1 --> Packet: ffff_ffff_2147483647 --> Packet: 7fff_ffff_-2147483648 --> Packet: 8000_0000_
\ No newline at end of file
diff --git a/tests/IecType/ref/test.iecInt.php.html b/tests/IecType/ref/test.iecInt.php.html
deleted file mode 100644
index 583ad9b..0000000
--- a/tests/IecType/ref/test.iecInt.php.html
+++ /dev/null
@@ -1 +0,0 @@
-Endianing off
0 --> Packet: 0000_1 --> Packet: 0001_-1 --> Packet: ffff_32767 --> Packet: 7fff_-32768 --> Packet: 8000_Endianing on
0 --> Packet: 0000_1 --> Packet: 0001_-1 --> Packet: ffff_32767 --> Packet: 7fff_-32768 --> Packet: 8000_
\ No newline at end of file
diff --git a/tests/IecType/ref/test.iecReal.php.html b/tests/IecType/ref/test.iecReal.php.html
deleted file mode 100644
index a195b00..0000000
--- a/tests/IecType/ref/test.iecReal.php.html
+++ /dev/null
@@ -1,12 +0,0 @@
-Endianing off
-0 --> Packet: 0000_0000_
-1 --> Packet: 0000_3f80_
--2 --> Packet: 0000_c000_
-0.333333333333 --> Packet: aaab_3eaa_
-25 --> Packet: 0000_41c8_
-Endianing on
-0 --> Packet: 0000_0000_
-1 --> Packet: 3f80_0000_
--2 --> Packet: c000_0000_
-0.333333333333 --> Packet: 3eaa_aaab_
-25 --> Packet: 41c8_0000_
diff --git a/tests/IecType/test.iecByte.php b/tests/IecType/test.iecByte.php
deleted file mode 100644
index 8af17c8..0000000
--- a/tests/IecType/test.iecByte.php
+++ /dev/null
@@ -1,33 +0,0 @@
- 125, // 32098 (DINT)
- "1" => 98,
- "2" => 0,
- "3" => 0,
- "4" => 0, // 0 (DINT)
- "5" => 0,
- "6" => 0,
- "7" => 0,
- "8" => 0, // 0 (DINT)
- "9" => 0,
- "10" => 0,
- "11" => 0,
- "12" => 255, // -1 (DINT)
- "13" => 255,
- "14" => 255,
- "15" => 255,
- "16" => 158, // -25000 (INT)
- "17" => 88,
- "18" => 97, // 25000 (INT)
- "19" => 168
-);
-
-// Print mixed values
-foreach($data as $d)
- echo ord(IecType::iecBYTE($d)) . "
";
-
-?>
\ No newline at end of file
diff --git a/tests/IecType/test.iecDInt.php b/tests/IecType/test.iecDInt.php
deleted file mode 100644
index 24a4820..0000000
--- a/tests/IecType/test.iecDInt.php
+++ /dev/null
@@ -1,50 +0,0 @@
- 0,
- "1" => 1,
- "2" => -1,
- "3" => pow(2,31)-1,
- "4" => -pow(2,31)
-);
-
-function byte2hex($value){
- $h = dechex(($value >> 4) & 0x0F);
- $l = dechex($value & 0x0F);
- return "$h$l";
-}
-
-function printPacket($packet){
- $str = "";
- $str .= "Packet: ";
- for($i=0;$i";
-// Print mixed values
-for($i=0;$i ";
- $v = IecType::iecDINT($data[$i], 0);
- echo printPacket($v);
- "
";
-}
-
-echo "Endianing on
";
-// Print mixed values
-for($i=0;$i ";
- $v = IecType::iecDINT($data[$i], 1);
- echo printPacket($v);
- "
";
-}
-
-?>
\ No newline at end of file
diff --git a/tests/IecType/test.iecInt.php b/tests/IecType/test.iecInt.php
deleted file mode 100644
index dec812e..0000000
--- a/tests/IecType/test.iecInt.php
+++ /dev/null
@@ -1,50 +0,0 @@
- 0,
- "1" => 1,
- "2" => -1,
- "3" => pow(2,15)-1,
- "4" => -pow(2,15)
-);
-
-function byte2hex($value){
- $h = dechex(($value >> 4) & 0x0F);
- $l = dechex($value & 0x0F);
- return "$h$l";
-}
-
-function printPacket($packet){
- $str = "";
- $str .= "Packet: ";
- for($i=0;$i";
-// Print mixed values
-for($i=0;$i ";
- $v = IecType::iecINT($data[$i], 0);
- echo printPacket($v);
- "
";
-}
-
-echo "Endianing on
";
-// Print mixed values
-for($i=0;$i ";
- $v = IecType::iecINT($data[$i], 1);
- echo printPacket($v);
- "
";
-}
-
-?>
\ No newline at end of file
diff --git a/tests/IecType/test.iecReal.php b/tests/IecType/test.iecReal.php
deleted file mode 100644
index 30495fd..0000000
--- a/tests/IecType/test.iecReal.php
+++ /dev/null
@@ -1,50 +0,0 @@
- 0, // -> 0000 0000
- "1" => 1, // -> 3f80 0000
- "2" => -2, // -> c000 0000
- "3" => 0.333333333333, //1/3 -> 3eaa aaab
- "4" => 25 // -> 41c8 0000
-);
-
-function byte2hex($value){
- $h = dechex(($value >> 4) & 0x0F);
- $l = dechex($value & 0x0F);
- return "$h$l";
-}
-
-function printPacket($packet){
- $str = "";
- $str .= "Packet: ";
- for($i=0;$i\n";
-// Print mixed values
-for($i=0;$i ";
- $v = IecType::iecREAL($data[$i], 0);
- echo printPacket($v);
- "
\n";
-}
-
-echo "Endianing on
\n";
-// Print mixed values
-for($i=0;$i ";
- $v = IecType::iecREAL($data[$i], 1);
- echo printPacket($v);
- "
\n";
-}
-
-?>
\ No newline at end of file
diff --git a/tests/ModbusMaster/BindClientToLocalIpAndPortTest.php b/tests/ModbusMaster/BindClientToLocalIpAndPortTest.php
new file mode 100644
index 0000000..b171356
--- /dev/null
+++ b/tests/ModbusMaster/BindClientToLocalIpAndPortTest.php
@@ -0,0 +1,25 @@
+port = $port;
+ // use wildcard as multiple IPs on same machine ala VirtualBox network adapter installed may result ip that you cannot bind to
+ // good enough for test that no thing throws exception.
+ $modbus->client = '0.0.0.0';
+ $modbus->client_port = mt_rand(30000, 40000);
+
+ $this->assertEquals([1], $modbus->readCoils(0, 256, 1));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000006000101000001', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/Fc15WriteMultipleCoilsTest.php b/tests/ModbusMaster/Fc15WriteMultipleCoilsTest.php
new file mode 100644
index 0000000..bc59828
--- /dev/null
+++ b/tests/ModbusMaster/Fc15WriteMultipleCoilsTest.php
@@ -0,0 +1,21 @@
+port = $port;
+
+ $this->assertTrue($modbus->fc15(0, 12288, [1, 0, 1]));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000008000f300000030105', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/Fc16WriteMultipleRegistersTest.php b/tests/ModbusMaster/Fc16WriteMultipleRegistersTest.php
new file mode 100644
index 0000000..ca1dcff
--- /dev/null
+++ b/tests/ModbusMaster/Fc16WriteMultipleRegistersTest.php
@@ -0,0 +1,21 @@
+port = $port;
+
+ $this->assertTrue($modbus->fc16(0, 12288, [-1,100001,1.3], ['INT', 'DINT', 'REAL']));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('000000110010300000050affff86a1000166663fa6', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/Fc1ReadCoilsTest.php b/tests/ModbusMaster/Fc1ReadCoilsTest.php
new file mode 100644
index 0000000..e4d0b82
--- /dev/null
+++ b/tests/ModbusMaster/Fc1ReadCoilsTest.php
@@ -0,0 +1,35 @@
+port = $port;
+
+ $this->assertEquals([1], $modbus->readCoils(0, 256, 1));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000006000101000001', $packetWithoutTransactionId);
+ }
+
+ public function testFc1Read3Coils()
+ {
+ $mockResponse = '31be0000000400010103'; // respond with 1 byte (00000011 bits set) [1, 1, 0]
+ $clientData = static::executeWithMockServer($mockResponse, function ($port) {
+ $modbus = new ModbusMaster('127.0.0.1', 'TCP');
+ $modbus->port = $port;
+
+ $this->assertEquals([1, 1, 0], $modbus->fc1(0, 256, 3));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000006000101000003', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/Fc22MaskWriteRegisterTest.php b/tests/ModbusMaster/Fc22MaskWriteRegisterTest.php
new file mode 100644
index 0000000..6450828
--- /dev/null
+++ b/tests/ModbusMaster/Fc22MaskWriteRegisterTest.php
@@ -0,0 +1,26 @@
+port = $port;
+
+ $bitValue = true;
+ $bitNumber = 2;
+ $andMask = 0xFFFF ^ pow(2, $bitNumber) ;
+ $orMask = 0x0000 ^ (pow(2, $bitNumber) * $bitValue ) ;
+
+ $this->assertTrue($modbus->fc22(0, 12288, $andMask, $orMask));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('0000000800163000fffb0004', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/Fc23ReadWriteRegistersTest.php b/tests/ModbusMaster/Fc23ReadWriteRegistersTest.php
new file mode 100644
index 0000000..83c821c
--- /dev/null
+++ b/tests/ModbusMaster/Fc23ReadWriteRegistersTest.php
@@ -0,0 +1,24 @@
+port = $port;
+
+ $data = array(10, -1000, 2000, 3.0);
+ $dataTypes = array("INT", "INT", "DINT", "REAL");
+
+ $this->assertEquals([0, 10, 252, 24, 7, 208, 0, 0, 0, 0, 64, 64], $modbus->fc23(0, 12288, 6, 12288, $data, $dataTypes));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000017001730000006300000060c000afc1807d0000000004040', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/Fc2ReadInputDiscretesTest.php b/tests/ModbusMaster/Fc2ReadInputDiscretesTest.php
new file mode 100644
index 0000000..00c95b1
--- /dev/null
+++ b/tests/ModbusMaster/Fc2ReadInputDiscretesTest.php
@@ -0,0 +1,35 @@
+port = $port;
+
+ $this->assertEquals([1], $modbus->readInputDiscretes(0, 256, 1));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000006000201000001', $packetWithoutTransactionId);
+ }
+
+ public function testFc1Read3InputDiscretes()
+ {
+ $mockResponse = 'b5110000000400020103';
+ $clientData = static::executeWithMockServer($mockResponse, function ($port) {
+ $modbus = new ModbusMaster('127.0.0.1', 'TCP');
+ $modbus->port = $port;
+
+ $this->assertEquals([1, 1, 0], $modbus->fc2(0, 256, 3));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000006000201000003', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/Fc3ReadMultipleRegistersTest.php b/tests/ModbusMaster/Fc3ReadMultipleRegistersTest.php
new file mode 100644
index 0000000..18b77db
--- /dev/null
+++ b/tests/ModbusMaster/Fc3ReadMultipleRegistersTest.php
@@ -0,0 +1,35 @@
+port = $port;
+
+ $this->assertEquals([0, 3], $modbus->readMultipleRegisters(0, 256, 1));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000006000301000001', $packetWithoutTransactionId);
+ }
+
+ public function testFc3Read3Words()
+ {
+ $mockResponse = 'e4710000000900030693e000040000'; // respond with 3 WORD (3*2 bytes) [147, 224, 0, 4, 0, 0]
+ $clientData = static::executeWithMockServer($mockResponse, function ($port) {
+ $modbus = new ModbusMaster('127.0.0.1', 'TCP');
+ $modbus->port = $port;
+
+ $this->assertEquals([147, 224, 0, 4, 0, 0], $modbus->fc3(0, 268, 3));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('000000060003010c0003', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/Fc4ReadMultipleInputRegistersTest.php b/tests/ModbusMaster/Fc4ReadMultipleInputRegistersTest.php
new file mode 100644
index 0000000..01cc9ef
--- /dev/null
+++ b/tests/ModbusMaster/Fc4ReadMultipleInputRegistersTest.php
@@ -0,0 +1,35 @@
+port = $port;
+
+ $this->assertEquals([0, 3], $modbus->readMultipleInputRegisters(0, 256, 1));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000006000401000001', $packetWithoutTransactionId);
+ }
+
+ public function testFc4Read3Words()
+ {
+ $mockResponse = 'e4710000000900030693e000040000'; // respond with 3 WORD (3*2 bytes) [147, 224, 0, 4, 0, 0]
+ $clientData = static::executeWithMockServer($mockResponse, function ($port) {
+ $modbus = new ModbusMaster('127.0.0.1', 'TCP');
+ $modbus->port = $port;
+
+ $this->assertEquals([147, 224, 0, 4, 0, 0], $modbus->fc4(0, 268, 3));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('000000060004010c0003', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/Fc5WriteSingleCoilTest.php b/tests/ModbusMaster/Fc5WriteSingleCoilTest.php
new file mode 100644
index 0000000..064f153
--- /dev/null
+++ b/tests/ModbusMaster/Fc5WriteSingleCoilTest.php
@@ -0,0 +1,35 @@
+port = $port;
+
+ $this->assertTrue($modbus->writeSingleCoil(0, 4096, [1]));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('0000000600051000ff00', $packetWithoutTransactionId);
+ }
+
+ public function testFc5WriteSingleCoilWith0()
+ {
+ $mockResponse = '489c00000006000510000000';
+ $clientData = static::executeWithMockServer($mockResponse, function ($port) {
+ $modbus = new ModbusMaster('127.0.0.1', 'TCP');
+ $modbus->port = $port;
+
+ $this->assertTrue($modbus->fc5(0, 4096, [0]));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000006000510000000', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/Fc6WriteSingleRegisterTest.php b/tests/ModbusMaster/Fc6WriteSingleRegisterTest.php
new file mode 100644
index 0000000..212c847
--- /dev/null
+++ b/tests/ModbusMaster/Fc6WriteSingleRegisterTest.php
@@ -0,0 +1,35 @@
+port = $port;
+
+ $this->assertTrue($modbus->writeSingleRegister(0, 4096, [15]));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('0000000600061000000f', $packetWithoutTransactionId);
+ }
+
+ public function testFc6WriteSingleRegisterWith0()
+ {
+ $mockResponse = '489c00000006000510000000';
+ $clientData = static::executeWithMockServer($mockResponse, function ($port) {
+ $modbus = new ModbusMaster('127.0.0.1', 'TCP');
+ $modbus->port = $port;
+
+ $this->assertTrue($modbus->fc6(0, 4096, [0]));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000006000610000000', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/MockResponseServer.php b/tests/ModbusMaster/MockResponseServer.php
new file mode 100644
index 0000000..081d415
--- /dev/null
+++ b/tests/ModbusMaster/MockResponseServer.php
@@ -0,0 +1,86 @@
+port = $port;
+
+ $loop = Factory::create();
+
+ if ('TCP' === $protocol) {
+ $this->startTcpServer($loop, $answerTimeout, $responsePacket);
+ } else {
+ $this->startUdpServer($loop, $answerTimeout, $responsePacket);
+ }
+
+ $loop->addPeriodicTimer(self::MAX_WAIT_TIMEOUT, function () use ($loop) {
+ $loop->stop();
+ });
+ $loop->run();
+ }
+
+ private function startTcpServer($loop, $answerTimeout, $responsePacket)
+ {
+ $socket = new Server($loop);
+
+ $socket->on('connection', function ($conn) use ($socket, $loop, $answerTimeout, $responsePacket) {
+ $conn->on('data', function ($data) use ($conn, $answerTimeout, $responsePacket) {
+ if ($answerTimeout) {
+ sleep($answerTimeout);
+ }
+ $conn->write(pack('H*', $responsePacket));
+
+ echo unpack('H*', $data)[1];
+ });
+
+ $conn->on('close', function () use ($socket, $loop) {
+ $socket->shutdown();
+ $loop->stop();
+ });
+ });
+
+ $socket->listen($this->port);
+ }
+
+ private function startUdpServer($loop, $answerTimeout, $responsePacket)
+ {
+ $factory = new \React\Datagram\Factory($loop);
+
+ $factory->createServer('127.0.0.1:' . $this->port)->then(function (Socket $server) use ($loop, $answerTimeout, $responsePacket) {
+ $server->on('message', function ($message, $address, Socket $server) use ($loop, $answerTimeout, $responsePacket) {
+ if ($answerTimeout > 0) {
+ sleep($answerTimeout);
+ }
+ $server->send(pack('H*', $responsePacket), $address);
+
+ echo unpack('H*', $message)[1];
+
+ $loop->addTimer(0.001, function () use ($server, $loop) {
+ $server->emit('shutdown', [$server]);
+ });
+ });
+
+ //silly but otherwise client will not receive packets from server. probably server is closed before stream is flushed etc
+ $server->on('shutdown', function () use ($server, $loop) {
+ $loop->addTimer(0.002, function () use ($server, $loop) {
+ $server->close();
+ $loop->stop();
+ });
+ });
+ });
+ }
+}
+
+new MockResponseServer($argv[1], $argv[2], $argv[3], $argv[4]);
\ No newline at end of file
diff --git a/tests/ModbusMaster/MockServerTestCase.php b/tests/ModbusMaster/MockServerTestCase.php
new file mode 100644
index 0000000..b6e93fd
--- /dev/null
+++ b/tests/ModbusMaster/MockServerTestCase.php
@@ -0,0 +1,32 @@
+addTimer(0.001, function (Timer $timer) use ($process, $closure, $port, &$clientData) {
+ $process->start($timer->getLoop());
+
+ $process->stdout->on('data', function ($output) use (&$clientData) {
+ $clientData[] = $output;
+ });
+
+ $closure($port);
+ });
+
+ $loop->run();
+ return $clientData;
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/ModbusExceptionTest.php b/tests/ModbusMaster/ModbusExceptionTest.php
new file mode 100644
index 0000000..0d31651
--- /dev/null
+++ b/tests/ModbusMaster/ModbusExceptionTest.php
@@ -0,0 +1,63 @@
+expectException(\Exception::class);
+ $this->expectExceptionMessage("Unknown socket protocol, should be 'TCP' or 'UDP'");
+
+ $modbus = new ModbusMaster('127.0.0.1', 'Mismatch');
+ $modbus->readCoils(0, 256, 1);
+ }
+
+ public function testPortClosedException()
+ {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('socket_connect() failed. Reason: ()No connection could be made because the target machine actively refused it.');
+
+ $modbus = new ModbusMasterTcp('127.0.0.1');
+ $modbus->setSocketTimeout(0.2, 0.2);
+ $modbus->readCoils(0, 256, 1);
+ }
+
+ public function testTimeoutException()
+ {
+ $this->expectException(\Exception::class);
+
+ $mockResponse = '89130000000400010101'; // respond with 1 byte (00000001 bits set) [1]
+ static::executeWithMockServer($mockResponse, function ($port) {
+ $this->expectExceptionMessage("Watchdog time expired [ 0.5 sec ]!!! Connection to 127.0.0.1:{$port} is not established.");
+
+ $modbus = new ModbusMaster('127.0.0.1', 'UDP');
+ $modbus->port = $port;
+ $modbus->setTimeout(0.5);
+ $modbus->setSocketTimeout(0.2, 0.2);
+
+ $modbus->readCoils(0, 256, 1);
+ }, 'UDP', 1);
+ }
+
+
+ public function testThrowIllegalDataValueException()
+ {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Modbus response error code: 3 (ILLEGAL DATA VALUE)');
+
+ $mockResponse = 'da8700000003008303'; // respond with 1 WORD (2 bytes) [0, 3]
+ $clientData = static::executeWithMockServer($mockResponse, function ($port) {
+ $modbus = new ModbusMaster('127.0.0.1', 'TCP');
+ $modbus->port = $port;
+
+ //can not query more than 124 WORDs. Wago response is ILLEGAL DATA VALUE
+ $this->assertEquals([0, 3], $modbus->readMultipleRegisters(0, 256, 140));
+ });
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('0000000600030100008c', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/UdpFc1ReadCoilsTest.php b/tests/ModbusMaster/UdpFc1ReadCoilsTest.php
new file mode 100644
index 0000000..78a6e34
--- /dev/null
+++ b/tests/ModbusMaster/UdpFc1ReadCoilsTest.php
@@ -0,0 +1,23 @@
+port = $port;
+
+ usleep(50000); // no idea how to fix this. wait for server to "warm" up or modbus UDP socket will timeout. does not occur with TCP
+ $this->assertEquals([1], $modbus->readCoils(0, 256, 1));
+ }, 'UDP');
+
+ $packetWithoutTransactionId = substr($clientData[0], 4);
+ $this->assertEquals('00000006000101000001', $packetWithoutTransactionId);
+ }
+}
\ No newline at end of file
diff --git a/tests/ModbusMaster/_test.bat b/tests/ModbusMaster/_test.bat
deleted file mode 100644
index 8122004..0000000
--- a/tests/ModbusMaster/_test.bat
+++ /dev/null
@@ -1,11 +0,0 @@
-@echo off
-call ../config.bat
-
-for %%f in (test.*.php) do %php% -q "%%f" > "output/%%f.html"
-
-cd output
-for %%f in (*.html) do %diff% "%%f" ../ref/"%%f"
-cd ..
-pause
-
-@echo on
\ No newline at end of file
diff --git a/tests/ModbusMaster/ref/test.tcp.fc16fc3.php.html b/tests/ModbusMaster/ref/test.tcp.fc16fc3.php.html
deleted file mode 100644
index 00dd046..0000000
--- a/tests/ModbusMaster/ref/test.tcp.fc16fc3.php.html
+++ /dev/null
@@ -1,72 +0,0 @@
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 1
- [4] => 0
- [5] => 1
- [6] => 0
- [7] => 255
- [8] => 0
- [9] => 255
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 1
- [4] => 255
- [5] => 255
- [6] => 127
- [7] => 255
- [8] => 128
- [9] => 0
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 0
- [4] => 0
- [5] => 1
- [6] => 0
- [7] => 0
- [8] => 255
- [9] => 255
- [10] => 255
- [11] => 255
- [12] => 255
- [13] => 255
- [14] => 127
- [15] => 255
- [16] => 0
- [17] => 0
- [18] => 128
- [19] => 0
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 0
- [4] => 0
- [5] => 0
- [6] => 63
- [7] => 128
- [8] => 0
- [9] => 0
- [10] => 192
- [11] => 0
- [12] => 170
- [13] => 171
- [14] => 62
- [15] => 170
- [16] => 0
- [17] => 0
- [18] => 65
- [19] => 200
-)
diff --git a/tests/ModbusMaster/ref/test.tcp.fc26.php.html b/tests/ModbusMaster/ref/test.tcp.fc26.php.html
deleted file mode 100644
index 7991aa8..0000000
--- a/tests/ModbusMaster/ref/test.tcp.fc26.php.html
+++ /dev/null
@@ -1 +0,0 @@
-writeMultipleRegister (FC26): DONE
\ No newline at end of file
diff --git a/tests/ModbusMaster/ref/test.tcp.socket_protocol_mismatch.php.html b/tests/ModbusMaster/ref/test.tcp.socket_protocol_mismatch.php.html
deleted file mode 100644
index b25cfe4..0000000
--- a/tests/ModbusMaster/ref/test.tcp.socket_protocol_mismatch.php.html
+++ /dev/null
@@ -1 +0,0 @@
-Caught exception: Unknown socket protocol, should be 'TCP' or 'UDP'
diff --git a/tests/ModbusMaster/ref/test.udp.fc16fc3.php.html b/tests/ModbusMaster/ref/test.udp.fc16fc3.php.html
deleted file mode 100644
index 00dd046..0000000
--- a/tests/ModbusMaster/ref/test.udp.fc16fc3.php.html
+++ /dev/null
@@ -1,72 +0,0 @@
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 1
- [4] => 0
- [5] => 1
- [6] => 0
- [7] => 255
- [8] => 0
- [9] => 255
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 1
- [4] => 255
- [5] => 255
- [6] => 127
- [7] => 255
- [8] => 128
- [9] => 0
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 0
- [4] => 0
- [5] => 1
- [6] => 0
- [7] => 0
- [8] => 255
- [9] => 255
- [10] => 255
- [11] => 255
- [12] => 255
- [13] => 255
- [14] => 127
- [15] => 255
- [16] => 0
- [17] => 0
- [18] => 128
- [19] => 0
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 0
- [4] => 0
- [5] => 0
- [6] => 63
- [7] => 128
- [8] => 0
- [9] => 0
- [10] => 192
- [11] => 0
- [12] => 170
- [13] => 171
- [14] => 62
- [15] => 170
- [16] => 0
- [17] => 0
- [18] => 65
- [19] => 200
-)
diff --git a/tests/ModbusMaster/ref/test.udp.fc26.php.html b/tests/ModbusMaster/ref/test.udp.fc26.php.html
deleted file mode 100644
index 7991aa8..0000000
--- a/tests/ModbusMaster/ref/test.udp.fc26.php.html
+++ /dev/null
@@ -1 +0,0 @@
-writeMultipleRegister (FC26): DONE
\ No newline at end of file
diff --git a/tests/ModbusMaster/test.tcp.fc16fc3.php b/tests/ModbusMaster/test.tcp.fc16fc3.php
deleted file mode 100644
index bd0b765..0000000
--- a/tests/ModbusMaster/test.tcp.fc16fc3.php
+++ /dev/null
@@ -1,44 +0,0 @@
-writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 5);
-print_r($recData);
-
-// Data to be writen - INT
-$data = array(0, 1, -1, pow(2,15)-1, -pow(2,15));
-$dataTypes = array("INT", "INT", "INT", "INT", "INT");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 5);
-print_r($recData);
-
-// Data to be writen - DINT
-$data = array(0, 1, -1, pow(2,31)-1, -pow(2,31));
-$dataTypes = array("DINT", "DINT", "DINT", "DINT", "DINT");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 10);
-print_r($recData);
-
-// Data to be writen - REAL
-$data = array(0, 1, -2, 1/3, 25);
-$dataTypes = array("REAL", "REAL", "REAL", "REAL", "REAL");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 10);
-print_r($recData);
-
-?>
\ No newline at end of file
diff --git a/tests/ModbusMaster/test.tcp.fc26.php b/tests/ModbusMaster/test.tcp.fc26.php
deleted file mode 100644
index 2c76b7f..0000000
--- a/tests/ModbusMaster/test.tcp.fc26.php
+++ /dev/null
@@ -1,24 +0,0 @@
-readWriteRegisters(0, 12288, 6, 12288, $data, $dataTypes);
-
-if(!$recData) {
- // Print error information if any
- echo "Error:" . $modbus->errstr . "";
- //
- exit();
-}
-
-// Print status information
-echo "writeMultipleRegister (FC26): DONE";
-?>
\ No newline at end of file
diff --git a/tests/ModbusMaster/test.tcp.socket_protocol_mismatch.php b/tests/ModbusMaster/test.tcp.socket_protocol_mismatch.php
deleted file mode 100644
index aa5f691..0000000
--- a/tests/ModbusMaster/test.tcp.socket_protocol_mismatch.php
+++ /dev/null
@@ -1,22 +0,0 @@
-readWriteRegisters(0, 12288, 6, 12288, $data, $dataTypes);
-} catch (Exception $e) {
- echo 'Caught exception: ', $e->getMessage(), "\n";
- exit();
-}
-// Should through an Exception
-
-// Print status information
-echo "Should never reach this line!";
\ No newline at end of file
diff --git a/tests/ModbusMaster/test.udp.fc16fc3.php b/tests/ModbusMaster/test.udp.fc16fc3.php
deleted file mode 100644
index 20dee62..0000000
--- a/tests/ModbusMaster/test.udp.fc16fc3.php
+++ /dev/null
@@ -1,44 +0,0 @@
-writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 5);
-print_r($recData);
-
-// Data to be writen - INT
-$data = array(0, 1, -1, pow(2,15)-1, -pow(2,15));
-$dataTypes = array("INT", "INT", "INT", "INT", "INT");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 5);
-print_r($recData);
-
-// Data to be writen - DINT
-$data = array(0, 1, -1, pow(2,31)-1, -pow(2,31));
-$dataTypes = array("DINT", "DINT", "DINT", "DINT", "DINT");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 10);
-print_r($recData);
-
-// Data to be writen - REAL
-$data = array(0, 1, -2, 1/3, 25);
-$dataTypes = array("REAL", "REAL", "REAL", "REAL", "REAL");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 10);
-print_r($recData);
-
-?>
\ No newline at end of file
diff --git a/tests/ModbusMaster/test.udp.fc26.php b/tests/ModbusMaster/test.udp.fc26.php
deleted file mode 100644
index 02352ac..0000000
--- a/tests/ModbusMaster/test.udp.fc26.php
+++ /dev/null
@@ -1,24 +0,0 @@
-readWriteRegisters(0, 12288, 6, 12288, $data, $dataTypes);
-
-if(!$recData) {
- // Print error information if any
- echo "Error:" . $modbus->errstr . "";
- //
- exit();
-}
-
-// Print status information
-echo "writeMultipleRegister (FC26): DONE";
-?>
\ No newline at end of file
diff --git a/tests/ModbusMasterTcp/_test.bat b/tests/ModbusMasterTcp/_test.bat
deleted file mode 100644
index 8122004..0000000
--- a/tests/ModbusMasterTcp/_test.bat
+++ /dev/null
@@ -1,11 +0,0 @@
-@echo off
-call ../config.bat
-
-for %%f in (test.*.php) do %php% -q "%%f" > "output/%%f.html"
-
-cd output
-for %%f in (*.html) do %diff% "%%f" ../ref/"%%f"
-cd ..
-pause
-
-@echo on
\ No newline at end of file
diff --git a/tests/ModbusMasterTcp/ref/test.fc16fc3.php.html b/tests/ModbusMasterTcp/ref/test.fc16fc3.php.html
deleted file mode 100644
index 00dd046..0000000
--- a/tests/ModbusMasterTcp/ref/test.fc16fc3.php.html
+++ /dev/null
@@ -1,72 +0,0 @@
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 1
- [4] => 0
- [5] => 1
- [6] => 0
- [7] => 255
- [8] => 0
- [9] => 255
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 1
- [4] => 255
- [5] => 255
- [6] => 127
- [7] => 255
- [8] => 128
- [9] => 0
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 0
- [4] => 0
- [5] => 1
- [6] => 0
- [7] => 0
- [8] => 255
- [9] => 255
- [10] => 255
- [11] => 255
- [12] => 255
- [13] => 255
- [14] => 127
- [15] => 255
- [16] => 0
- [17] => 0
- [18] => 128
- [19] => 0
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 0
- [4] => 0
- [5] => 0
- [6] => 63
- [7] => 128
- [8] => 0
- [9] => 0
- [10] => 192
- [11] => 0
- [12] => 170
- [13] => 171
- [14] => 62
- [15] => 170
- [16] => 0
- [17] => 0
- [18] => 65
- [19] => 200
-)
diff --git a/tests/ModbusMasterTcp/ref/test.fc26.php.html b/tests/ModbusMasterTcp/ref/test.fc26.php.html
deleted file mode 100644
index 7991aa8..0000000
--- a/tests/ModbusMasterTcp/ref/test.fc26.php.html
+++ /dev/null
@@ -1 +0,0 @@
-writeMultipleRegister (FC26): DONE
\ No newline at end of file
diff --git a/tests/ModbusMasterTcp/test.fc16fc3.php b/tests/ModbusMasterTcp/test.fc16fc3.php
deleted file mode 100644
index 2fc3ee2..0000000
--- a/tests/ModbusMasterTcp/test.fc16fc3.php
+++ /dev/null
@@ -1,44 +0,0 @@
-writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 5);
-print_r($recData);
-
-// Data to be writen - INT
-$data = array(0, 1, -1, pow(2,15)-1, -pow(2,15));
-$dataTypes = array("INT", "INT", "INT", "INT", "INT");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 5);
-print_r($recData);
-
-// Data to be writen - DINT
-$data = array(0, 1, -1, pow(2,31)-1, -pow(2,31));
-$dataTypes = array("DINT", "DINT", "DINT", "DINT", "DINT");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 10);
-print_r($recData);
-
-// Data to be writen - REAL
-$data = array(0, 1, -2, 1/3, 25);
-$dataTypes = array("REAL", "REAL", "REAL", "REAL", "REAL");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 10);
-print_r($recData);
-
-?>
\ No newline at end of file
diff --git a/tests/ModbusMasterTcp/test.fc26.php b/tests/ModbusMasterTcp/test.fc26.php
deleted file mode 100644
index 076ab22..0000000
--- a/tests/ModbusMasterTcp/test.fc26.php
+++ /dev/null
@@ -1,24 +0,0 @@
-readWriteRegisters(0, 12288, 6, 12288, $data, $dataTypes);
-
-if(!$recData) {
- // Print error information if any
- echo "Error:" . $modbus->errstr . "";
- //
- exit();
-}
-
-// Print status information
-echo "writeMultipleRegister (FC26): DONE";
-?>
\ No newline at end of file
diff --git a/tests/ModbusMasterUdp/_test.bat b/tests/ModbusMasterUdp/_test.bat
deleted file mode 100644
index 8122004..0000000
--- a/tests/ModbusMasterUdp/_test.bat
+++ /dev/null
@@ -1,11 +0,0 @@
-@echo off
-call ../config.bat
-
-for %%f in (test.*.php) do %php% -q "%%f" > "output/%%f.html"
-
-cd output
-for %%f in (*.html) do %diff% "%%f" ../ref/"%%f"
-cd ..
-pause
-
-@echo on
\ No newline at end of file
diff --git a/tests/ModbusMasterUdp/ref/test.fc15fc1.php.html b/tests/ModbusMasterUdp/ref/test.fc15fc1.php.html
deleted file mode 100644
index 55a3de0..0000000
--- a/tests/ModbusMasterUdp/ref/test.fc15fc1.php.html
+++ /dev/null
@@ -1,66 +0,0 @@
-array(32) {
- [0]=>
- bool(true)
- [1]=>
- bool(false)
- [2]=>
- bool(true)
- [3]=>
- bool(true)
- [4]=>
- bool(false)
- [5]=>
- bool(true)
- [6]=>
- bool(true)
- [7]=>
- bool(true)
- [8]=>
- bool(true)
- [9]=>
- bool(true)
- [10]=>
- bool(true)
- [11]=>
- bool(true)
- [12]=>
- bool(false)
- [13]=>
- bool(false)
- [14]=>
- bool(false)
- [15]=>
- bool(false)
- [16]=>
- bool(false)
- [17]=>
- bool(false)
- [18]=>
- bool(false)
- [19]=>
- bool(false)
- [20]=>
- bool(true)
- [21]=>
- bool(true)
- [22]=>
- bool(true)
- [23]=>
- bool(true)
- [24]=>
- bool(true)
- [25]=>
- bool(true)
- [26]=>
- bool(true)
- [27]=>
- bool(true)
- [28]=>
- bool(true)
- [29]=>
- bool(true)
- [30]=>
- bool(true)
- [31]=>
- bool(true)
-}
diff --git a/tests/ModbusMasterUdp/ref/test.fc16fc3.php.html b/tests/ModbusMasterUdp/ref/test.fc16fc3.php.html
deleted file mode 100644
index 00dd046..0000000
--- a/tests/ModbusMasterUdp/ref/test.fc16fc3.php.html
+++ /dev/null
@@ -1,72 +0,0 @@
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 1
- [4] => 0
- [5] => 1
- [6] => 0
- [7] => 255
- [8] => 0
- [9] => 255
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 1
- [4] => 255
- [5] => 255
- [6] => 127
- [7] => 255
- [8] => 128
- [9] => 0
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 0
- [4] => 0
- [5] => 1
- [6] => 0
- [7] => 0
- [8] => 255
- [9] => 255
- [10] => 255
- [11] => 255
- [12] => 255
- [13] => 255
- [14] => 127
- [15] => 255
- [16] => 0
- [17] => 0
- [18] => 128
- [19] => 0
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 0
- [4] => 0
- [5] => 0
- [6] => 63
- [7] => 128
- [8] => 0
- [9] => 0
- [10] => 192
- [11] => 0
- [12] => 170
- [13] => 171
- [14] => 62
- [15] => 170
- [16] => 0
- [17] => 0
- [18] => 65
- [19] => 200
-)
diff --git a/tests/ModbusMasterUdp/ref/test.fc16fc3bind.php.html b/tests/ModbusMasterUdp/ref/test.fc16fc3bind.php.html
deleted file mode 100644
index 00dd046..0000000
--- a/tests/ModbusMasterUdp/ref/test.fc16fc3bind.php.html
+++ /dev/null
@@ -1,72 +0,0 @@
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 1
- [4] => 0
- [5] => 1
- [6] => 0
- [7] => 255
- [8] => 0
- [9] => 255
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 1
- [4] => 255
- [5] => 255
- [6] => 127
- [7] => 255
- [8] => 128
- [9] => 0
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 0
- [4] => 0
- [5] => 1
- [6] => 0
- [7] => 0
- [8] => 255
- [9] => 255
- [10] => 255
- [11] => 255
- [12] => 255
- [13] => 255
- [14] => 127
- [15] => 255
- [16] => 0
- [17] => 0
- [18] => 128
- [19] => 0
-)
-Array
-(
- [0] => 0
- [1] => 0
- [2] => 0
- [3] => 0
- [4] => 0
- [5] => 0
- [6] => 63
- [7] => 128
- [8] => 0
- [9] => 0
- [10] => 192
- [11] => 0
- [12] => 170
- [13] => 171
- [14] => 62
- [15] => 170
- [16] => 0
- [17] => 0
- [18] => 65
- [19] => 200
-)
diff --git a/tests/ModbusMasterUdp/ref/test.fc2.php.html b/tests/ModbusMasterUdp/ref/test.fc2.php.html
deleted file mode 100644
index 5baae72..0000000
--- a/tests/ModbusMasterUdp/ref/test.fc2.php.html
+++ /dev/null
@@ -1,7 +0,0 @@
-Test should pass when %IX0.0==FALSE and %IX0.1==TRUE
-array(2) {
- [0]=>
- bool(false)
- [1]=>
- bool(true)
-}
diff --git a/tests/ModbusMasterUdp/ref/test.fc26.php.html b/tests/ModbusMasterUdp/ref/test.fc26.php.html
deleted file mode 100644
index 7991aa8..0000000
--- a/tests/ModbusMasterUdp/ref/test.fc26.php.html
+++ /dev/null
@@ -1 +0,0 @@
-writeMultipleRegister (FC26): DONE
\ No newline at end of file
diff --git a/tests/ModbusMasterUdp/ref/test.fc26bind.php.html b/tests/ModbusMasterUdp/ref/test.fc26bind.php.html
deleted file mode 100644
index 7991aa8..0000000
--- a/tests/ModbusMasterUdp/ref/test.fc26bind.php.html
+++ /dev/null
@@ -1 +0,0 @@
-writeMultipleRegister (FC26): DONE
\ No newline at end of file
diff --git a/tests/ModbusMasterUdp/ref/test.fc4.php.html b/tests/ModbusMasterUdp/ref/test.fc4.php.html
deleted file mode 100644
index 4cbe5ae..0000000
--- a/tests/ModbusMasterUdp/ref/test.fc4.php.html
+++ /dev/null
@@ -1,11 +0,0 @@
-Test should pass when %IX0.0==FALSE and %IX0.1==TRUE
-array(4) {
- [0]=>
- int(0)
- [1]=>
- int(2)
- [2]=>
- int(0)
- [3]=>
- int(0)
-}
diff --git a/tests/ModbusMasterUdp/ref/test.fc5.php.html b/tests/ModbusMasterUdp/ref/test.fc5.php.html
deleted file mode 100644
index a6a24be..0000000
--- a/tests/ModbusMasterUdp/ref/test.fc5.php.html
+++ /dev/null
@@ -1,5 +0,0 @@
-Array
-(
- [0] => 0
- [1] => 5
-)
diff --git a/tests/ModbusMasterUdp/ref/test.fc6fc3.php.html b/tests/ModbusMasterUdp/ref/test.fc6fc3.php.html
deleted file mode 100644
index 6102dcd..0000000
--- a/tests/ModbusMasterUdp/ref/test.fc6fc3.php.html
+++ /dev/null
@@ -1,5 +0,0 @@
-Array
-(
- [0] => 207
- [1] => 199
-)
diff --git a/tests/ModbusMasterUdp/test.fc15fc1.php b/tests/ModbusMasterUdp/test.fc15fc1.php
deleted file mode 100644
index 5a7d8c4..0000000
--- a/tests/ModbusMasterUdp/test.fc15fc1.php
+++ /dev/null
@@ -1,22 +0,0 @@
-writeMultipleCoils(0, 12288, $data);
-//echo $modbus->status;
-//$modbus->status = "";
-//echo "\n\n";
-// Read data - FC 1
-$recData = $modbus->readCoils(0, 12288, 32);
-//echo $modbus->status;
-//echo "\n\n";
-var_dump($recData);
\ No newline at end of file
diff --git a/tests/ModbusMasterUdp/test.fc16fc3.php b/tests/ModbusMasterUdp/test.fc16fc3.php
deleted file mode 100644
index dff33c7..0000000
--- a/tests/ModbusMasterUdp/test.fc16fc3.php
+++ /dev/null
@@ -1,44 +0,0 @@
-writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 5);
-print_r($recData);
-
-// Data to be writen - INT
-$data = array(0, 1, -1, pow(2,15)-1, -pow(2,15));
-$dataTypes = array("INT", "INT", "INT", "INT", "INT");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 5);
-print_r($recData);
-
-// Data to be writen - DINT
-$data = array(0, 1, -1, pow(2,31)-1, -pow(2,31));
-$dataTypes = array("DINT", "DINT", "DINT", "DINT", "DINT");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 10);
-print_r($recData);
-
-// Data to be writen - REAL
-$data = array(0, 1, -2, 1/3, 25);
-$dataTypes = array("REAL", "REAL", "REAL", "REAL", "REAL");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 10);
-print_r($recData);
-
-?>
\ No newline at end of file
diff --git a/tests/ModbusMasterUdp/test.fc16fc3bind.php b/tests/ModbusMasterUdp/test.fc16fc3bind.php
deleted file mode 100644
index 5d3bed9..0000000
--- a/tests/ModbusMasterUdp/test.fc16fc3bind.php
+++ /dev/null
@@ -1,45 +0,0 @@
-client = $test_bind_client_ip;
-
-// Data to be writen - BYTE
-$data = array(0, 1, 1, pow(2,8)-1, pow(2,8)-1);
-$dataTypes = array("BYTE", "BYTE", "BYTE", "BYTE", "BYTE");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 5);
-print_r($recData);
-
-// Data to be writen - INT
-$data = array(0, 1, -1, pow(2,15)-1, -pow(2,15));
-$dataTypes = array("INT", "INT", "INT", "INT", "INT");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 5);
-print_r($recData);
-
-// Data to be writen - DINT
-$data = array(0, 1, -1, pow(2,31)-1, -pow(2,31));
-$dataTypes = array("DINT", "DINT", "DINT", "DINT", "DINT");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 10);
-print_r($recData);
-
-// Data to be writen - REAL
-$data = array(0, 1, -2, 1/3, 25);
-$dataTypes = array("REAL", "REAL", "REAL", "REAL", "REAL");
-// Write data - FC 16
-$modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 10);
-print_r($recData);
-
-?>
\ No newline at end of file
diff --git a/tests/ModbusMasterUdp/test.fc2.php b/tests/ModbusMasterUdp/test.fc2.php
deleted file mode 100644
index 3c73077..0000000
--- a/tests/ModbusMasterUdp/test.fc2.php
+++ /dev/null
@@ -1,14 +0,0 @@
-readInputDiscretes(0, 0, 2);
-
-var_dump($recData);
\ No newline at end of file
diff --git a/tests/ModbusMasterUdp/test.fc26.php b/tests/ModbusMasterUdp/test.fc26.php
deleted file mode 100644
index 1a889de..0000000
--- a/tests/ModbusMasterUdp/test.fc26.php
+++ /dev/null
@@ -1,24 +0,0 @@
-readWriteRegisters(0, 12288, 6, 12288, $data, $dataTypes);
-
-if(!$recData) {
- // Print error information if any
- echo "Error:" . $modbus->errstr . "";
- //
- exit();
-}
-
-// Print status information
-echo "writeMultipleRegister (FC26): DONE";
-?>
\ No newline at end of file
diff --git a/tests/ModbusMasterUdp/test.fc26bind.php b/tests/ModbusMasterUdp/test.fc26bind.php
deleted file mode 100644
index bf24f9e..0000000
--- a/tests/ModbusMasterUdp/test.fc26bind.php
+++ /dev/null
@@ -1,25 +0,0 @@
-client = $test_bind_client_ip;
-
-// Data to be writen
-$data = array(1000, 2000, 1.250, 1.250);
-$dataTypes = array("REAL", "REAL", "REAL", "REAL");
-
-// FC23
-$recData = $modbus->readWriteRegisters(0, 12288, 6, 12288, $data, $dataTypes);
-
-if(!$recData) {
- // Print error information if any
- echo "Error:" . $modbus->errstr . "";
- //
- exit();
-}
-
-// Print status information
-echo "writeMultipleRegister (FC26): DONE";
-?>
\ No newline at end of file
diff --git a/tests/ModbusMasterUdp/test.fc4.php b/tests/ModbusMasterUdp/test.fc4.php
deleted file mode 100644
index dee4929..0000000
--- a/tests/ModbusMasterUdp/test.fc4.php
+++ /dev/null
@@ -1,14 +0,0 @@
-readMultipleInputRegisters(0, 0, 2);
-
-var_dump($recData);
\ No newline at end of file
diff --git a/tests/ModbusMasterUdp/test.fc5.php b/tests/ModbusMasterUdp/test.fc5.php
deleted file mode 100644
index 95e6f92..0000000
--- a/tests/ModbusMasterUdp/test.fc5.php
+++ /dev/null
@@ -1,23 +0,0 @@
-writeSingleRegister(0, 12288, array(0), array('WORD'));
-
-// Write single coil - FC5
-$modbus->writeSingleCoil(0, 12288, $data_true);
-$modbus->writeSingleCoil(0, 12289, $data_false);
-$modbus->writeSingleCoil(0, 12290, $data_true);
-$modbus->writeSingleCoil(0, 12291, $data_false);
-
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 1);
-print_r($recData);
diff --git a/tests/ModbusMasterUdp/test.fc6fc3.php b/tests/ModbusMasterUdp/test.fc6fc3.php
deleted file mode 100644
index 03c39f5..0000000
--- a/tests/ModbusMasterUdp/test.fc6fc3.php
+++ /dev/null
@@ -1,15 +0,0 @@
-writeSingleRegister(0, 12288, $data, $dataTypes);
-// Read data - FC3
-$recData = $modbus->readMultipleRegisters(0, 12288, 1);
-print_r($recData);
diff --git a/tests/PhpType/Bytes2MixedTest.php b/tests/PhpType/Bytes2MixedTest.php
new file mode 100644
index 0000000..fcaa25b
--- /dev/null
+++ b/tests/PhpType/Bytes2MixedTest.php
@@ -0,0 +1,45 @@
+ 125, // 32098 (DINT)
+ "1" => 98,
+ "2" => 0,
+ "3" => 0,
+ "4" => 0, // 0 (DINT)
+ "5" => 0,
+ "6" => 0,
+ "7" => 0,
+ "8" => 0, // 0 (DINT)
+ "9" => 0,
+ "10" => 0,
+ "11" => 0,
+ "12" => 255, // -1 (DINT)
+ "13" => 255,
+ "14" => 255,
+ "15" => 255,
+ "16" => 158, // -25000 (INT)
+ "17" => 88,
+ "18" => 97, // 25000 (INT)
+ "19" => 168
+ ];
+
+ public function testUnsignedInt()
+ {
+ $this->assertEquals(32098, PhpType::bytes2unsignedInt(array_slice(self::DATA, 0, 4)));
+ }
+
+ public function testSignedInt()
+ {
+ $this->assertEquals(0, PhpType::bytes2signedInt(array_slice(self::DATA, 4, 4)));
+ $this->assertEquals(0, PhpType::bytes2signedInt(array_slice(self::DATA, 8, 4)));
+ $this->assertEquals(-1, PhpType::bytes2signedInt(array_slice(self::DATA, 12, 4)));
+ $this->assertEquals(-25000, PhpType::bytes2signedInt(array_slice(self::DATA, 16, 2)));
+ $this->assertEquals(25000, PhpType::bytes2signedInt(array_slice(self::DATA, 18, 2)));
+ }
+}
diff --git a/tests/PhpType/Bytes2RealTest.php b/tests/PhpType/Bytes2RealTest.php
new file mode 100644
index 0000000..2fd7b80
--- /dev/null
+++ b/tests/PhpType/Bytes2RealTest.php
@@ -0,0 +1,31 @@
+ 0,
+ 1 => 0,
+ 2 => 68,
+ 3 => 122,
+ 4 => 0,
+ 5 => 0,
+ 6 => 68,
+ 7 => 250,
+ 8 => 0,
+ 9 => 0,
+ 10 => 63,
+ 11 => 160,
+ ];
+
+ public function testByte2Real()
+ {
+ $this->assertEquals(1000, PhpType::bytes2float(array_slice(self::DATA, 0, 4)));
+ $this->assertEquals(2000, PhpType::bytes2float(array_slice(self::DATA, 4, 4)));
+ $this->assertEquals(1.25, PhpType::bytes2float(array_slice(self::DATA, 8, 4)));
+ }
+}
diff --git a/tests/PhpType/Bytes2SignedIntTest.php b/tests/PhpType/Bytes2SignedIntTest.php
new file mode 100644
index 0000000..362a30d
--- /dev/null
+++ b/tests/PhpType/Bytes2SignedIntTest.php
@@ -0,0 +1,42 @@
+assertEquals(-1, PhpType::bytes2signedInt(array_slice(self::DATA, 0, 2)));
+ $this->assertEquals(-1, PhpType::bytes2signedInt(array_slice(self::DATA, 0, 4)));
+
+ $this->assertEquals(0, PhpType::bytes2signedInt(array_slice(self::DATA, 4, 4)));
+ $this->assertEquals(1, PhpType::bytes2signedInt(array_slice(self::DATA, 8, 4)));
+ $this->assertEquals(-2147483648, PhpType::bytes2signedInt(array_slice(self::DATA, 12, 4)));
+ $this->assertEquals(2147483647, PhpType::bytes2signedInt(array_slice(self::DATA, 16, 4)));
+ }
+}
diff --git a/tests/PhpType/Bytes2StringTest.php b/tests/PhpType/Bytes2StringTest.php
new file mode 100644
index 0000000..8b5d788
--- /dev/null
+++ b/tests/PhpType/Bytes2StringTest.php
@@ -0,0 +1,32 @@
+assertEquals('eHll oowlr!da', PhpType::bytes2string(self::DATA));
+ $this->assertEquals('Hello world!', PhpType::bytes2string(self::DATA, true));
+ }
+}
diff --git a/tests/PhpType/Bytes2UnSignedIntTest.php b/tests/PhpType/Bytes2UnSignedIntTest.php
new file mode 100644
index 0000000..2c424fc
--- /dev/null
+++ b/tests/PhpType/Bytes2UnSignedIntTest.php
@@ -0,0 +1,42 @@
+assertEquals(65535, PhpType::bytes2unsignedInt(array_slice(self::DATA, 0, 2)));
+ $this->assertEquals(4294967295, PhpType::bytes2unsignedInt(array_slice(self::DATA, 0, 4)));
+
+ $this->assertEquals(0, PhpType::bytes2unsignedInt(array_slice(self::DATA, 4, 4)));
+ $this->assertEquals(1, PhpType::bytes2unsignedInt(array_slice(self::DATA, 8, 4)));
+ $this->assertEquals(2147483648, PhpType::bytes2unsignedInt(array_slice(self::DATA, 12, 4)));
+ $this->assertEquals(2147483647, PhpType::bytes2unsignedInt(array_slice(self::DATA, 16, 4)));
+ }
+}
diff --git a/tests/PhpType/PhpTypeArrayExceptionWithTextArrayTest.php b/tests/PhpType/PhpTypeArrayExceptionWithTextArrayTest.php
new file mode 100644
index 0000000..0565a13
--- /dev/null
+++ b/tests/PhpType/PhpTypeArrayExceptionWithTextArrayTest.php
@@ -0,0 +1,27 @@
+ 100, // 32098 (DINT)
+ "1" => "e",
+ "2" => 0,
+ "3" => 0
+ ];
+
+ public function testExceptionWhenSize2ContainsString()
+ {
+ $this->expectException(\Exception::class);
+ PhpType::bytes2unsignedInt(array_slice(self::DATA, 0, 2));
+ }
+
+ public function testExceptionWhenSize4ContainsString()
+ {
+ $this->expectException(\Exception::class);
+ PhpType::bytes2unsignedInt(array_slice(self::DATA, 0, 4));
+ }
+}
diff --git a/tests/PhpType/PhpTypeArraySizeExceptionsTest.php b/tests/PhpType/PhpTypeArraySizeExceptionsTest.php
new file mode 100644
index 0000000..6003ad4
--- /dev/null
+++ b/tests/PhpType/PhpTypeArraySizeExceptionsTest.php
@@ -0,0 +1,46 @@
+ 100, // 32098 (DINT)
+ "1" => 2,
+ "2" => 0,
+ "3" => 0,
+ "4" => 100, // 32098 (DINT)
+ "5" => 2
+ ];
+
+ public function testExceptionWhenSizeShort()
+ {
+ $this->expectException(\Exception::class);
+ PhpType::bytes2unsignedInt(array_slice(self::DATA, 0, 1));
+ }
+
+ public function testExceptionWhenSizeShort3()
+ {
+ $this->expectException(\Exception::class);
+ PhpType::bytes2unsignedInt(array_slice(self::DATA, 0, 3));
+ }
+
+ public function testExceptionWhenSizeLong()
+ {
+ $this->expectException(\Exception::class);
+ PhpType::bytes2unsignedInt(array_slice(self::DATA, 0, 5));
+ }
+
+ public function testNoExceptionWhenSize2()
+ {
+ $this->assertEquals(25602, PhpType::bytes2unsignedInt(array_slice(self::DATA, 0, 2)));
+ }
+
+ public function testNoExceptionWhenSize4()
+ {
+ $this->assertEquals(25602, PhpType::bytes2unsignedInt(array_slice(self::DATA, 0, 4)));
+ }
+
+}
\ No newline at end of file
diff --git a/tests/PhpType/_test.bat b/tests/PhpType/_test.bat
deleted file mode 100644
index 8122004..0000000
--- a/tests/PhpType/_test.bat
+++ /dev/null
@@ -1,11 +0,0 @@
-@echo off
-call ../config.bat
-
-for %%f in (test.*.php) do %php% -q "%%f" > "output/%%f.html"
-
-cd output
-for %%f in (*.html) do %diff% "%%f" ../ref/"%%f"
-cd ..
-pause
-
-@echo on
\ No newline at end of file
diff --git a/tests/PhpType/ref/test.bytes2mixed.php.html b/tests/PhpType/ref/test.bytes2mixed.php.html
deleted file mode 100644
index 952bc9d..0000000
--- a/tests/PhpType/ref/test.bytes2mixed.php.html
+++ /dev/null
@@ -1 +0,0 @@
-32098
0
0
-1
-25000
25000
\ No newline at end of file
diff --git a/tests/PhpType/ref/test.bytes2real.php.html b/tests/PhpType/ref/test.bytes2real.php.html
deleted file mode 100644
index 7d44edb..0000000
--- a/tests/PhpType/ref/test.bytes2real.php.html
+++ /dev/null
@@ -1 +0,0 @@
-1000
2000
1.25
\ No newline at end of file
diff --git a/tests/PhpType/ref/test.bytes2signedint.php.html b/tests/PhpType/ref/test.bytes2signedint.php.html
deleted file mode 100644
index a2b10ea..0000000
--- a/tests/PhpType/ref/test.bytes2signedint.php.html
+++ /dev/null
@@ -1 +0,0 @@
--1
0
1
-2147483648
2147483647
diff --git a/tests/PhpType/ref/test.bytes2string.php.html b/tests/PhpType/ref/test.bytes2string.php.html
deleted file mode 100644
index 31bbf09..0000000
--- a/tests/PhpType/ref/test.bytes2string.php.html
+++ /dev/null
@@ -1 +0,0 @@
-eHll oowlr!da
Hello world!
\ No newline at end of file
diff --git a/tests/PhpType/ref/test.bytes2unsignedint.php.html b/tests/PhpType/ref/test.bytes2unsignedint.php.html
deleted file mode 100644
index 29be8ee..0000000
--- a/tests/PhpType/ref/test.bytes2unsignedint.php.html
+++ /dev/null
@@ -1,6 +0,0 @@
-float(4294967295)
-
int(0)
-
int(1)
-
float(2147483648)
-
int(2147483647)
-
diff --git a/tests/PhpType/ref/test.strangearray.size.php.html b/tests/PhpType/ref/test.strangearray.size.php.html
deleted file mode 100644
index d0e619d..0000000
--- a/tests/PhpType/ref/test.strangearray.size.php.html
+++ /dev/null
@@ -1 +0,0 @@
-Exception 'Data are not in array 2 or 4 bytes'
25602
Exception 'Data are not in array 2 or 4 bytes'
25602
Exception 'Data are not in array 2 or 4 bytes'
\ No newline at end of file
diff --git a/tests/PhpType/ref/test.strangearray.textarray.php.html b/tests/PhpType/ref/test.strangearray.textarray.php.html
deleted file mode 100644
index 734d099..0000000
--- a/tests/PhpType/ref/test.strangearray.textarray.php.html
+++ /dev/null
@@ -1 +0,0 @@
-Exception 'Data are not numeric'
\ No newline at end of file
diff --git a/tests/PhpType/test.bytes2mixed.php b/tests/PhpType/test.bytes2mixed.php
deleted file mode 100644
index 6b1b391..0000000
--- a/tests/PhpType/test.bytes2mixed.php
+++ /dev/null
@@ -1,37 +0,0 @@
- 125, // 32098 (DINT)
- "1" => 98,
- "2" => 0,
- "3" => 0,
- "4" => 0, // 0 (DINT)
- "5" => 0,
- "6" => 0,
- "7" => 0,
- "8" => 0, // 0 (DINT)
- "9" => 0,
- "10" => 0,
- "11" => 0,
- "12" => 255, // -1 (DINT)
- "13" => 255,
- "14" => 255,
- "15" => 255,
- "16" => 158, // -25000 (INT)
- "17" => 88,
- "18" => 97, // 25000 (INT)
- "19" => 168
-);
-
-// Print mixed values
-echo PhpType::bytes2unsignedInt(array_slice($data, 0, 4)) . "
";
-echo PhpType::bytes2signedInt(array_slice($data, 4, 4)) . "
";
-echo PhpType::bytes2signedInt(array_slice($data, 8, 4)) . "
";
-echo PhpType::bytes2signedInt(array_slice($data, 12, 4)) . "
";
-echo PhpType::bytes2signedInt(array_slice($data, 16, 2)) . "
";
-echo PhpType::bytes2signedInt(array_slice($data, 18, 2)) . "
";
-
-?>
\ No newline at end of file
diff --git a/tests/PhpType/test.bytes2real.php b/tests/PhpType/test.bytes2real.php
deleted file mode 100644
index b6acd56..0000000
--- a/tests/PhpType/test.bytes2real.php
+++ /dev/null
@@ -1,27 +0,0 @@
- 0,
- 1 => 0,
- 2 => 68,
- 3 => 122,
- 4 => 0,
- 5 => 0,
- 6 => 68,
- 7 => 250,
- 8 => 0,
- 9 => 0,
- 10 => 63,
- 11 => 160,
-);
-
-$dword = array_chunk($data, 4);
-
-// Print float interpretation of the real value
-echo PhpType::bytes2float($dword[0]) . "
";
-echo PhpType::bytes2float($dword[1]) . "
";
-echo PhpType::bytes2float($dword[2]) . "
";
-?>
\ No newline at end of file
diff --git a/tests/PhpType/test.bytes2signedint.php b/tests/PhpType/test.bytes2signedint.php
deleted file mode 100644
index 567299c..0000000
--- a/tests/PhpType/test.bytes2signedint.php
+++ /dev/null
@@ -1,35 +0,0 @@
-";
-}
-?>
diff --git a/tests/PhpType/test.bytes2string.php b/tests/PhpType/test.bytes2string.php
deleted file mode 100644
index 547502b..0000000
--- a/tests/PhpType/test.bytes2string.php
+++ /dev/null
@@ -1,28 +0,0 @@
-";
-echo PhpType::bytes2string($data, true) . "
";
-
-?>
diff --git a/tests/PhpType/test.bytes2unsignedint.php b/tests/PhpType/test.bytes2unsignedint.php
deleted file mode 100644
index 9aa6f37..0000000
--- a/tests/PhpType/test.bytes2unsignedint.php
+++ /dev/null
@@ -1,36 +0,0 @@
-";
-}
-?>
diff --git a/tests/PhpType/test.strangearray.size.php b/tests/PhpType/test.strangearray.size.php
deleted file mode 100644
index ba817e2..0000000
--- a/tests/PhpType/test.strangearray.size.php
+++ /dev/null
@@ -1,44 +0,0 @@
- 100, // 32098 (DINT)
- "1" => 2,
- "2" => 0,
- "3" => 0,
- "4" => 100, // 32098 (DINT)
- "5" => 2
-);
-
-// Print mixed values
-try {
- echo PhpType::bytes2unsignedInt(array_slice($data, 0, 1)) . "
";
-} catch(Exception $e) {
- echo "Exception 'Data are not in array 2 or 4 bytes'". "
";
-}
-try {
- echo PhpType::bytes2unsignedInt(array_slice($data, 0, 2)). "
";
-} catch(Exception $e) {
- echo "Exception 'Data are not in array 2 or 4 bytes'". "
";
-}
-try {
- echo PhpType::bytes2unsignedInt(array_slice($data, 0, 3)). "
";
-} catch(Exception $e) {
- echo "Exception 'Data are not in array 2 or 4 bytes'". "
";
-}
-try {
- echo PhpType::bytes2unsignedInt(array_slice($data, 0, 4)). "
";
-} catch(Exception $e) {
- echo "Exception 'Data are not in array 2 or 4 bytes'". "
";
-}
-try {
- echo PhpType::bytes2unsignedInt(array_slice($data, 0, 5)). "
";
-} catch(Exception $e) {
- echo "Exception 'Data are not in array 2 or 4 bytes'". "
";
-}
-?>
\ No newline at end of file
diff --git a/tests/PhpType/test.strangearray.textarray.php b/tests/PhpType/test.strangearray.textarray.php
deleted file mode 100644
index 10306a0..0000000
--- a/tests/PhpType/test.strangearray.textarray.php
+++ /dev/null
@@ -1,22 +0,0 @@
- 100, // 32098 (DINT)
- "1" => "e",
- "2" => 0,
- "3" => 0
-);
-
-// Print mixed values
-try {
- echo PhpType::bytes2unsignedInt(array_slice($data, 0, 4));
-} catch(Exception $e) {
- echo "Exception 'Data are not numeric'";
-}
-?>
diff --git a/tests/README.md b/tests/README.md
deleted file mode 100644
index 1dbebf5..0000000
--- a/tests/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-Probably broken and dubious.
-
-Left from the original repo.
diff --git a/tests/config.bat b/tests/config.bat
deleted file mode 100644
index ef49dfc..0000000
--- a/tests/config.bat
+++ /dev/null
@@ -1,5 +0,0 @@
-set php=c:\Program_Files\xampp\php\php.exe
-rem set php=C:\PHP\versions\php-5.2.6-Win32\php.exe -d auto_prepend_file=C:\PHP\locale.php
-set diff="diff.exe"
-rem set testUri=http://localHost/nette/_trunk/tests
-rem set wget=wget.exe
diff --git a/tests/config.php b/tests/config.php
deleted file mode 100644
index 9c71b4a..0000000
--- a/tests/config.php
+++ /dev/null
@@ -1,3 +0,0 @@
-