Send text from MATLAB on PC to another PC via serial port (RS-232)

6 views (last 30 days)
I am experiencing trouble sending data from one computer to another via RS-232. My ultimate goal is to control the keyboard of Computer #2 with the code sent by Computer #1. e.g. I have written the following code in hopes that it would simulate the key 'J' being pressed on the keyboard of Computer #2. When I run the code no error message appears, but on the other hand it seems that the signal wasn't received on Computer #2 (for- example when 'notepad' is open I don't see the letter J being typed).
Perhaps my understanding of the way the serial port is used is incorrect. Can someone explain what I need to do/check to make this happen?
Thanks!
Here is the code I've been trying to use:
clear all
delete(instrfindall);
s = serial('COM1','BaudRate',9600);
fopen(s);
fprintf(s,'J');
fclose(s);
delete(s);
clear s;

Answers (1)

Walter Roberson
Walter Roberson on 12 Jan 2016
You would need a relatively old system to be able to get that to work in the form you are trying. By about 1990, the PS/2 connectors (which are not RS232 compatible!) had taken over from the DE-9 (or earlier DB25) RS232 serial connectors for keyboards.
If you are not able to find such an old system in working order, then you are going to need to have software running on the destination system that reads the characters and requests that the system act on them. For example this could be implemented inside MATLAB by reading the characters and using the JAVA Robot class to post the characters as keystrokes.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!