John Davidson

Windows USB Serial CMD call using "mode com3: BAUD=38400... instead of PHP call

0 comments
Message:


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.



My Answer:
To make a Windows USB serial CMD call, you can use the `mode` command in Command Prompt. Here's an example of how you can use the `mode` command to communicate with a USB serial device:

1. Connect your USB serial device to your computer.
2. Open Command Prompt by pressing Win + R, typing "cmd", and pressing Enter.
3. Use the following command to list all available COM ports on your computer:

mode

4. Identify the COM port number assigned to your USB serial device (e.g., COM3).
5. Use the following command to configure the COM port for communication:

mode COM3: baud=9600 data=8 parity=n stop=1

Replace "COM3" with the COM port number of your USB serial device and adjust the baud rate, data bits, parity, and stop bits as needed.
6. You can now send and receive data to/from your USB serial device using Command Prompt.

Keep in mind that the specific commands and configurations may vary depending on your USB serial device and its communication protocol. Make sure to refer to the device's documentation for more information on how to communicate with it using Command Prompt.

Rate this post

3 of 5 based on 3281 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us