1

I asked a previous question about a PHP call no longer working on when Win10 upgraded to Win 11. It now strangely writes to a file rather than to the set COM port (may be a win11 apache/php issue, see my other question?).

The code that used to work was:

<?php

`mode com3: BAUD=38400 PARITY=N data=8 stop=1 xon=off`;

file_put_contents(com3, chr(1).chr(255).chr(1).chr(4).chr(64).chr(5));

?>

This used to work fine but now writes to a file called com3 :(
fyi: The ` backtick quotes in PHP executes the command in it - and this still works on Win11.

  • Question is how can I do this direct from Console/CMD prompt. This already works e.g.:
C:\> mode com3: BAUD=38400 PARITY=N data=8 stop=1 xon=off

And can apparently send a command using:

C:\> set /p x="hello" <nul >\\.\COM3

But instead of sending "hello" I want to send the same as would have using the PHP code: "chr(1).chr(255).chr(1).chr(4).chr(64).chr(5))"

Anyone have a good idea how I can send this code from the CMD. As I will make another script to automate this.

Any advice appreciated?

i.e. in php I would do something like:

<?php

$scall = chr(1).chr(255).chr(1).chr(4).chr(64).chr(5);

`mode com3: BAUD=38400 PARITY=N data=8 stop=1 xon=off`;

`set /p x="$scall" <nul >\\.\COM3`;

?>

Appreciate if someone knows how I would change this PHP script, to be able to send those number values? (It may already be fine ;)

fyi: On 232 analyser or some USB Serial COM port software - I would send the code in "DEC", with "1,255,1,4,64,5," And this works too... If helps to set what values would send in CMD prompt.

Thanks for the help.

aku foo
  • 53
  • 6

1 Answers1

1

This code worked in the end, in case helps anyone:

<?php

$scall = chr(1).chr(255).chr(0).chr(255).chr(255).chr(5);
file_put_contents(“scom3.txt”, $scall);

`mode com3: BAUD=38400 PARITY=N data=8 stop=1 xon=off`;
`type “scom3.txt” > com3`;

?>

Doing via "set" and "echo" worked but had an issue as the command chars seem to get changed. So by writing to file, and calling the command from a file, it worked. Also had to remove the \\ escape chars before COM3 from the PHP, as was getting ignored I think. Thanks for article on this site: https://batchloaf.wordpress.com/2013/02/12/simple-trick-for-sending-characters-to-a-serial-port-in-windows/

Anyone have an idea of how to send the command direct so it doesn't get corrupted so doesn't needing to get from a file will be helpful? Thanks.

aku foo
  • 53
  • 6